File: cell.scm

package info (click to toggle)
elk 3.0-6
  • links: PTS
  • area: main
  • in suites: potato, slink
  • size: 4,068 kB
  • ctags: 3,123
  • sloc: ansic: 20,686; lisp: 5,232; makefile: 419; awk: 91; sh: 21
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))