Skip to content

Instantly share code, notes, and snippets.

@danking
Created June 8, 2012 19:22
Show Gist options
  • Select an option

  • Save danking/2897687 to your computer and use it in GitHub Desktop.

Select an option

Save danking/2897687 to your computer and use it in GitHub Desktop.
(define-struct just-a-function ([l #:mutable] r) #:property prop:procedure 2)
(define (define#-help proc)
(let* ((me (box #f))
(f (just-a-function proc (lambda args (apply (just-a-function-l (unbox me)) args)))))
(set-box! me f)
(values f (lambda (new-proc) (set-just-a-function-l! f new-proc)))))
(define-syntax define# (syntax-rules () ((_ ((name magic) args ...) body)
(define-values (name magic)
(define#-help (lambda (args ...) body))))))
(define# ((foo magic) x) (sqr x))
(foo 9)
(magic sqrt)
(foo 9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment