Page 1 of 1

Missing parameters are treated as zero!

Posted: Sat Sep 26, 2015 7:15 pm
by [-hh]
WARNING!

I needed a few hours to find out why a (lengthy) handler
gave me wrong results. I couldn't believe it.

If you have a handler with one or more parameters
then to call this handler WITHOUT parameters is, with LC,
NOT the same as a call with empty parameters:


---> LC treats *missing* params as zero !!!! <---

Make a new stack, 1 button, 1 field. Script the button:

Code: Select all

on mouseUp
   put empty into fld 1
   -- variant 1: Call the handler without parameter
   checkIt        --> yields true true
   -- variant 2: Call the handler with an empty parameter
   put empty into y
   checkIt y      --> yields true false
end mouseUp

on checkIt x
    put cr & (x is empty) && (x is "0") after fld 1
end checkit
I started to check this with LC 8.0.0-dp-5, then went back over LC 7, LC 6 down to LC 5.5.5. They all give the same result, on Mac/Linux/Win, please correct me if it is different with you.
HC on an emulated MacPlus yields for both variants "true false" what is logically correct, IMHO.

Is there a "List of Warnings" about such things?
Knowing the above "feature" had saved me a lot of time.

Re: Missing parameters are treated as zero!

Posted: Mon Sep 28, 2015 8:05 am
by LCMark
This is one of those anomalies which we're stuck with at the moment - I'll file it as such in the Quality Centre in due course.

We know it's not a behavior that is easily changed, as 7 originally worked the way you expected and peoples code broke. If a parameter is unspecified its value is 'undefined' which is treated subtly differently for type coercion.