What is the difference between....

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

What is the difference between....

Post by chris25 » Wed Dec 04, 2013 5:20 pm

Dictionary - empty constant
I know I am living in Ireland but.....if I script this: local sVar = 'empty' or 'false' or "" and then I read this I am slightly lost.

Putting empty into a field or variable clears it. (Ok good, understood) I thought this would have been enough...

Putting empty into a nonexistent variable creates the variable with no content. This is a philosophical playground over wine and cheese, anyone care to join me?...

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: What is the difference between....

Post by Klaus » Wed Dec 04, 2013 5:57 pm

Hi Chris,
chris25 wrote:Dictionary - empty constant
I know I am living in Ireland but.....if I script this: local sVar = 'empty' or 'false' or "" and then I read this I am slightly lost.
hm, EMPTY <> FALSE
But EMPTY = ""
chris25 wrote:Putting empty into a nonexistent variable creates the variable with no content.
Come on, Chris you really need a bit more imagination! 8)

What about this "real life" example, I am sure you will be able to translate this to some real Livecode problem 8)
When do you decide to buy new food?
I bet it is something like this:

Code: Select all

...
if TheFridge = EMPTY then
   buy_new_food
   exit to top
end if
if the num of items of TheFridge = 1 then
   put item 1 of TheFridge into tMouth

   ## !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   put empty into TheFridge
else
   put item -1 of TheFridge into tMouth
end if
send "check_fridge" to me in 60*60*24 secs
...
If TheFridge is never MARKED as EMPTY, you will not buy any food and starve and you don't want that! :D


Best

Klaus

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

Re: What is the difference between....

Post by dunbarx » Wed Dec 04, 2013 6:44 pm

I thought that Klaus used Kühlschranks, not fridges.

This may throw a monkey wrench into your thinking:

Code: Select all

on mouseUp
   put empty into temp
   add 2 to temp
   answer temp
end mouseUp
You get "2". Same as if you started out by putting "0" into temp. HC did this as well, allowing one to add a number to empty, as if it was nought. But at least temp was in fact created.

Now then. You cannot do this:

Code: Select all

on mouseUp
   add 2 to temp
   answer temp
end mouseUp
Because temp does not exist as of yet, LC pouts. So there is a big difference between an empty variable and no variable at all.

Craig

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: What is the difference between....

Post by Klaus » Wed Dec 04, 2013 6:59 pm

:D :D :D

OK, the plural is actually "Kühlschränke", but I did not want to confuse Chris more than neccessary! 8)

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: What is the difference between....

Post by chris25 » Wed Dec 04, 2013 7:20 pm

You know, you guys can make my question sound as if I had no need to ask it. :) But the reality is you are answering the question, or should I say more accurately, understanding the definition in the dictionary from a point of perspective of extensive experience and knowledge. I read that statement and am left with ugh, because I have not yet learned to translate English into programmers English into "ah, that makes perfect sense" ...not yet - I'm working on it.

Now actually your answers really have made things very clear, so that when somebody else asks this same question, I will be able to also say: "What? it's so easy how can you not understand that"? :)

All in all , thankyou, yes I mean that. Your examples both were actually fun to read, and really now it does make it clear. Though one important point, and I have to blame someone else for this - sorry :) but one of the first things I read and actually read more than once was this: A variable is created at the moment it is given a value... this for me was clear. So in Craig's second example: "" ad 2 to temp, but temp does not exist"" clearly needs re-adjusting perhaps? not Craig, but the instructional teaching about the variable I mean.

German plurals? - no problem Klaus :D (Koelkasten) loved your story.
regards
chris

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: What is the difference between....

Post by Klaus » Wed Dec 04, 2013 7:24 pm

Well:

Code: Select all

on mouseUp
   add 2 to temp
   answer temp
end mouseUp
actually displays 2 in the answer dialog!? 8)

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

Re: What is the difference between....

Post by dunbarx » Wed Dec 04, 2013 7:34 pm

Chris.

The code starts to execute. The very first thing asked of the engine is to add "2" to (what seems like) a variable name, but is NOT a variable reference, since no variable with that name exists.

So "putting" something into a variable does indeed create it, and at the same time loads it. But "adding" a value to a variable requires that variable already to exist. It does not. Just be happy, unlike most other languages, that variables do not have to be explicitly declared (or typed). Unless explicitVariables is turned on, you just create them on the fly. We love this.

This is not an issue with making a new custom property, for example, since the only way to create and load such a thing is by using "set". This is analogous to using "put" for a variable. Note that you cannot "put" anything into a custom property at all. It is not a container, it is a property. Take a script for example. You can set a script to something, but you cannot put anything into it. It is a property.

Craig

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: What is the difference between....

Post by chris25 » Wed Dec 04, 2013 7:52 pm

I thought putting something into a variable and giving it a value meant exactly the same thing even though you are doing two different things, the definition of value is literally anything that a variable contains? A string of words , letters, text or numbers.
kind regards

chris

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

Re: What is the difference between....

Post by dunbarx » Wed Dec 04, 2013 10:18 pm

I thought putting something into a variable and giving it a value meant exactly the same thing even though you are doing two different things, the definition of value is literally anything that a variable contains? A string of words , letters, text or numbers.
kind regards
If you put something (even empty) into a variable, whatever you put is the value. Putting and what you put are rolled up together, and the simple act of putting will create a new variable if one does not already exist.

In other words, you can declare a new variable, which will create it with empty as a value (what else could it contain?) :

Code: Select all

local xx
on mouseUp
 if xx = "" then answer "kk"
end mouseUp
or you can put something into it:

Code: Select all

on mouseUp
put "" into kk
 if xx = "" then answer "kk"
end mouseUp
But if you do this:

Code: Select all

on mouseUp
   answer gg
end mouseUp
LC will have to assume gg is a literal, since nobody in recent memory ever created a variable by that name, and it has no other options.

Craig

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

Re: What is the difference between....

Post by [-hh] » Thu Dec 05, 2013 3:30 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 11:38 am, edited 1 time in total.
shiftLock happens

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: What is the difference between....

Post by chris25 » Thu Dec 05, 2013 4:31 pm

Hermann - I had no idea that 'empty' could be so 'full' :? Congratulations - I need more wine...forget the cheese. :D

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

Re: What is the difference between....

Post by jacque » Thu Dec 05, 2013 7:47 pm

Code: Select all

10 (empty is in empty) = false
11 (empty is not in empty) = true

12 (empty is in (empty & "A")) = false
13 (empty is not in (empty & "A")) = true
I think this is due to the nature of the parser. The first "empty" is being defined as an unquoted literal, and "empty" is not in empty. I'm not sure there is a way around that, given that the language is untyped.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: What is the difference between....

Post by dunbarx » Thu Dec 05, 2013 7:59 pm

Jacque,

Would the parser take a reserved constant and interpret it as a literal?

This works:

if colon is in ":" then answer "Yep" --Yep

Empty is an odd duck, like quote. Hard to isolate.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”