blob: d15f3ffc3c89877cda07d0480ce74ede64d37399 (
plain)
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
46
47
48
49
50
51
52
53
54
55
56
|
(define make-add (lambda (a) (lambda (b) (+ a b))))
(define add4 (make-add 4))
(add4 5)
`(a b ,((lambda (a) `(test . ,a)) 69) c d)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define fib (lambda (c) (_fib 0 1 0 c)))
(define _fib (lambda (a b n c)
(if (= n c)
b
(_fib b (+ a b) (+ n 1) c))))
(define do (lambda (c f) (_do f '() 0 c)))
(define _do (lambda (f r n c)
(if (= n c) r
(_do f (cons (f n) r) (+ n 1) c))))
;; comment
;; another comment
;; fib(13)
;(do 10 (lambda (n) (display (fib n)))) ; comment
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define +list (lambda (l) (_+list l 0)))
(define _+list (lambda (l acc)
(if (nil? l)
acc
(_+list (cdr l) (+ acc (car l))))))
(+list '(10 12))
(define * (lambda (a n) (+list (do n (lambda (n) a)))))
(* 9 7)
(define reverse (lambda (l) (_reverse l '())))
(define _reverse (lambda (l n)
(if (nil? l) n
(_reverse (cdr l) (cons (car l) n)))))
;; (+list (do 100 (lambda (n) (fib n))))
(reverse (do 100 (lambda (n) (fib n))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; don't know about a good example
(defmacro m (a) `(+ ,a 57))
(m (+ 1 2))
|