c80e3c75a0
Adding to the manual gensym for macros are 2 new macros, but very literal from the CL in letoverlambda. The first is the (with-gensyms ...) macro that can generate a small set of syms for a macro. Works something like: (defmacro adder2 [A B] (with-gensyms [a b] `(let [[~a ~A] [~b ~B]] (+ ~a ~b)))) and ~a and ~b will be replaced with (gensym "a") and (gensym "b") respectively. Then the final macro is a new defmacro that will automatically replace symbols prefaced with "g!" with a new gensym based on the rest of the symbol. So in this final version of 'nif': (defmacro/g! nif4 (expr pos zero neg) `(let [[~g!result ~expr]] (cond [(pos? ~g!result) ~pos] [(zero? ~g!result) ~zero] [(neg? ~g!result) ~neg]))) all uses of ~g!result will be replaced with (gensym "result"). |
||
---|---|---|
.. | ||
contrib | ||
__init__.hy | ||
core.hy | ||
defclass.hy | ||
language.hy | ||
math.hy | ||
native_macros.hy | ||
quote.hy | ||
unless.hy | ||
when.hy | ||
with_decorator.hy |