File: cell.scm

package info (click to toggle)
elk 3.99.8-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,204 kB
  • sloc: ansic: 22,346; lisp: 6,208; makefile: 775; sh: 171; awk: 154; cpp: 92
file content (23 lines) | stat: -rw-r--r-- 563 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
;;; -*-Scheme-*-

(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)))))

(define c (make-cell))
(print ((c 'set) 99))
(print (c 'get))