Using lisp displa to view local variables



PS Though the backquote syntax can be very handy, for cases like this, it's
generally easier just to construct the expressions with explicit list
functions.  There are also fancy versions of the backquote syntax which can
be helpful, but I would recommend starting with the list operations, which
are somewhat more verbose, but simpler.

On Tue, Jul 26, 2011 at 16:45, Stavros Macrakis <macrakis at alum.mit.edu>wrote:

> You really need to review basic Lisp semantics.
>
> For a normal function f, (f x (+ a b)) does not pass the expressions x and
> (+ a b) to f, but their values.  So f has no way of "retrieving" the
> expressions you used.
>
> For a macro, (f x (+ a b)) passes the unevaluated expressions.
>
> You need to write a macro that, called as (f a b), returns something like
> (progn (myprint 'a a) (myprint 'b b)), where myprint takes *as separate
> arguments* the name and the value of each expression.
>
>             -s
>
> On Tue, Jul 26, 2011 at 16:31, Edwin Woollett <woollett at charter.net>wrote:
>
>> On July 26, 2011, Stavros Makrakis wrote:
>> **************************
>>
>> That all looks correct to me.  If you want something like (ldisplay x y z)
>> to print x=3, y=3, etc., then ***ldisplay*** needs to be a macro.
>> ******************************************
>> I have tried using  (dolist (xk xx)  body) with and without
>> (defmacro...) with no success. I obviously need to study up
>> on Lisp macros. Where do I put the commas when my
>> starting point is a lisp list like xx?
>> ------------------------------**------------------------------**------
>> MAXIMA> (dolist (bk '(1 2 3))
>>               (print bk))
>>
>> 1
>> 2
>>
>> 3
>> NIL
>>
>> MAXIMA> (defun ldisplay (&rest xx)
>>     (dolist (xk xx) ($display_value xk)))
>>
>>
>> LDISPLAY
>>
>> MAXIMA> (defun f1 ()
>>  (let ((a1 'aa) (s1 "my string") (l1 '(a b c)))
>>        (mtell "local")
>>        (ldisplay s1 l1 a1)
>>        (mtell "bye")))
>>
>> F1
>>
>> MAXIMA> (f1)
>>
>> local
>> xk = my string
>> xk = (a, b, c)
>> xk = aa
>> bye
>> NIL
>>
>> MAXIMA> (defmacro $ldisplay (&rest xx)
>>     (dolist (xk xx) ($display_value xk)))
>>
>> $LDISPLAY
>>
>>
>> MAXIMA> (defun f1 ()
>>  (let ((a1 'aa) (s1 "my string") (l1 '(a b c)))
>>        (mtell "local")
>>        ($ldisplay s1 l1 a1)
>>        (mtell "bye")))
>>
>> F1
>>
>> MAXIMA> (f1)
>>
>> local
>> xk = s1
>> xk = l1
>> xk = a1
>> bye
>> NIL
>>
>> MAXIMA> (defmacro $ldisplay (&rest xx)
>>     (dolist (xk ,xx) ($display_value xk)))
>>
>>
>> Maxima encountered a Lisp error:
>> Error in READ [or a callee]: A comma has appeared out of a backquote.
>> Error in EVAL [or a callee]: The variable XX is unbound.
>> Error in EVAL [or a callee]: The variable XK is unbound.
>>
>> MAXIMA> (defmacro $ldisplay (&rest xx)
>>     (dolist (xk xx) ($display_value ,xk)))
>>
>>
>> Maxima encountered a Lisp error:
>> Error in READ [or a callee]: A comma has appeared out of a backquote.
>> Error in EVAL [or a callee]: The variable XK is unbound.
>>
>> ------------------------------**------
>>
>> Ted
>>
>>
>>
>