bakpakin / Fennel

Lua Lisp Language
https://fennel-lang.org
MIT License
2.42k stars 124 forks source link

[Enhancement] Allow passing special forms as functions in macro context #468

Closed alexmozaidze closed 10 months ago

alexmozaidze commented 10 months ago

It would be nice to have. I've yet to find myself in a strong need for it, but it would remove some boilerplate from small macros such as the following example:

(lambda dec-inc-boilerplate [f idx ?by]
  `(set ,idx (,f ,idx ,(or ?by 1))))

(lambda -- [idx ?by]
  (dec-inc-boilerplate - idx ?by))

(lambda ++ [idx ?by]
  (dec-inc-boilerplate + idx ?by))

Right now, one must copy-paste the body of dec-inc-boilerplate into those other macros and have the form invocation baked-in:

(lambda -- [idx ?by]
  `(set ,idx (- ,idx ,(or ?by 1))))

(lambda ++ [idx ?by]
  `(set ,idx (+ ,idx ,(or ?by 1))))

Again, not the end of the world, but would be nice to have ^^

technomancy commented 10 months ago

Turns out this works fine already, you just need to quote the symbol for the special.

(lambda dec-inc-boilerplate [f idx ?by]
  `(set ,idx (,f ,idx ,(or ?by 1))))

(lambda -- [idx ?by]
  (dec-inc-boilerplate `- idx ?by))

(lambda ++ [idx ?by]
  (dec-inc-boilerplate `+ idx ?by))
alexmozaidze commented 10 months ago

Welp, that's an oopsie on my side. Thanks for pointing it out!

technomancy commented 10 months ago

Haha no worries.