Empty paramter eval

If you find an issue in LiveCode but are having difficulty pinning down a reliable recipe or want to sanity-check your findings with others, this is the place.

Please have one thread per issue, and try to summarize the issue concisely in the thread title so others can find related issues here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
russellf
Posts: 17
Joined: Thu Feb 11, 2016 8:34 pm

Empty paramter eval

Post by russellf » Thu Mar 17, 2016 7:06 pm

on mouseUp
answer Something() = 0
answer Something() = empty
answer Something(empty) = 0
answer Something(empty) = empty
end mouseUp

function Something pNothing
return pNothing
end Something

This will return
'true'
'true'
'false'
'true'

Is this expected?

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

Re: Empty paramter eval

Post by jacque » Fri Mar 18, 2016 8:23 pm

Well, it's expected if you know how the engine "thinks".

answer Something() = 0 -- When using empty with a number (math, or comparisons,) LC will treat empty as zero.
answer Something() = empty -- self-explanatory; empty (no param) is empty (the constant)
answer Something(empty) = 0 -- you'd think this would work as in #1, but here the engine is interpreting the constant as a string.
answer Something(empty) = empty -- these are equivalent when compared as both constants and strings

The third one is something of a puzzle. I believe it's happening because you're running the constant "empty" through a function, and the return value is interpreted by LC as a string rather than a constant.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

russellf
Posts: 17
Joined: Thu Feb 11, 2016 8:34 pm

Re: Empty paramter eval

Post by russellf » Fri Mar 18, 2016 9:19 pm

The problem I am facing with it is how it propagates through functions. If I do Something(Something()) then again it will be equal to 0. This can cause unexpected outcomes when you think an empty parameter should equate to empty. Also, this will continue even if you assign it to a variable such as:

put Something() into a
put OtherFunction(a) into b

Now anything in OtherFunction will see a = 0.

Edit: Let me also add that my reasoning is based on the fact that:

answer empty = 0

yields 'false'

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

Re: Empty paramter eval

Post by jacque » Sat Mar 19, 2016 9:26 pm

You can avoid the translation to zero by altering the function slightly:

Code: Select all

function Something pNothing
  if pNothing = empty then put "" into pNothing
  return pNothing
end Something
This seems to remove the string conversion.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Empty paramter eval

Post by [-hh] » Sat Mar 19, 2016 10:08 pm

shiftLock happens

russellf
Posts: 17
Joined: Thu Feb 11, 2016 8:34 pm

Re: Empty paramter eval

Post by russellf » Mon Mar 21, 2016 12:37 pm

@jacque: Thanks for the feedback. I'm using a similar workaround, but as you can imagine this lessens the usefulness of empty params if they don't propogate and behave as you would expect 'empty' to.

@-hh: Ha! Seems I'm late to the party. Thanks for the link.

Post Reply

Return to “Bug Triage”