Subject: Using lisp displa to view local variables
From: Robert Dodier
Date: Tue, 26 Jul 2011 15:02:56 -0600
I don't see why disp, display, or ldisplay can't be
used instead of creating a new function.
I'm pretty sure (MFUNCALL '$FOO (... args ...)) works
for all kinds of Maxima functions -- I don't remember if
display & friends are ordinary Lisp functions or DEFMSPEC macros,
but it shouldn't matter w/ MFUNCALL.
Sorry if I'm off base here.
best, Robert Dodier
On 7/26/11, Stavros Macrakis <macrakis at alum.mit.edu> wrote:
> 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
>>>
>>>
>>>
>>
>