Welcome to the CHICKEN Scheme pasting service

define-dynamic added by mario-goulart on Mon Mar 11 19:43:05 2013

(define-syntax define-dynamic
  (syntax-rules ()
    ((_ var value)
     (define var
       (let ((slot (lambda () value)))
         (lambda (#!optional new-value)
           (if new-value
               (set! slot (lambda () new-value))
               (slot))))))))

(define-dynamic foo 'foo)
(define-dynamic bar (foo))

(print (bar)) ;; => foo
(foo 'foo2)
(print (bar)) ;; => foo2

(parameterize ((foo 'foo3))
  (print (bar))) ;; => foo3

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Which module provides `define-foreign-type'?
Visually impaired? Let me spell it for you (wav file) download WAV