Skip to content

Instantly share code, notes, and snippets.

Created March 24, 2011 22:09
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 anonymous/886009 to your computer and use it in GitHub Desktop.
Save anonymous/886009 to your computer and use it in GitHub Desktop.
<amalloy> (doc reify)
<sexpbot> ⟹ "Macro ([& opts+specs]); reify is a macro with the
following structure: (reify options* specs*) Currently there are no
options. Each spec consists of the protocol or interface name followed
by zero or more method bodies: protocol-or-interface-or-Object
(methodName [args+] body)* Methods should be supplied for all methods
of the desired protocol(s) and interface(s). You can also define
overrides for methods of Object. Note that the first parameter must be
supplied to correspond to the target object ('this' in Java parlance).
Thus methods for interfaces will take one more argument than do the
interface declarations. Note also that recur calls to the method head
should *not* pass the target object, it will be supplied automatically
and can not be substituted. The return type can be indicated by a type
hint on the method name, and arg types can be indicated by a type hint
on arg names. If you leave out all hints, reify will try to match on
same name/arity method in the protocol(s)/interface(s) - this is
preferred. If you supply any hints at all, no inference is done, so
all hints (or default of Object) must be correct, for both arguments
and return type. If a method is overloaded in a protocol/interface,
multiple independent method definitions must be supplied. If
overloaded with same arity in an interface you must specify complete
hints to disambiguate - a missing hint implies Object. recur works to
method heads The method bodies of reify are lexical closures, and can
refer to the surrounding local scope: (str (let [f \"foo\"] (reify
Object (toString [this] f)))) == \"foo\" (seq (let [f \"foo\"] (reify
clojure.lang.Seqable (seq [this] (seq f))))) == (\\f \\o
\\o))"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment