about 'local X = empty' statement

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

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 580
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

about 'local X = empty' statement

Post by Thierry » Mon Sep 18, 2017 3:35 pm

Hi all,

try next in a card script
(but it doesn't have to be there):

Code: Select all

local x = empty

on opencard
      answer "<" & x & ">"
end opencard
Think what could be the answer, and try it...

Thierry
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

bogs
Posts: 599
Joined: Sat Feb 25, 2017 10:45 pm

Re: about 'local X = empty' statement

Post by bogs » Mon Sep 18, 2017 4:18 pm

Thierry wrote:Think what could be the answer, and try it...
Without having tried it yet, I am guessing you would see <> in the answer box, going to go look now :D

*Edit - Ok, I was wrong :?
ImageImage

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 580
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: about 'local X = empty' statement

Post by Thierry » Mon Sep 18, 2017 4:39 pm

bogs wrote: Without having tried it yet, I am guessing you would see <> in the answer box, going to go look now :D

*Edit - Ok, I was wrong :?
and that's the point. I was guessing this too, and that the result is the word 'empty'
instead of an empty variable looks a bug to me.

In fact, I've been challenged with a bug last week and need quite some times
to find the culprit, which was one of my local not being empty with this statement!

So, experts: bug or feature?

Regards,

Thierry
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

bogs
Posts: 599
Joined: Sat Feb 25, 2017 10:45 pm

Re: about 'local X = empty' statement

Post by bogs » Mon Sep 18, 2017 5:09 pm

Thierry wrote:and that's the point. I was guessing this too, and that the result is the word 'empty'
instead of an empty variable looks a bug to me.
Awww, I was trying not to give it away :D

I would agree it seems 'bug-ish', after all if you have nothing in a variable, it should be nothing whether you write empty, "", or some other method.

I am thinking if you put empty into a field, then said [answer "<" & field "Field" & ">"] you would get the <> back. Maybe should test that one before saying it though, as well as putting [x=""] hehe.
ImageImage

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 580
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: about 'local X = empty' statement

Post by Thierry » Mon Sep 18, 2017 5:18 pm

bogs wrote:
Thierry wrote:and that's the point. I was guessing this too, and that the result is the word 'empty'
instead of an empty variable looks a bug to me.
I would agree it seems 'bug-ish', after all if you have nothing in a variable, it should be nothing whether you write empty, "", or some other method.
Doing this works as expected since eons:

Code: Select all

put empty into x

put empty into field "whatever"
Thierry
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4916
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: about 'local X = empty' statement

Post by dunbarx » Mon Sep 18, 2017 6:12 pm

I think it is clearly a bug, in that the constant "empty" ought to be 100% interchangeable with "" (that is, two consecutive quotes) in all cases. It has to be something to do with having an expression in the local variable declaration, as opposed simply to declaring a variable.

Craig

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 580
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: about 'local X = empty' statement

Post by Thierry » Mon Sep 18, 2017 6:30 pm

dunbarx wrote:I think it is clearly a bug, in that the constant "empty" ought to be 100% interchangeable with "" (that is, two consecutive quotes) in all cases.
Thanks Craig,

Bug 20416

Thierry
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

bogs
Posts: 599
Joined: Sat Feb 25, 2017 10:45 pm

Re: about 'local X = empty' statement

Post by bogs » Mon Sep 18, 2017 8:24 pm

What happens when I think out-loud (besides an echo) :?:

I wonder if it is happening due to the guessing magic in the engine. You know, like when it decides what you wrote should be something else, so your saying [local x=empty], and it is interpreting empty as a string, so that is what you get back ?

Of course, no sooner did I have this thought, then I tested it, turns out not so much :D
If you type local x, and then the rest of the code, it still answers <empty> :shock: but if you put [x=""] it does answer <>. Go figure :?

SO now I am darn sure it is a bug, because an uninitialized variable should sure as tootin be nothing.
ImageImage

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 580
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: about 'local X = empty' statement

Post by Thierry » Mon Sep 18, 2017 9:07 pm

Thierry wrote:
Bug 20416

Thierry
Latest news:

This bug has been marked as a duplicate of bug 19413

Thierry
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

bogs
Posts: 599
Joined: Sat Feb 25, 2017 10:45 pm

Re: about 'local X = empty' statement

Post by bogs » Mon Sep 18, 2017 10:06 pm

It is funny, but apparently I can't sign in there :lol:

Anyhoo, I think they are missing the 'bug' part of it, because an unassigned value should be the same as "".

i.e.

Code: Select all

local x 
// x should contain nothing at this point, as it is only declared...

on opencard
      answer "<" & x & ">"
end opencard
The result still answers <empty>.

Unfortunately, I can't point that out in the original report, as I said, I don't seem to be able to sign in there :(

*Edit - apparently this part of it was fixed somewhere along the way, I was originally testing it in 6.x, but when I (DOH) tested it in a more recent release (8.1.4), the above does actually display correctly :oops: my bad :oops:
ImageImage

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

Re: about 'local X = empty' statement

Post by mwieder » Thu Sep 28, 2017 1:06 am

As noted in the comments to but 19413, this isn't actually a bug, but the confluence of a few things.

For starters, while assigning values to local variables at declaration time is not officially forbidden, it's not officially condoned either.
The engine treats this the same way it treats assignments of constants, i.e., strings and numbers are accepted, nothing else is.
There is no evaluation of rvalues at declaration time.

Combine this with the fact that LC for stupid historical reasons allows unquoted string literals unless you have 'strict variables' enabled, and you find that you are assigning the string "empty" to a local variable at declaration time.

This prevents the use of predefined constants in declarations... try using true in place of empty and you'll get the same sort of result.

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 580
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: about 'local X = empty' statement

Post by Thierry » Thu Sep 28, 2017 8:05 am

mwieder wrote:As noted in the comments to but 19413, this isn't actually a bug, but the confluence of a few things.
bug or not bug and adding to this that the Script Editor is a bit silent,;
this is a real pain, for starters or not :twisted:
For starters, while assigning values to local variables at declaration time is not officially forbidden, it's not officially condoned either.
I believe your statement should be print on stone somewhere in the dictionary or the users' guide.

My 2 cents,

Thierry
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

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

Re: about 'local X = empty' statement

Post by mwieder » Thu Sep 28, 2017 4:16 pm

bug or not bug and adding to this that the Script Editor is a bit silent,;
this is a real pain, for starters or not :twisted:
Yep. No argument from me on that account.

Post Reply

Return to “Talking LiveCode”