Is there syntax for calling a function, ignoring result?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Pomo
Posts: 11
Joined: Tue Mar 31, 2015 7:50 pm

Is there syntax for calling a function, ignoring result?

Post by Pomo » Mon Apr 13, 2015 11:07 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Is there syntax for calling a function, ignoring result?

Post by dunbarx » Tue Apr 14, 2015 12:09 am

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

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Is there syntax for calling a function, ignoring result?

Post by SparkOut » Tue Apr 14, 2015 8:43 am

Also you can

Code: Select all

get setValue("kName","Fred")
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)

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Is there syntax for calling a function, ignoring result?

Post by Klaus » Tue Apr 14, 2015 1:36 pm

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! :D

Best

Klaus

Pomo
Posts: 11
Joined: Tue Mar 31, 2015 7:50 pm

Re: Is there syntax for calling a function, ignoring result?

Post by Pomo » Tue Apr 14, 2015 4:51 pm

Klaus wrote:short answer: No!
Function WITH result, a handler or die! :D
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

Post Reply