Alan@AI.AI.MIT.EDU (02/09/88)
(define (make-cell)
(call-with-current-continuation
(lambda (return-from-make-cell)
(letrec ((state
(call-with-current-continuation
(lambda (return-new-state)
(return-from-make-cell
(lambda (op)
(case op
((set)
(lambda (value)
(call-with-current-continuation
(lambda (return-from-access)
(return-new-state
(list value return-from-access))))))
((get) (car state)))))))))
((cadr state) 'done)))))bard@THEORY.LCS.MIT.EDU (Bard Bloom) (02/09/88)
Date: Mon, 8 Feb 88 17:44:38 EST
From: Alan@AI.AI.MIT.EDU
Sender: JAR@AI.AI.MIT.EDU
(define (make-cell)
(call-with-current-continuation
(lambda (return-from-make-cell)
(letrec ((state
(call-with-current-continuation
(lambda (return-new-state)
(return-from-make-cell
(lambda (op)
(case op
((set)
(lambda (value)
(call-with-current-continuation
(lambda (return-from-access)
(return-new-state
(list value return-from-access))))))
((get) (car state)))))))))
((cadr state) 'done)))))
What the hey is this?evan@russell.STANFORD.EDU (Evan Kirshenbaum) (02/10/88)
In article <8802090251.AA01964@RAVEN.LCS.MIT.EDU> bard@THEORY.LCS.MIT.EDU (Bard Bloom) writes:
]
] Date: Mon, 8 Feb 88 17:44:38 EST
] From: Alan@AI.AI.MIT.EDU
] Sender: JAR@AI.AI.MIT.EDU
]
] (define (make-cell)
] (call-with-current-continuation
] (lambda (return-from-make-cell)
] (letrec ((state
] (call-with-current-continuation
] (lambda (return-new-state)
] (return-from-make-cell
] (lambda (op)
] (case op
] ((set)
] (lambda (value)
] (call-with-current-continuation
] (lambda (return-from-access)
] (return-new-state
] (list value return-from-access))))))
] ((get) (car state)))))))))
] ((cadr state) 'done)))))
]
]
]
]What the hey is this?
A side-effect-free value cell (I think). Cute. For those who take
the trouble to walk through it, I think that last call should be to
(caddr state) [the return-from-access continuation].
Now can you do it without consing?
---
Evan Kirshenbaum
Stanford University
evan@CSLI.STANFORD.EDU
...!ucbvax!russell.stanford.edu!evanduba@iuvax.cs.indiana.edu (02/25/88)
;; This is how we would write the "set!-free" make-cell in Scheme
;; extended with the F-operator and prompts (see Felleisen POPL88).
(define (make-cell)
(# (rec state
(F (lambda (set-state)
(lambda (op)
(case op
[(get) state]
[(set) set-state])))))))
;; Now with just F
(define (make-cell)
(F (lambda (return-cell)
(rec state
(F (lambda (set-state)
(return-cell
(lambda (op)
(case op
[(get) state]
[(set) set-state])))))))))
;; Of course what this code shows is that in a language with call/cc or F
;; either rec and letrec must be considered side-effects, or they must
;; be fixed so that it is not possible to find out that they are
;; implemented with side-effects.
;; Bruce Duba and Matthias Felleisen