Thanks for trying it and finding bugs.

Fix to both these bugs is in the function being called.

/*--------------*/

call_expr_tree(lis):=block([final:[],curr_exp],

expr_tree(lis),

if(final#[]) then (final:map(lambda([x],

[cons(first(first(x)),last(first(x))),last(x)]),final),

finalize_list(final)) else lis)$

expr_tree(lis),

if(final#[]) then (final:map(lambda([x],

[cons(first(first(x)),last(first(x))),last(x)]),final),

finalize_list(final)) else lis)$

/*---------------*/

Initially I couldn't understand x[1] assignment bug until I realized that Maxima treats x[1] and first(x) differently. x[1] notation opens door to global assignment while first(x) will stay a read only operation.

Its was something worth learning and subtle.

Now,

call_expr_tree(a+b); => ["+",a,b]

x[1]:1$ /*x[1] removed with first(x) and this assignment stays out of scope for the function.*/

On Mon, Aug 11, 2014 at 10:53 PM, Barton Willis <willisb@unk.edu> wrote:

Bugs (doesn't handle base case of recursion correctly?)

(%i2) call_expr_tree(1);

last: empty argument.

#0: finalize_list(tt=[])(tree.mac line 14)

OK:

(%i3) call_expr_tree(a+b);

(%o3) ["+",b,a]

(%i4) x[1] : 5;

(%o4) 5

Not OK (fix this with a local, I think)

(%i5) call_expr_tree(a+b);

first: argument must be a non-atomic expression; found

both curr_exp and final are global variables--I think you could

greatlysimplify your code and eliminate theseglobals too.

Regards,

Pankaj Sejwal

____________________________________________

"The more I read, the more I acquire, the more certain I am that I know nothing.” - Voltaire