Get value of function with variable

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7233
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Get value of function with variable

Post by jacque » Mon Sep 14, 2020 11:08 pm

mwieder wrote:
Mon Sep 14, 2020 6:42 pm
Is there an advantage there to using "value" instead of dispatching the function to the card?
Not particularly, but it's a convenient one-liner when you want to get a value back. So yeah, either way works unless the developer is a line-counting absessive I guess.

Actually, come to think of it, dispatch may have the advantage of not requiring the compiler to load. Hadn't thought of that.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Get value of function with variable

Post by mwieder » Tue Sep 15, 2020 1:58 am

Haven't looked at this, but my guess is that "value" does the same sort of runtime parsing as "do", so yes, I'd expect it to be slower.
Hmmm... should be an easy benchmark... <goes back to the laboratory>

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Get value of function with variable

Post by mwieder » Tue Sep 15, 2020 2:08 am

Yep... "dispatch" turns out to be about 5 times faster than an equivalent "value".

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7233
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Get value of function with variable

Post by jacque » Tue Sep 15, 2020 5:52 am

Right, I had heard somewhere that the only two commands/functions that load the compiler are "do" and "value" but I hadn't thought about that in relation to dispatch. I usually go out of my way to avoid "do". I should be more consistent.

"Dispatch" certainly requires less punctuation. :)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Get value of function with variable

Post by mwieder » Tue Sep 15, 2020 4:55 pm

I avoid "do" whenever possible for the slowness reason.
I use dispatch frequently, just have to remember that it returns a three-state value: handled, unhandled, and passed.
So I've gotten into the habit of checking "if it is not unhandled" rather than "if it is handled" after a dispatch call.

Post Reply

Return to “Talking LiveCode”