I am working through desctructuring chapter 18 of PG's On Lisp book.
He defines a pattern matching version of dbind like this:
(defmacro if-match (pat seq then &optional else)
`(aif2 (match ',pat ,seq)
(let ,(mapcar #'(lambda (v)
`(,v (binding ',v it)))
(vars-in then #'atom))
,then)
,else))
I have typed out all related functions like vars-in, var? etc (not
shown here).
Then he shows an example function abab where he uses the above macro.
I typed out the abab function as well as shown below:
(defun abab (seq)
(if-match (?x ?y ?x ?y) seq
(values ?x ?y)
nil))
However after say I have shut down my Emacs and later restart it and
compile this file
which has all code, it gives me the error on abab as shown:
Compilation failed: 1 error 0 warnings 14 style-warnings 0 notes
[1.17 secs]
(in macroexpansion of (IF-MATCH (?X ?Y ?X ...) SEQ ...))
(hint: For more precise location, try *BREAK-ON-SIGNALS*.)
The function VARS-IN is undefined.
Now if I compile C-c C-c vars-in and var? etc then compile abab it
gets compiled. Why does the if-match expansion fail when I do a
compile file C-c, C-k.
Any ideas to help me resolve this would be great? Pls forgive if it is
a stupid error on my part.
Thanks a ton in advance,
Regards,
Deepak Surti
I forgot to mention. I am using SBCL.
On Apr 21, 4:56 pm, Deepak Surti <·······@gmail.com> wrote:
> I am working through desctructuring chapter 18 of PG's On Lisp book.
> He defines a pattern matching version of dbind like this:
>
> (defmacroif-match(pat seq then &optional else)
> `(aif2 (match ',pat ,seq)
> (let ,(mapcar #'(lambda (v)
> `(,v (binding ',v it)))
> (vars-in then #'atom))
> ,then)
> ,else))
>
> I have typed out all related functions like vars-in, var? etc (not
> shown here).
>
> Then he shows an example function abab where he uses the above macro.
>
> I typed out the abab function as well as shown below:
>
> (defun abab (seq)
> (if-match(?x ?y ?x ?y) seq
> (values ?x ?y)
> nil))
>
> However after say I have shut down my Emacs and later restart it and
> compile this file
> which has all code, it gives me the error on abab as shown:
>
> Compilation failed: 1 error 0 warnings 14 style-warnings 0 notes
> [1.17 secs]
> (in macroexpansion of (IF-MATCH(?X ?Y ?X ...) SEQ ...))
> (hint: For more precise location, try *BREAK-ON-SIGNALS*.)
> The function VARS-IN is undefined.
>
> Now if I compile C-c C-c vars-in and var? etc then compile abab it
> gets compiled. Why does theif-matchexpansion fail when I do a
> compile file C-c, C-k.
>
> Any ideas to help me resolve this would be great? Pls forgive if it is
> a stupid error on my part.
>
> Thanks a ton in advance,
> Regards,
> Deepak Surti
On 21 Dub, 13:59, Deepak Surti <·······@gmail.com> wrote:
> ...
> > However after say I have shut down my Emacs and later restart it and
> > compile this file
> > which has all code, it gives me the error on abab as shown:
>
> > Compilation failed: 1 error 0 warnings 14 style-warnings 0 notes
> > [1.17 secs]
> > (in macroexpansion of (IF-MATCH(?X ?Y ?X ...) SEQ ...))
> > (hint: For more precise location, try *BREAK-ON-SIGNALS*.)
> > The function VARS-IN is undefined.
>
Macro is expanded in compile time, and the functions are not known at
that time. Either use eval-when, or separate the definitions to
different file.
Try look up eval-when in Practical Common Lisp, for example.
Regards,
Tomas
On Apr 21, 5:15 pm, Tomas Zellerin <········@gmail.com> wrote:
> On 21 Dub, 13:59, Deepak Surti <·······@gmail.com> wrote:
>
> > ...
> > > However after say I have shut down my Emacs and later restart it and
> > > compile this file
> > > which has all code, it gives me the error on abab as shown:
>
> > > Compilation failed: 1 error 0 warnings 14 style-warnings 0 notes
> > > [1.17 secs]
> > > (in macroexpansion of (IF-MATCH(?X ?Y ?X ...) SEQ ...))
> > > (hint: For more precise location, try *BREAK-ON-SIGNALS*.)
> > > The function VARS-IN is undefined.
>
> Macro is expanded in compile time, and the functions are not known at
> that time. Either use eval-when, or separate the definitions to
> different file.
>
> Try look up eval-when in Practical Common Lisp, for example.
>
> Regards,
> Tomas
Hi Tomas,
Separating out functions into another file did the trick.
Thanks for the quick response. I will surely go through PCL as pointed
out by you.
Regards,
Deepak