Created
January 7, 2012 00:11
-
-
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)
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
; 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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.