-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.scm
87 lines (59 loc) · 1.5 KB
/
test.scm
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
(integer? "asdf")
(real? 1)
(+ 1.2 4/5 5) (* 2 3+1.5i) (symbol? 'foo)
(string=? "foo" "bar")
(string=? "foo" "foo")
(= 1 1)
(= 1 1.0)
``(1 ,"foo" ,(2 ,(/ 1.0 5)))
`("expect 1 :" ,(car '(1 2)))
`("expect 1 :" ,(car '(1 . 2)))
`("expect [2] :" ,(cdr '(1 2)))
`("expect 2 :" ,(cdr '(1 . 2)))
`("expect [1,2] :" ,(cons 1 '(2)))
`("expect true :" ,(eqv? 1 1))
`("expect false :" ,(eqv? 1 2))
`("expect true :" ,(equal? '(1 2 3) '(1 2 3)))
`("expect false :" ,(equal? '(1 2 3) '(2 2 3)))
(define foo 1)
`("expect 2: " ,(+ 1 foo))
(set! foo 2)
`("expect 3: " ,(+ 1 foo))
`("expect 2: " ,((lambda (a b) (+ a b))
1 1))
(define (foo bar baz)
(- bar baz)
(+ bar baz))
`("expect 2: " ,(foo 1 1))
(define (bar) "baz")
bar
(bar)
(define (foo bar . baz) bar)
(foo 1 2 3 4)
(define (foo bar . baz) baz)
(foo 1 2 3 4)
(define (foo . baz) baz)
(foo 1 2 3 4)
(define (add a b) (+ 1 2))
(write-string "Hello, World!\n")
(define (length list)
(if (equal? list '())
0
(+ 1 (length (cdr list)))))
(define (my-avg numbers)
(/ (apply + numbers)
(length numbers)))
(define (handler err)
(write-string "caught exception: ")
(write err)
(write-string " continuing...\n"))
(with-exception-handler handler
(lambda () (raise (bad-form-error "bad form" '()))))
(write
(with-exception-handler handler
(lambda () (+ 1 1))))
(write-string "\n")
(define scope-test 1)
((lambda () (define scope-test (+ scope-test 1))))
(write scope-test)
(write-string "\n")