Page 1 of 1
if ... and is ...
Posted: Fri May 04, 2012 1:56 pm
by seaniepie
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
Re: if ... and is ...
Posted: Fri May 04, 2012 3:47 pm
by Mark
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
Re: if ... and is ...
Posted: Fri May 04, 2012 5:16 pm
by seaniepie
'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

Re: if ... and is ...
Posted: Fri May 04, 2012 5:25 pm
by Mark
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
Re: if ... and is ...
Posted: Fri May 04, 2012 5:56 pm
by mwieder
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.
Re: if ... and is ...
Posted: Sat May 05, 2012 12:08 am
by mwieder
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.