shen-cl
shen-cl copied to clipboard
Error defining macro-defining macro
(let w (gensym W) x (gensym X) y (gensym Y) zs (gensym Zs)
(defmacro declare-reduce-binary
[declare [reduce-binary Name] | Declarations] ->
(let macro-name (gensym Name)
[[lambda x [lambda y y]]
[defmacro macro-name
[query reduce-binary Name] -> macro-name
[Name w x y | zs] -> [Name w [Name x y | zs]]]
[declare | Declarations]])))
error: The function SHEN::V154 is undefined.
version:
Shen, copyright (C) 2010-2015 Mark Tarver
www.shenlanguage.org, Shen 22.2
running under Common Lisp, implementation: SBCL
port 3.0.3 ported by Mark Tarver, Robert Koeninger and Bruno Deferrari
Additionally, any further entries into the REPL error with The function SHEN::|declare-reduce-binary| is undefined.
Reads as
[LET* [[w [gensym [QUOTE W]]]
[x [gensym [QUOTE X]]]
[y [gensym [QUOTE Y]]]
[zs [gensym [QUOTE Zs]]]]
[defun [QUOTE declare-reduce-binary] [V20]
[COND [[AND [CONSP [QUOTE V20]]
[AND [EQ [CAR [QUOTE V20]] [QUOTE declare]]
[AND [CONSP [CDR [QUOTE V20]]]
[AND [CONSP [CAR [CDR [QUOTE V20]]]]
[AND [EQ [CAR [CAR [CDR [QUOTE V20]]]] [QUOTE reduce-binary]]
[AND [CONSP [CDR [CAR [CDR [QUOTE V20]]]]]
[NULL [CDR [CDR [CAR [CDR [QUOTE V20]]]]]]]]]]]]
[LET [[macro-name [gensym [CAR [CDR [CAR [CDR [QUOTE V20]]]]]]]]
[LIST [LIST [QUOTE lambda] x [LIST [QUOTE lambda] y y]]
[LIST [QUOTE defmacro] macro-name
[CONS [QUOTE query] [CAR [CDR [QUOTE V20]]]]
[QUOTE ->]
macro-name
[CONS [CAR [CDR [CAR [CDR [QUOTE V20]]]]]
[CONS w [CONS x [CONS y zs]]]]
[QUOTE ->]
[LIST [CAR [CDR [CAR [CDR [QUOTE V20]]]]]
w
[CONS [CAR [CDR [CAR [CDR [QUOTE V20]]]]]
[CONS x [CONS y zs]]]]]
[CONS [QUOTE declare]
[CDR [CDR [QUOTE V20]]]]]]]
[T [QUOTE V20]]]]]
Hi @TheGreatCatAdorer. The defmacro
declaration needs to be at the top level, you cannot put it inside a let
(same applies to define
). Another issue is that the expanded code cannot contain multiple forms, if you need that you have to wrap them in [package null [] ....]
so that they become a single form.
Btw, for let bindings you should use upper-case names, otherwise the code may not be portable.