passing parameters in a send call.

Jim Ault JimAultWins at yahoo.com
Mon May 22 12:42:50 EDT 2006


Well, Graham, you posed the question:
> Isn't it true that
> 
>     send "myCmd x,y" to...
> 
>   just sends that exact string (minus the quotes)  to the target: if
> so, the target environment can only resolve x and y if it's in the
> same name space as the script that did the sending (I mean if it is
> able to evaluate x and y), which is in general not true (after all,
> the point of handler parameters is to pass information from one
> context to another)

My simple example shows that "x,y" are passed as their RESOLVED values
rather than a STRING that is evaluated at the destination.

The following stacks pass the values and puts the correct result into fld 2

Steps(A).. make a new mainstack, name it "Apple", drag two scroll flds, edit
the stack script to the following, apply, then enter a value into line 1 and
2 of fld 1, dbl click.

Steps(B).. make a new mainstack, name it "Banana", drag two scroll flds,
edit the stack script to the following, apply, then enter a value into line
1 and 2 of fld 1, dbl click.

Both stacks will update fld 2 in stack Apple

----Apple script -----------------
on mouseDoubleUp
  put line 1 of fld 1 into xx
  put line 2 of fld 1 into yy
  send "calc xx,yy" to me
end mouseDoubleUp

on calc xx,yy
  put xx * yy into fld 2
end calc


on crossTest
 put line 1 of fld 1 into xx
  put line 2 of fld 1 into yy
  send "calc xx,yy" to stack Banana
end crossTest

---Banana script ----------------------
on mouseDoubleUp
  put line 1 of fld 1 into xx
  put line 2 of fld 1 into yy
  --send "calc xx,yy" to me
  
  send "calc xx,yy" to stack Apple
end mouseDoubleUp

on calc xx,yy
  breakpoint
  put xx * yy into fld 2 of stack Apple
end calc


Rev 2.6.1, Mac OSX 10.4.6

Jim Ault
Las Vegas

On 5/22/06 8:00 AM, "Graham Samuel" <livfoss at mac.com> wrote:

> On Sun, 21 May 2006 15:28:28 -0600, Dar Scott <dsc at swcp.com> wrote
>> On May 21, 2006, at 3:01 PM, Sarah Reichelt wrote:
>> 
>> 
>>> I always use something like:
>>>   send "myAdd " & pArrayA to stack "someStack"
>>> 
>>> so that the variable is evaluated before the send.
>>> 
>> 
>> Hi, Sarah!
>> 
>> I'll pick on two aspects of that.
>> 
>> 
>> First of all, I haven't been convinced that there are any merits to
>> this:
>> 
>>     send "myCmd " & x & comma & y to ...
>> 
>> Over this:
>> 
>>     send "myCmd x, y" to ...
>> 
>> And it has some potential problems, such as when x contains a comma.
>> (Also, the latter lends itself to some future (I hope) compiler
>> optimization that compiles code that does not require runtime
>> compiling.)
>> 
>> 
>> Second, in this particular case where pArrayA is an array, the
>> expression '"myAdd " & pArrayA' will resolve to "myAdd ".  The array
>> value looks empty to '&'.
> 
> Isn't it true that
> 
>     send "myCmd x,y" to...
> 
>   just sends that exact string (minus the quotes)  to the target: if
> so, the target environment can only resolve x and y if it's in the
> same name space as the script that did the sending (I mean if it is
> able to evaluate x and y), which is in general not true (after all,
> the point of handler parameters is to pass information from one
> context to another). So if I'm right
> 
>     send "myCmd"& x &","& y to...
> 
> first evaluates x and y in the context of the sender (which is what
> Sarah said) and therefore achieves the expected result, whereas the
> other method doesn't. Arrays being a special case may not work
> anyway, but I'm trying to make a more general point.
> 
> I hope what I've just written makes sense.
> 
> Graham
> 
> 
> ----------------------------------------
> Graham Samuel / The Living Fossil Co. / UK and France
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution





More information about the use-livecode mailing list