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
local X Y T in | |
X=1 | |
Y=1 | |
T=X==Y | |
case T of true then {Browse true} else {Browse false} end | |
end |
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
local MulByN A B N in | |
local N in | |
N=3 | |
proc {MulByN X ?Y} | |
Y=N*X | |
end | |
end | |
A=4 | |
N=5 | |
{Browse N} |
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
local MulByN A B in | |
local N in | |
N=3 | |
proc {MulByN X ?Y} | |
Y=N*X | |
end | |
end | |
A=4 | |
{Browse N} | |
{MulByN 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
declare OrElse | |
fun {OrElse BP1 BP2} | |
if {BP1} then true | |
else {BP2} | |
end | |
end | |
{Browse {OrElse fun {$} 1==1 end fun {$} 2==3 end}} | |
{Browse {OrElse fun {$} 1==2 end fun {$} 2==2 end}} | |
{Browse {OrElse fun {$} 1==2 end fun {$} 2==3 end}} |
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
declare Sum1 Sum2 | |
Sum1 = proc {$ N ?R} | |
local T in | |
T=N==0 | |
if T then R=0 | |
else | |
local S M in | |
S=N-1 | |
{Sum1 S M} | |
R=N+M |
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
(define (odd-sequence min max) | |
(cond ((even? min) (odd-sequence (+ 1 min) max)) | |
((> min max) '()) | |
(else (cons min (odd-sequence (+ 2 min) max))))) | |
(define (search-for-primes min max) | |
(map timed-prime-test (odd-sequence min max)) | |
(newline)) |
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
(define (runtime) (current-milliseconds)) |
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
(define (start-prime-test n start-time) | |
(if (prime? n) | |
(report-prime (- (runtime) start-time)) | |
#f)) |
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
(define (fib n) | |
(fib-iter 1 0 0 1 n)) | |
(define (fib-iter a b p q count) | |
(cond ((= count 0) b) | |
((even? count) | |
(fib-iter a | |
b | |
(+ (* p p) (* q q)) ; compute p' | |
(+ (* q q) (* 2 p q)) ; compute q' | |
(/ count 2))) |
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
(define (fast-multi a b) | |
(define (double n) (+ n n)) | |
(define (halve n) (/ n 2)) | |
(define (even? n) (= (remainder n 2) 0)) | |
(define (iter a b x) | |
(cond ((or (= a 0) (= b 0)) 0) | |
((= b 1) (+ a x)) | |
((even? b) (iter (double a) (halve b) x)) | |
(else (iter a (- b 1) (+ a x))))) | |
(iter a b 0)) |