In Scheme define works as follows:
(define w 42) ; yields nothing w ; thence yields 42 (define (x r t) (- r t)) (x 5 2) ; yields 3MzScheme goes farther to facilitate Currying and after
(define ((y a b) c) (+ a b c)) ((y 3 3) 4) ; yields 10.Originally:
(define (bind p k) (cond ((not (procedure? p)) (error "first arg to bind must be a procedure")) ((not (procedure? k)) (error "second arg to bind must be a procedure")) (#t (lambda () (let* ((p2 (p)) (q (k p2)) ) (if (not (procedure? q)) (error "second arg to bind must be a procedure that returns a procedure") (q) )))))) (define (return v) (lambda () v))Dispensing (foolishly) with the checking in bind and employing MzScheme’s currying define extension we may define ‘bind’ and ‘return’ thus:
(define ((bind p k)) ((k (p)))) (define ((return v)) v)Likewise:
(define ((display2 a)) (display a)) (define (read2) (read))((bind read2 (lambda (x) (display2 x)))) still works as before. It could be written
((bind read2 display2))Sometime brevity helps. Judge for yourself.
The program execution might then be described as follows: