Hi,
I propose an alternative for the and/or layout in LC. e.g.:
current code:
if (gWhatever contains "blahBlah" and gWhatever contains "somethingElse") or (gWhatever is tAlternative and gOtherVar is true) then
suggested code:
if (gWhatever contains "blahBlah" and contains "somethingElse) or ( is tAlternative and gOtherVar is true) then
very good for things like
if gWhatever is var1 or is var2 or is var3 or is var4 then
-- code here
else if gWhatever is var5 or is var6 or is var7 or is var8 then
So it could work with and is , and contains, and there is, or is, or contains, or there is, etc, etc
if ... and is ...
Moderator: Klaus
Re: if ... and is ...
Hi,
I'm not sure that this is worth the hassle. I would have written the second example like this:
Kind regards,
Mark
I'm not sure that this is worth the hassle. I would have written the second example like this:
Code: Select all
if gWhatever is among the items of var1,var2,var3,var4 then
-- code here
else if gWhatever is var5 or is var6 or is var7 or is var8 then
-- more code here
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: if ... and is ...
'is among' is not the same as 'is'. e.g., gWhatever = cat, var1= catamaran, var2 = scatter gun, var3 = dog, var4 = mouse,... var7 = cat. - 'is among' will return a different answer to 'is'.
Besides, that works for one thing but not all. Plus, in the interest of making it more english, you don't repeat the proper noun after every conjunction. You would say "If myDrink is 'milked' and is 'sugared' and is 'hot' then \ iShallDrinkIt. We sound more like a 2 year olds if we add the noun or proper noun in each time. Whereas we could have it sounding a little more mature while not loosing the high level language of it
Besides, that works for one thing but not all. Plus, in the interest of making it more english, you don't repeat the proper noun after every conjunction. You would say "If myDrink is 'milked' and is 'sugared' and is 'hot' then \ iShallDrinkIt. We sound more like a 2 year olds if we add the noun or proper noun in each time. Whereas we could have it sounding a little more mature while not loosing the high level language of it

Re: if ... and is ...
Hi,
Surely, I get your point, but I just don't think it is worth the investment.
My example and your second exampel are definitely the same. Var1 is a or Var1 is b is exactly the same is Var1 is among the items of a,b.
Kind regards,
Mark
Surely, I get your point, but I just don't think it is worth the investment.
My example and your second exampel are definitely the same. Var1 is a or Var1 is b is exactly the same is Var1 is among the items of a,b.
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: if ... and is ...
Sean- I think your point is well taken - if the subject is already defined then there's no need to repeat it to apply the following clause. From the POV of a compiler designer, though, it raises some serious complexities, and I'm not sure how much rewriting it would take to shoehorn this in.
Your "is var1 or is var2..." example could of course be done with a switch statement, which I think is quite readable, but that doesn't address the natural language aspect of the statement, which I think is what you're talking about.
Hmmm... lemme see if I can come up with a preprocessor script for glx2 to handle this...
BTW: the "is in" construct is much faster than the "contains" construct because internally "contains" makes a new copy of the original to work with.
Your "is var1 or is var2..." example could of course be done with a switch statement, which I think is quite readable, but that doesn't address the natural language aspect of the statement, which I think is what you're talking about.
Hmmm... lemme see if I can come up with a preprocessor script for glx2 to handle this...
BTW: the "is in" construct is much faster than the "contains" construct because internally "contains" makes a new copy of the original to work with.
Re: if ... and is ...
Well, that was pretty easy - I wrote a preprocessor script to handle this situation and I'll include it with the next GLX2 release. Here's a test stack.
- Attachments
-
- Preprocessor.zip
- GLX2 script preprocessor tester
- (4.88 KiB) Downloaded 213 times