-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlet.scm
More file actions
45 lines (39 loc) · 1.01 KB
/
Copy pathlet.scm
File metadata and controls
45 lines (39 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
;simple let expression
(let ((x 2) (y 5))
(+ x y))
; the above is syntactic sugar for:
((lambda (x y)
(+ x y)) 2 5)
;tricky for variable scope
(define x 10)
(+ (let ((x 5))
(* x (+ x 2))) x)
;the last x=10, since it's outside the let body
;this result in 45 --> 5+2*5 + 10
;another with variable scope
(define x 10)
(let ((x 5)
(y (* x 2)))
(+ x y))
;result=25, since y asignment is outside the let body hence x at that point equals 10
; same example but using let* which is a recursive let
(define x 10)
(let* ((x 5)
(y (* x 2)))
(+ x y))
; result=15 since x=5 and y=10
; the same example re-written as recursive let
(define x 10)
(let ((x 5))
(let ((y (* x 2)))
(+ x y)))
;result=15 since i'm using recursive let, the y definition is not longer in the variable declaration but in the body of the first let, so it's using the inner x declaration
;named let
;print from 1 to 10
(let ite ((c 1))
(newline)
(display c)
(if (< c 10)
(ite (+ c 1))))
;letrec
;not well understood yet...