1
0
forked from alex-eg/sex

mark multi-form macro expansions with $

A bare list was read as several forms, so a macro returning
`((make-adder 10) 5)' -- a call of what make-adder returns -- was
spliced into two. Add a new $ char to denote splicing, so ($ form ...)
splices.
This commit is contained in:
2026-09-29 23:51:41 +03:00
parent 6f54bfbe08
commit 53f92727a5
3 changed files with 62 additions and 10 deletions

View File

@@ -212,6 +212,20 @@ Sex has support for syntactic macros. Macro definitions look like
functions: they have a name, an argument list and a body. Macro should
return Sex code.
A macro returns *one* form. To return several --- a function beside the
struct it works on, say --- return them under =$=, which splices them in
where the macro was written:
#+begin_src scheme
(defmacro (pair-of-fns a b)
`($ (fn ,a () int (return 1))
(fn ,b () int (return 2))))
#+end_src
=($)= expands to nothing. Everything else is a single form, including
one whose head is itself a form: =`((make-adder 10) 5)= calls what
=make-adder= returned, and is not two forms.
*** Examples:
**** Structure with templated value type
#+begin_src scheme