What is the difference between....
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
What is the difference between....
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?...
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?...
Re: What is the difference between....
Hi Chris,
But EMPTY = ""
What about this "real life" example, I am sure you will be able to translate this to some real Livecode problem
When do you decide to buy new food?
I bet it is something like this:
If TheFridge is never MARKED as EMPTY, you will not buy any food and starve and you don't want that!
Best
Klaus
hm, EMPTY <> FALSEchris25 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.
But EMPTY = ""
Come on, Chris you really need a bit more imagination!chris25 wrote:Putting empty into a nonexistent variable creates the variable with no content.
What about this "real life" example, I am sure you will be able to translate this to some real Livecode problem
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
...
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: What is the difference between....
I thought that Klaus used Kühlschranks, not fridges.
This may throw a monkey wrench into your thinking:
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:
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
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
Now then. You cannot do this:
Code: Select all
on mouseUp
add 2 to temp
answer temp
end mouseUp
Craig
Re: What is the difference between....
OK, the plural is actually "Kühlschränke", but I did not want to confuse Chris more than neccessary!
Re: What is the difference between....
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 (Koelkasten) loved your story.
regards
chris
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 (Koelkasten) loved your story.
regards
chris
Re: What is the difference between....
Well:
actually displays 2 in the answer dialog!?
Code: Select all
on mouseUp
add 2 to temp
answer temp
end mouseUp
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: What is the difference between....
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
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
Re: What is the difference between....
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
kind regards
chris
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: What is the difference between....
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.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
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
Code: Select all
on mouseUp
put "" into kk
if xx = "" then answer "kk"
end mouseUp
Code: Select all
on mouseUp
answer gg
end mouseUp
Craig
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: What is the difference between....
..........
Last edited by [-hh] on Wed Aug 13, 2014 11:38 am, edited 1 time in total.
shiftLock happens
Re: What is the difference between....
Hermann - I had no idea that 'empty' could be so 'full' Congratulations - I need more wine...forget the cheese.
-
- VIP Livecode Opensource Backer
- Posts: 7215
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: What is the difference between....
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
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: What is the difference between....
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
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