Page 1 of 1

Empty paramter eval

Posted: Thu Mar 17, 2016 7:06 pm
by russellf
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?

Re: Empty paramter eval

Posted: Fri Mar 18, 2016 8:23 pm
by jacque
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.

Re: Empty paramter eval

Posted: Fri Mar 18, 2016 9:19 pm
by russellf
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'

Re: Empty paramter eval

Posted: Sat Mar 19, 2016 9:26 pm
by jacque
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.

Re: Empty paramter eval

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

Re: Empty paramter eval

Posted: Mon Mar 21, 2016 12:37 pm
by russellf
@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.