Вы находитесь на странице: 1из 6

Chez Scheme Version 9.4.

1
Copyright 1984-2016 Cisco Systems, Inc.

>
Exception: variable ! is not bound
Type (debug) to enter the debugger.
> (letrec
((! (lambda (n)
(if (zero? n) 1
(* n (! (sub1 n)))))))
(! 5))
120
> (letrec
((! (lambda (n)
(if (zero? n) 1
(* n (! (sub1 n)))))))
!)
#<procedure !>
> ((letrec
((! (lambda (n)
(if (zero? n) 1
(* n (! (sub1 n)))))))
!)
5)
120
> (list-ref '(a b c d) 4)

Exception in list-ref: index 4 is out of range for list (a b c d)


Type (debug) to enter the debugger.
> (list-ref '(a b c d) 3)
d
> (list-ref '(a b c d e f) 3)
|(list-ref (a b c d e f) 3)
|d
d
> (list-ref '(a b c d e f) 3)
|(list-ref (a b c d e f) 3)
| (inner-function 3)
| |(inner-function 2)
| | (inner-function 1)
| | |(inner-function 0)
| | |(a b c d e f)
| | (b c d e f)
| |(c d e f)
| (d e f)
|d
d
>
Exception: invalid syntax (trace-lambda (n) (cond ((...) ls) (else (...)))) at line
24, char 3 of /Users/jhemann/304/let-and-co.ss
Type (debug) to enter the debugger.
> (list-ref '(a b c d e f) 3)
|(list-ref (a b c d e f) 3)
| (inner-function 3)
| |(inner-function 2)
| | (inner-function 1)
| | |(inner-function 0)
| | |(a b c d e f)
| | (b c d e f)
| |(c d e f)
| (d e f)
|d
d
> (easy-list-ref '(a b c d e f) 3)
|(easy-list-ref (a b c d e f) 3)
|(easy-list-ref (b c d e f) 2)
|(easy-list-ref (c d e f) 1)
|(easy-list-ref (d e f) 0)
|d
d
> (fact 10)
|(fact 10)
| (fact 9)
| |(fact 8)
| | (fact 7)
| | |(fact 6)
| | | (fact 5)
| | | |(fact 4)
| | | | (fact 3)
| | | | |(fact 2)
| | | | | (fact 1)
| | | |[10](fact 0)
| | | |[10]1
| | | | | 1
| | | | |2
| | | | 6
| | | |24
| | | 120
| | |720
| | 5040
| |40320
| 362880
|3628800
3628800
> (fact-acc 10)
|(fact-acc 10)
Exception: incorrect number of arguments to #<procedure at let-and-co.ss:731>
Type (debug) to enter the debugger.
> (fact-acc 10 1)
|(fact-acc 10 1)
|(fact-acc 9 10)
|(fact-acc 8 90)
|(fact-acc 7 720)
|(fact-acc 6 5040)
|(fact-acc 5 30240)
|(fact-acc 4 151200)
|(fact-acc 3 604800)
|(fact-acc 2 1814400)
|(fact-acc 1 3628800)
|(fact-acc 0 3628800)
|3628800
3628800
> (other-fact 10)
3628800
> (other-fact 10)
|(loop 10 1)
|(loop 9 10)
|(loop 8 90)
|(loop 7 720)
|(loop 6 5040)
|(loop 5 30240)
|(loop 4 151200)
|(loop 3 604800)
|(loop 2 1814400)
|(loop 1 3628800)
|(loop 0 3628800)
|3628800
3628800
> (feed-me-seymour 4)
|(loop 4)
|(loop 3)
|(loop 2)
|(loop 1)
|(loop 0)
(feed me seymour!)|#<procedure>
#<procedure>
> ((feed-me-seymour 4) 5)
|(loop 4)
|(loop 3)
|(loop 2)
|(loop 1)
|(loop 0)
(feed me seymour!)|#<procedure>
|(loop 5)
|(loop 4)
|(loop 3)
|(loop 2)
|(loop 1)
|(loop 0)
(feed me seymour!)|#<procedure>
#<procedure>
> ((feed-me-seymour 4) 5)
|(loop 4)
|(loop 3)
|(loop 2)
|(loop 1)
|(loop 0)
|#<procedure>
|(loop 5)
|(loop 4)
|(loop 3)
|(loop 2)
|(loop 1)
|(loop 0)
|#<procedure>
#<procedure>
> ((letrec
((even?
(lambda (n)
(if (zero? n) #t
(odd? (sub1 n)))))
(odd?
(lambda (n)
(if (zero? n) #f
(even? (sub1 n))))))
odd?)
5)
#t
> ((letrec
((even?
(lambda (n)
(if (zero? n) #t
(odd? (sub1 n)))))
(odd?
(lambda (n)
(if (zero? n) #f
(even? (sub1 n))))))
odd?)
6)
#f
> ((letrec
((even?
(trace-lambda traced-even? (n)
(if (zero? n) #t
(odd? (sub1 n)))))
(odd?
(traced-lambda traced-odd? (n)
(if (zero? n) #f
(even? (sub1 n))))))
odd?) 10)

Exception: variable n is not bound


Type (debug) to enter the debugger.
> ((letrec
((even?
(trace-lambda traced-even? (n)
(if (zero? n) #t
(odd? (sub1 n)))))
(odd?
(trace-lambda traced-odd? (n)
(if (zero? n) #f
(even? (sub1 n))))))
odd?) 10)
|(traced-odd? 10)
|(traced-even? 9)
|(traced-odd? 8)
|(traced-even? 7)
|(traced-odd? 6)
|(traced-even? 5)
|(traced-odd? 4)
|(traced-even? 3)
|(traced-odd? 2)
|(traced-even? 1)
|(traced-odd? 0)
|#f
#f
> (let ((x 5) (y 6))
(let ((y 7) (x y))
(+ x y)))
13
> (let ((x 5) (y 6))
(let* ((y 7)
(x y))
(+ x y)))
14
> (let ((x 5))
(let ((y (add1 x)))
(let ((z (+ x x)))
(list x y z))))
(5 6 10)
> (let* ((x 5)
(y (add1 x))
(z (+ x x)))
(list x y z))
(5 6 10)
> (filter even? '(1 2 3 4 5))
(2 4)
> `((+ 5 3) is ,(+ 5 3))
((+ 5 3) is 8)
> (quote (+ a 5))
(+ a 5)
> (quasiquote ((+ 5 3) is (unquote (+ 5 3))))
((+ 5 3) is 8)
> '(, is a thing)
(,is a thing)
> '(unquote is a thing)
(unquote is a thing)
> `(this has quotes in front of (+ 2 4) ,(+ 2 4))
(this has quotes in front of (+ 2 4) 6)
> `(this has quotes in front of (+ 2 4) ',(+ 2 4))
(this has quotes in front of (+ 2 4) '6)
> `(this has quotes in front of (+ 2 4) '',(+ 2 4))
(this has quotes in front of (+ 2 4) ''6)
> `(this has quotes in front of (+ 2 4) ''',(+ 2 4))
(this has quotes in front of (+ 2 4) '''6)
> `(this is the ,'(unquote 5))
(this is the ,5)
> (((lambda (s) (lambda (z) (s (s (s z))))) add1) 0)
3
> (((lambda (n)
(lambda (m)
(lambda (s)
(lambda (z)
((m n) z)))))
(lambda (s) (lambda (z) (s (s (s z))))))
(lambda (s) (lambda (z) (s (s (s z))))))

#<procedure>
> (((((lambda (n)
(lambda (m)
(lambda (s)
(lambda (z)
((m n) z)))))
(lambda (s) (lambda (z) (s (s (s z))))))
(lambda (s) (lambda (z) (s (s (s z))))))
add1)
0)

#<procedure s>
> (((((lambda (n)
(lambda (m)
(lambda (s)
(lambda (z)
(((m n) s) z)))))
(lambda (s) (lambda (z) (s (s z)))))
(lambda (s) (lambda (z) (s (s z)))))
add1)
0)

27
> (((((lambda (n)
(lambda (m)
(lambda (s)
(lambda (z)
(((m n) s) z)))))
(lambda (s) (lambda (z) (s (s z)))))
(lambda (s) (lambda (z) (s (s z)))))
add1)
0)
4
> (((((lambda (n)
(lambda (m)
(lambda (s)
(lambda (z)
(((m n) s) z)))))
(lambda (s) (lambda (z) (s (s z)))))
(lambda (s) (lambda (z) (s (s z)))))
add1)
0)
4
> (lambda (quote) (lambda (z) '''''z))
#<procedure>
> (((lambda (quote) (lambda (z) '''''z))
add1)
0)
5
> (define fun 'horrifying)
> (map (lambda (d) (cons 1 d)) '(a b c d e f g))
((1 . a) (1 . b) (1 . c) (1 . d) (1 . e) (1 . f) (1 . g))
> (map (lambda (d) (cons 1 d)) '((a) (b) (c) (d) (e) (f) (g)))
((1 a) (1 b) (1 c) (1 d) (1 e) (1 f) (1 g))
> (lambda (n)
(lambda (m)
(lambda (s)
(lambda (z)
((m n) z)))))
> ((curry map) ((curry cons) 1))

Вам также может понравиться