Held: Monday, April 6, 1998
(call/cc fun), it calls the function
using the current continuation as a parameter.
(+ 2 3) in
(* (+2 3) 3) if the whole expression is typed in
response to the prompt?
call/cc, and they significantly
affect control.
> (define id (lambda (x) x)) > (define (silly cont) (* 2 (+ 3 (cont 1))))
(silly id)? Eight. Why?
We apply the id function to 1, giving 1, add 3, giving
4, and then multiply by 2, giving 8 .
(+ 2 (call/cc silly))?
Surprisingly, we get 3.
(cont 1), we use the continuation of
"add 2, print, and go on to the next expression".
let expressions,
which have the form
(let ((var1 val1)
(var2 val2)
...
(varn valn))
sequence-of-expressions)
(let ((tmp (read))) (* tmp tmp))
(define (filter pred lst)
(if (null? lst) nil
(let ((first (car lst))
(rest (filter pred (cdr lst))))
(if (pred first)
(cons first rest)
rest))))
(let ((a 10))
(+ a
(let ((a 5)) a)
a))
(let ((a 10)
(fun (let ((a 5)) (lambda () a))))
(+ a (fun)))
let is not a necessary construct. It
is, in effect, a shorthand for lambda abstraction and application.
The generic let clause above might be written
((lambda (var1 ... body) val1 val2 ... valn)
(read)
(write obj)
(display obj)
(newline)
begin.
(begin (display "Enter x: ") (define x (read)) (write (* x x)) (newline) )
(set! var exp)
stores a value in the memory location corresponding to a variable.
(set-car! var exp)
sets the first part of a cons cell.
(define var (cons exp (cdr var)))
(set! var (cons exp (cdr var)))
(set-cdr! var exp) does something similar for the cdr.
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
Source text last modified Thu May 7 20:29:42 1998.
This page generated on Thu May 7 20:34:44 1998 by SiteWeaver.
Contact our webmaster at rebelsky@math.grin.edu