Functions (was: Re: horizontal and vertical scrolling)

J. Landman Gay jacque at hyperactivesw.com
Thu Jun 16 00:28:40 EDT 2011


On 6/15/11 6:58 PM, Timothy Miller wrote:
> Hi Jacque,

We may as well let everyone else in on this, someone may have something 
to add. And I don't think you embarrassed either of us. I mean, we 
weren't posting our underwear to Facebook or anything. :)

For the peanut gallery: we were talking in email about the value of 
using functions.

> If I understand your article on functions correctly, a handler or a
> script can do anything a function can do. However, scripts containing
> functions are easier to create and maintain. Also, functions are
> easier to repair and maintain, because they are not embedded in
> complex scripts.

Right. Change your function and all handlers that use it automatically 
work the new way.

> If I thought about it, I could probably figure out a way to write a
> script or a handler that would generate random numbers, but it would
> be messy, and it would be silly to put the script in more than one
> place.
>
> Am I getting the right idea?

Yes, that's it.

> There's another thingie, sort of like a function... I think it also
> returns a value or list, but I can't recall what it's called and
> can't find it in the dictionary under "control structures," so, never
> mind.

Regular (i.e. "command") handlers can return values too if they use the 
"return" keyword at the end; i.e., "return somethingOrOther". That puts 
the value into "the result". It's invisible, nothing comes back 
automatically. So the handler that did the calling needs to "get the 
result" in order to retrieve the value. With a function, the value comes 
back immediately all by itself and plops itself into the variable you 
provided.

If anyone wants to provide some rules of thumb for when you use a 
function and when you don't, that might be interesting.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com




More information about the use-livecode mailing list