Skip to content

Instantly share code, notes, and snippets.

@dpk
Created January 7, 2012 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpk/1573191 to your computer and use it in GitHub Desktop.
Save dpk/1573191 to your computer and use it in GitHub Desktop.
J-style "under" in Plan. Might go in the standard library. (cf. http://prog21.dadgum.com/121.html)
; don't use "inverse" because it's not the same as a mathematical inverse
; and maybe we'll have a separate system for keeping track of those later.
; also possibly set-opposite should be called set-opposite!
(let opposites+ {}
(deffn (opposite f) (opposites+ f))
(deffn (set-opposite f g)
(set (opposites+ f) g)))
(defmac (under var (f &s) &body)
(let ,var (,f ,@s)
(protect
,@body
((opposite ,f) ,var))))
(set (setter opposite) set-opposite)
(set (opposite open) close)
(set (opposite socket) close)
(set (opposite socketpair) (partial map close))
@dpk
Copy link
Author

dpk commented Jan 7, 2012

As of writing, this won't work in the Plan in the git repo, because it requires function arguments to be destructuring, which they're not there yet. It also uses the hypothetical "protect" statement, which, along with the rest of the error-handling system, is not implemented currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment