1 / 3

Esercizio

Esercizio. Si sciva in CAML una fuzione DIV che calcoli la divisione intera sui naturali (zero incluso). La funzione deve risultare indefinita allorchè applicata come in (DIV n 0), per ogni n≥0, con n dividendo e 0 divisore. Un volta scritta, la si esegua sulla macchina CAML per le seguenti

cleave
Download Presentation

Esercizio

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Esercizio Si sciva in CAML una fuzione DIV che calcoli la divisione intera sui naturali (zero incluso). La funzione deve risultare indefinita allorchè applicata come in (DIV n 0), per ogni n≥0, con n dividendo e 0 divisore. Un volta scritta, la si esegua sulla macchina CAML per le seguenti applicazioni: DIV 3 5;; DIV 18 3;; DIV 3 0;; DIV 0 0;; Una soluzione

  2. DIV dd ds = if (dd-ds)≥0 then 1+DIV(dd-ds)ds else 0 • Caml Light version 0.74 #let rec DIV dd ds = if (dd-ds) >= 0 then 1+DIV(dd-ds)ds else 0;; • DIV : int -> int -> int = <fun> • #DIV 3 5 ;; • - : int = 0 • #DIV 18 3;; • - : int = 6 • #DIV 3 0;; • Uncaught exception: Out_of_memory • #f 0 0;; • Uncaught exception: Out_of_memory Out_of_memory: Perchè? Cosasignifica?

  3. Memoria a struttura di grafo @ ds dd IFTE ≥ + 0 + - @ 1 0 1 grafodellafunzioneDIV + 1 + 0 @ 0 1 DIV 0 0: grafo dell’espressione dopo la 3^ riduzione di grafo

More Related