Using lisp displa to view local variables



Common Lisp has lexical scope, so (eval 'x) evaluates x in the global scope
(by default).  Example:

(let ((x 3)) (eval 'x)) => error


You need to make $display_value into a Lisp macro, e.g.

(defmacro $display_value (x) `(displa (list '(mtext) ',x " = " ,x)))


Maxima does allow Lisp macros in Maxima expressions, so you can call this
from either Maxima or Lisp code.

           -s

On Tue, Jul 26, 2011 at 13:42, Edwin Woollett <woollett at charter.net> wrote:

> On July 23, 2011, Dieter Kaiser wrote:
> *******************
> There are a lot of more possibilities, e.g. an example with a
> mtext-expression:
>
> MAXIMA> (defun $display_value (x)
>         (displa `((mtext) ,x " = " ,(eval x))))
> $DISPLAY_VALUE
>
> MAXIMA> (display_value 'expr)
> expr = a + b + c
> NIL
> **************************
> I would like to use your approach to look at local
> lisp variables inside a lisp function, but am having
> trouble getting a bound local variable passed:
> ------------------------------**------------------------
> Maxima 5.24.0
> using Lisp GNU Common Lisp (GCL) GCL 2.6.8 (a.k.a. GCL)
>
> (%i1) load(mfiles);
> (%o1)                         c:/work2/mfiles.mac
>
> (%i2) print_lines("display.lisp",1,**11)$
> ;;; display.lisp
>
> (defun ldisplay (&rest xx)
>         (mapcar #'(lambda (s)
>                             (displa `((mtext) ,s " = " ,(eval s))) ) xx))
>
> (defun f1 ()
>     (let ((a1 'aa) (s1 "my string") (l1 '(a b c)))
>             (mtell "local")
>             (ldisplay 's1 'l1 'a1)
>             (mtell "bye")))
>
> (%i3) load("display.lisp");
> (%o3)                            display.lisp
>
> (%i4) ?trace (?ldisplay);
> (%o4)                             (ldisplay)
>
> (%i5) :lisp (f1)
> local
>  1> (LDISPLAY S1 L1 A1)
> Maxima encountered a Lisp error:
>
> Error in EVAL [or a callee]: The variable S1 is unbound.
>
> Automatically continuing.
> To enable the Lisp debugger set *debugger-hook* to nil.
> (%i5)
> ------------------------------**--------------------
> Any suggestions for getting bound local variables passed
> to ldisplay?
>
> Ted Woollett
> p.s. I am probably making a basic lisp programming error?
>
>
> ______________________________**_________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/**mailman/listinfo/maxima<http://www.math.utexas.edu/mailman/listinfo/maxima>;
>