Skip to content

Instantly share code, notes, and snippets.

@jcoglan
Created January 30, 2009 17:41
Show Gist options
  • Save jcoglan/55157 to your computer and use it in GitHub Desktop.
Save jcoglan/55157 to your computer and use it in GitHub Desktop.
; Modifies a variable by applying a function to said variable
(define-syntax ! (syntax-rules ()
[(! x (fn arg ...))
(set! x (fn x arg ...))]
[(! x fn)
(set! x (fn x))]))
; for example...
(define-syntax square! (syntax-rules ()
[(square! x)
(! x (* x))]))
(define a 6)
(square! a)
; a = 36
; This is safer, and allows (! x (compose square add1))
(define-syntax ! (syntax-rules ()
[(! x fn arg ...)
(set! x (fn x arg ...))]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment