Page Numbers: Yes X: 306 Y: 1.0" First Page: 30
Margins: Top: 1.0" Bottom: 1.3"
Heading:
CS-370 (FALL 1982)3-LISP REFERENCE MANUALNovember 5, 1982
——————————
Modified Processor
——————————
(define READ-NORMALISE-PRINT
(lambda simple [level env stream]
(block (prompt level)
(reply (normalise (read stream) env done))
stream)
(read-normalise-print level env stream))))
(define NORMALISE
(lambda simple [exp env return]
(cond [(normal exp) (return exp)]
[(atom exp) (return (binding exp env))]
[(rail exp) (normalise-rail exp env return)]
[(pair exp) (reduce (car exp) (cdr exp) env return)])))
(define REDUCE
(lambda simple [proc args env return]
(letnormalise [[proc! proc env]]
(if (reflective proc!); Continuation C0
(↑(de-reflect proc!) args env return)
(letnormalise [[args! args env]]
(if (primitive proc!); Continuation C1
(return ↑(↑proc! . ↑args!))
(normalise (body proc!)
(bind (pattern proc!) args! ↑(cenv proc!))
return)))))))
(define NORMALISE-RAIL
(lambda simple [rail env return]
(if (empty rail)
(return (rcons))
(letnormalise [[first! (1st rail)]]
(letnormalise-rail [[rest! (rest rail) env]]; Continuation C2
(return (prep first! rest!))))))); Continuation C3
—————————
;;; This redefinition requires the addition of the following procedures:
(define DONE (lambda simple args args))
(define LETNORMALISE (processor-let ’normalise))
(define LETNORMALISE-RAIL (processor-let ’normalise-rail))
(define PROCESSOR-LET
(lambda simple [proc]
(lambda macro [list body]
(if (empty list)
body
̀ (,proc ,(2nd (1st list)) ,(3rd (1st list))
(lambda simple [,(1st (1st list))]
(,(processor-let proc) ,(rest list) ,body))))))
Non-Tail-Recursive Version:
(define READ-NORMALISE-PRINT
(lambda simple [level env stream]
(block (prompt level)
(reply (normalise (read stream) env)
stream)
(read-normalise-print level env stream))))
(define NORMALISE
(lambda simple [exp env]
(cond [(normal exp) exp]
[(atom exp) (binding exp env)]
[(rail exp) (normalise-rail exp env)]
[(pair exp) (reduce (car exp) (cdr exp) env)])))
(define REDUCE
(lambda simple [proc args env]
(let [[proc! (normalise proc env)]]
(if (reflective proc!)
(↑(de-reflect proc!) args env)
(let [[args! (normalise args env)]]
(if (primitive proc!)
↑(↑proc! . ↑args!)
(normalise (body proc!)
(bind (pattern proc!) args! ↑(cenv proc!)))))))))))
(define NORMALISE-RAIL
(lambda simple [rail env]
(if (empty rail)
(rcons)
(prep (normalise (1st rail) env)
(normalise-rail (rest rail) env)))))
Extensional Control Reflection Version:
(define READ-NORMALISE-PRINT
(lambda simple [level env stream]
(block (prompt level)
(reply (normalise (read stream) env done))
stream)
(read-normalise-print level env stream))))
(define NORMALISE
(lambda simple [exp env return]
(cond [(normal exp) (return exp)]
[(atom exp) (return (binding exp env))]
[(rail exp) (normalise-rail exp env return)]
[(pair exp) (reduce (car exp) (cdr exp) env return)])))
(define REDUCE
(lambda simple [proc args env return]
(letnormalise [[proc! proc env]
[args! proc env]]
(cond [(primitive proc!) (return ↑(↑proc! . ↑args!))]
[(reflective proc!) (↑(de-reflect proc!) args! return)]
[$T (normalise (body proc!)
(bind (pattern proc!) args! ↑(cenv proc!))
return)]))))
(define NORMALISE-RAIL
(lambda simple [rail env return]
(if (empty rail)
(return (rcons))
(letnormalise [[first! (1st rail)]]
(letnormalise-rail [[rest! (rest rail) env]]; Continuation C2
(return (prep first! rest!))))))); Continuation C3
(define LAZY
(lambda simple [env pattern body]
(lambda macro args
̀ ((lambda simple ,pattern ,body)
. ,(map (lambda simple [exp] ̀ (delay ,exp))
args))))
(define IF
(lambda lazy [premise c1 c2]
(force (ef (force premise!)
c1))
c2))))
(define IF
(lambda macro [@premise @c1 @c2]
̀ ((lambda simple [premise c1 c2]
(force (ef (force premise!)
c1))
c2)))
(delay ,@premise)
(delay ,@c1)
(delay ,@c2))))
(define IF
(lambda macro [@premise @c1 @c2]
̀ (let [[premise (delay ,@premise)]
[c1 (delay ,@c1)]
[c2 (delay ,@c2)]]
(force (ef (force premise!)
c1
c2)))))