-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Denis Smet
committed
Oct 15, 2023
1 parent
7d21556
commit 3135231
Showing
2 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
(ns sicp.chapter-1.ex-1-20) | ||
|
||
; Exercise 1.20 | ||
; The process that a procedure generates is of course dependent on the rules used by the interpreter. | ||
; As an example, consider the iterative gcd procedure given above. | ||
; Suppose we were to interpret this procedure using normal-order evaluation, as discussed in 1.1.5. | ||
; (The normal-order-evaluation rule for if is described in Exercise 1.5.) | ||
; Using the substitution method (for normal order), illustrate the process generated in evaluating | ||
; (gcd 206 40) and indicate the remainder operations that are actually performed. | ||
; | ||
; How many remainder operations are actually performed in the normal-order evaluation of (gcd 206 40)? | ||
; In the applicative-order evaluation? | ||
|
||
(defn gcd [a b] | ||
(if (= b 0) | ||
a | ||
(gcd b (mod a b)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(ns sicp.chapter-1.ex-1-20-test | ||
(:require [clojure.test :refer :all]) | ||
(:require [sicp.chapter-1.ex-1-20 :refer [gcd]])) | ||
|
||
(deftest gcd-test | ||
(is (= 2 (gcd 206 40))) ; 4 times | ||
) |