calling function in msg

Richard Herz herz at ucsd.edu
Tue Apr 2 13:30:00 EST 2002


Jacqueline Landman Gay wrote:

>> You can access functions normally from the message box if you first "start
>> using" the stack containing the function definitions.

> Even if they are in the topstack you are working on? That's usually the
> case when I try to test a function I've just written.

Works for me.

Mike Yates wrote:

>>For example: In the stack script defined the function
> >
> >function sq x
> >return x*x
> >end  sq
> >
> >If you enter into the msg box sq(3) you get 9 as expected. But if you
> >enter 3*sq(3) you get an error.

>  On the other hand if you enter sq(3)*3 you get 27. It's the lack of
>  symmetry that is the problem - also  it doesn't just apply to defined
>  functions but native functions as well - try 3*sin(3) and sin(3)*3.

If you "start using" the stack with the function sq() definitions, executing
the following from the msg box *does* show an apparent problem
[command from msg -> result in msg (or answer dialog)]:

put sq(3)*3 -> 9  *** this is not good *** () around expression doesn't help
put 3*sq(3) -> 9  *** this is not good ***

answer 3*sq(3) -> answer dialog with 27
answer sq(3)*3 -> answer dialog with 27
sq(3)*3 -> 27  (why does this work?)
3*sq(3) -> error (but should get one here?, e.g., you'll get it with 2*2)

Rich Herz <herz at ucsd.edu>
http://mechanics.ucsd.edu/research/herz/reactorlab/




More information about the metacard mailing list