Page 1 of 1
Is there syntax for calling a function, ignoring result?
Posted: Mon Apr 13, 2015 11:07 pm
by Pomo
I have a function that saves a value and returns nothing important. Only the side-effect is important. I would like to use a statement like
setValue("kName","Fred")
for the combination of brevity and clarity. This is an error though.
What works:
1) put setValue("kName","Fred") into foo
2) Convert setValue to a handler and use
setValue "kName",datavalue
Is there any compact syntax that calls setValue("kName","Fred") without implying a result? Not a big deal here. It just seems that in my mind, functions calculate or do something internally, while handlers respond to messages caused by actions.
Thank you.
Doug
Re: Is there syntax for calling a function, ignoring result?
Posted: Tue Apr 14, 2015 12:09 am
by dunbarx
Hi.
There are two basic ways to run a "subRoutine" in LC. Each sends a message somewhere, usually to an object higher up in the message path.
Function calls send a message to a handler that returns a value to the calling handler. If you write: "put doubleUp(5) into fld 1" into a button script, and in the card script you have:
Code: Select all
function doubleUp var
return var * 2
end doubleUp
You will get a "10" in fld 1.
The other is a message handler. If you write: "doubleUp 5", you are sending a message directly up the hierarchy with a single parameter. You might have, again in the card script:
Code: Select all
on doubleUp var
put var * 2 into fld 1
end doubleUp
You still get a "10" in fld 1.
The distinction may not be obvious at this stage, but you soon will clearly know when you need one or the other. In both cases, the calling handler continues past the calls.
Note that the second example above did not need to make use of any of the following words (which may actually make the idea clearer): "Send", "Call" or "Dispatch".
Would you take a challenge, read up on those in the dictionary, and write back with how that can be? Or might you find out how to return a value to the calling handler even with a command call?
Craig Newman
Re: Is there syntax for calling a function, ignoring result?
Posted: Tue Apr 14, 2015 8:43 am
by SparkOut
Also you can
which will place any returned value into "it" which you can ignore, and the "it" variable will be reused and overwritten the next time any operation giving a value is performed.
Additionally, becoming less basic, it sounds like setProp might be something for you to investigate. (After you have taken up Craig's challenge)
Re: Is there syntax for calling a function, ignoring result?
Posted: Tue Apr 14, 2015 1:36 pm
by Klaus
Hi Doug,
Pomo wrote:Is there any compact syntax that calls setValue("kName","Fred") without implying a result?
short answer: No!
Function WITH result, a handler or die!
Best
Klaus
Re: Is there syntax for calling a function, ignoring result?
Posted: Tue Apr 14, 2015 4:51 pm
by Pomo
Klaus wrote:short answer: No!
Function WITH result, a handler or die!
Klaus
This. In the end, I converted the result-less function into a handler. The "get f(a)" also looks plausible.
I really appreciate being able to ask about the best practices for accomplishing particular tasks in LC. These kinds of questions remain for me even after reading the docs and examples. Thanks to everyone who replied.
Doug