if ... and is ...

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderator: Klaus

Post Reply
seaniepie
Posts: 154
Joined: Wed Sep 07, 2011 10:56 am

if ... and is ...

Post by seaniepie » Fri May 04, 2012 1:56 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: if ... and is ...

Post by Mark » Fri May 04, 2012 3:47 pm

Hi,

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
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

seaniepie
Posts: 154
Joined: Wed Sep 07, 2011 10:56 am

Re: if ... and is ...

Post by seaniepie » Fri May 04, 2012 5:16 pm

'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 :D

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: if ... and is ...

Post by Mark » Fri May 04, 2012 5:25 pm

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
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

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: if ... and is ...

Post by mwieder » Fri May 04, 2012 5:56 pm

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.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: if ... and is ...

Post by mwieder » Sat May 05, 2012 12:08 am

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

Post Reply