Question: why eval(parse(command with assignment)) does not work?

is it possible for a string such as "res:=boo()" to be evaluated after calling parse, and have res have the value that the function boo() returned?

Now, it does not work. I must do   res:=eval(parse("boo()")) , meaning the result of the call to boo() is outside the string.

Here is an example of what I mean

boo:=proc()
   return 99;
end proc;  

foo:=proc()
  local s,res,i;
  s:="res:=boo()";
  eval(parse(s)):
  print(res);
end proc;

foo();

The above does not work. It displays res but this works

boo:=proc()
   return 99;
end proc;  

foo:=proc()
  local s,res,i;
  s:="boo()";
  res:=eval(parse(s)):
  print(res);
end proc;

foo();

The above works, and prints 99.

The reason I am asking, is that I was thinking of storing in a data base the complete Maple command as string, along with the LHS of the call, and just load the string the evaluate it, and it will have res automatically set.

It is no problem if this can't work, I could always just eval the command itself, without the assignment being there. Just thought to ask if there is a way.

 

Please Wait...