get name of variable as string in function?



I suggest you keep things simple and modular:

/* The worker function */
mprintx(name,val) := print(sconcat("  ",name," = "),val)$

mprint('a,a)$

/* Print 1 variable */
mprint(zz23) := mprintx(zz23,ev(zz23))$

mprint('a)$

/* Print many variables in a list */
mprintl(ll23) := map(mprintx,ll23,map(ev,ll23))$

mprintl('[a,b])$

/* Print many variables as multiple arguments */
mprintll([mm23]) ::= subst(mm23,'mm23,'(mprintl('mm23)))$

mprintll(a,b)$

             -s

mprintll(a,b);


On Thu, Feb 2, 2012 at 16:36, Edwin Woollett <woollett at charter.net> wrote:

>
> On Feb. 2, 2012,  Stavros Macrakis wrote:
> ---------------------
>
>  mprint(zz) := print(sconcat(zz," = ",ev(zz)))$ and then mprint('a).
>>
> ------------------------
> This works. Now I want to define mdisplay(a)
> or mdisplay(a,b), etc to apply this def. to each
> arg in succession. But my tries so far fail:
> ------------------------------**---------------------
> (%i1) [a,b] : [2,3];
> (%o1) [2,3]
>
> (%i2) mprint(zz234) := print(sconcat("  ",zz234," = "),ev(zz234))$
>
> (%i3) mprint('a);
>
>  a =  2 (%o3) 2
>
> (%i4) map('mprint,'[a,b]);
>  a =  2  b =  3 (%o4) [2,3]
>
> (%i5) mdisplay([vv]) := map('mprint,'vv)$
>
> (%i6) mdisplay(a,b);
> map: improper argument: vv
> #0: mdisplay(vv=[2,3])
> -- an error. To debug this try: debugmode(true);
>
> (%i7) mdisplay([vv]) := (print(vv),map('mprint,'vv))$
>
> (%i8) mdisplay(a,b);
> [2,3] map: improper argument: vv
> #0: mdisplay(vv=[2,3])
> -- an error. To debug this try: debugmode(true);
>
> ------------------------------**-----
> Ted
>
>
>
>
>
>