Hot to debug a MACROLET with XLISP?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Hot to debug a MACROLET with XLISP?

edgar-rft
Hi all,

I'm still sitting here on the third rework of the XLISP reference while
simultaneosly porting some of my favourite Common Lisp AI tools to Nyquist,
where I got stuck with the following problem.

Question to the Nyquist specialists on this list:

The particular problem I have with MACROLETs is that MACROEXPAND and
MACROEXPAND-1 only look for macros in the *OBARRAY*, while MACROLETs are
stored as macro-FLETs in the association list of the lexical environment,
where MACROEXPAND and MACROEXPAND-1 do not search at all.

The Common Lisp MACROEXPAND has an "environment" parameter that enables
expanding MACROLETs, maybe there is a similar environment trick in XLISP
that I only haven't understood?

----

What I want is writing debugging code similar to this:

(defun blah ()
   (MACROLET ((macro-name (macro-args)
                `(print ,macro-args)))
     (MACROEXPAND '(macro-name 'something))))

(blah) => (PRINT SOMETHING)

But what XLISP returns is:

(blah) => (MACRO-NAME (QUOTE SOMETHING))

MACROEXPAND shall expand the MACROLET and _not_ just simply return the
unexpanded (MACRO-NAME (QUOTE SOMETHING)).

The problem is that xmacroexpand() and x1macroexpand() functions in
"xlbfun.c" use FBOUNDP to search for the macro symbol, where BOUNDP and
FBOUNDP only search the *OBARRAY* but _not_ the lexical environment.

This leads to the next question "How to test if a local lexical variable
or function is bound to a valid value?" but I already have written a set
of lexical introspection tools for this.

NOTE: the behaviour of BOUND and FBOUNDP is _not_ a bug, it's only not
clearly documented that BOUND and FBOUNDP only search for bindings in
the *OBARRAY*.

But this then still doesn't answer the question if it's not a bug that
MACROEXPAND and MACROEXPAND-1 explicitely call FBOUNDP leaving no other
choice to the XLISP programmer.

----

Possible workaround:

I can read the unexpanded code from the lexical environment via *EVALHOOK*
or GETENV (from "evalenv.lsp"), but even then I can find no way how to
pass the code to the internal macroexpand() function in "xeval.c".

Here is a (very short version of) how to read the unexpanded MACROLET
from the lexical environment:

(defun blah ()
   (MACROLET ((macro-name (macro-args)
                `(print ,macro-args)))
     (get-lambda-expression (cdr (assoc 'MACRO-NAME (cadr (getenv)))))))

(blah) => (MACRO (MACRO-ARGS) (BACKQUOTE (PRINT (COMMA MACRO-ARGS))))

Maybe there a way how I can expand this myself by using some built-in
XLISP functions, but _without_ writing a full macro expander?

----

The main question is:

Does anybody know how to MACROEXPAND MACROLETs with XLISP?

Thanks,

- edgar






--
The author of this email does not necessarily endorse the following
advertisements, which are the sole responsibility of the advertiser:


------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
Audacity-nyquist mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/audacity-nyquist