Created
March 3, 2015 18:58
-
-
Save orchid-hybrid/03a2df6a0c1992bfe534 to your computer and use it in GitHub Desktop.
making a mutable cell in scheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> (define (make-cell value) (cons (lambda () value) (lambda (new-value) (set! value new-value)))) | |
> (define cell (make-cell 'x)) | |
> ((car cell)) | |
x | |
> ((cdr cell) 'y) | |
> ((car cell)) | |
y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment