1. Syntax for OR
- Posted by cp Mar 03, 2015
- 1743 views
It seems that this syntax is supported ?
if seqConn[1] = 1 or 3 then
and is equivalent to..
if seqConn[1] = 1 or seqConn[1] = 3 then
casey
2. Re: Syntax for OR
- Posted by Lnettnay Mar 03, 2015
- 1685 views
It seems that this syntax is supported ?
if seqConn[1] = 1 or 3 then
and is equivalent to..
if seqConn[1] = 1 or seqConn[1] = 3 then
casey
I'm sorry cp but you are totally mistaken. What the parser is seeing is
if (seqConn[1] = 1) or (3)
and since the
(3) != 0
then the or is true.
To test this out
seqConn[1] = 2 if seqConn[1] = 1 or 3
and see what happens.
Lonny
3. Re: Syntax for OR
- Posted by katsmeow Mar 03, 2015
- 1675 views
Use parentheses liberally, they come free with each OE installation.
if seqConn[1] = (1 or 3) thenI tend to use equal() on everything, saves crashing from unequal sequence lengths and other nonsense.
Kat
4. Re: Syntax for OR
- Posted by Lnettnay Mar 04, 2015
- 1702 views
Use parentheses liberally, they come free with each OE installation.
if seqConn[1] = (1 or 3) thenI tend to use equal() on everything, saves crashing from unequal sequence lengths and other nonsense.
Kat
I'm sorry Kat, but that isn't correct.
(1 or 3) = 1 -- so if seqConn[1] = 3 -- then seqConn[1] = (1 or 3) will be false
Lonny
5. Re: Syntax for OR
- Posted by DerekParnell (admin) Mar 04, 2015
- 1644 views
Use parentheses liberally, they come free with each OE installation.
if seqConn[1] = (1 or 3) thenI tend to use equal() on everything, saves crashing from unequal sequence lengths and other nonsense.
Kat
I'm sorry Kat, but that isn't correct.
I'm sorry Lonny, but what isn't correct? The syntax is correct. The use of parenthesis is correct. The intended result maybe correct, if we knew what the code intended by the code. So without that sort of context, it would be presumptuous to assume that Kat's code is "incorrect".
(1 or 3) = 1 -- so if seqConn[1] = 3 -- then seqConn[1] = (1 or 3) will be false
Lonny
But ...
(1 or 3) = 1 -- so if seqConn[1] = 1 -- then seqConn[1] = (1 or 3) will be true
So maybe you might have been more accurate to say something along the lines of ...
It is incorrect that if A = (B or C) ... is equivalent to if (A = B) or (A = C) then ..., however, the idea that using parenthesis to explicitly highlight your coding intentions is a good one.
6. Re: Syntax for OR
- Posted by DerekParnell (admin) Mar 04, 2015
- 1644 views
It seems that this syntax is supported ?
if seqConn[1] = 1 or 3 then
and is equivalent to..
if seqConn[1] = 1 or seqConn[1] = 3 then
casey
As said by others, this type of shortcut is not supported. The operator precedence rules means that in the absence of parenthesis,
if seqConn[1] = 1 or 3 then
and is really equivalent to..
if (seqConn[1] = 1) or (3) then
or to use really longhand ...
if (seqConn[1] = 1) then ... elsif (3) then ... end if
7. Re: Syntax for OR
- Posted by jimcbrown (admin) Mar 04, 2015
- 1673 views
I'm sorry Lonny, but what isn't correct?
Erm, you state it below:
It is incorrect that if A = (B or C) ... is equivalent to if (A = B) or (A = C) then ...
From the context of the original post, I interpreted katsmeow's post to mean:
- if A = (B or C) ... is equivalent to if (A = B) or (A = C) then ...##
And I think that's a reasonable interpretation of katsmeow's words.
So without that sort of context, it would be presumptuous to assume that Kat's code is "incorrect".
I would think OP's post provides enough context... if katsmeow intended to speak about something different, then I think that katsmeow should have provided additional context herself to make this clear. (OTOH, when posting in a hurry or on the run, it's possible to make minor mistakes and forget to include things. It happens, it's no big deal, the important bit is to obtain clarification after the fact. It's also possible that this is a "joke" post, where katsmeow is trying to alert the OP about the possible traps due to the lack of an explicit boolean type in Euphoria - but in that case, some initial confusion is to be expected.)
if we knew what the code intended by the code.
After spending several minutes rereading this line, I still do not understand what it means.
8. Re: Syntax for OR
- Posted by DerekParnell (admin) Mar 04, 2015
- 1660 views
I'm sorry Lonny, but what isn't correct?
Erm, you state it below:
It is incorrect that if A = (B or C) ... is equivalent to if (A = B) or (A = C) then ...
However Jim, nobody actually said that those two fragments were identical. If somebody had said that, THEN one could say "you are incorrect" - but no one did say it. True, it might have been implied, but we do not KNOW that. It would still be an assumption on our part.
I feel that if there's an assumption, then when trying to address it, one should spell out what one assumes while offering a 'correction'.
From the context of the original post, I interpreted katsmeow's post to mean:
- if A = (B or C) ... is equivalent to if (A = B) or (A = C) then ...##
And I think that's a reasonable interpretation of katsmeow's words.
Yes, to preface one's correction with our interpretation of something is a good thing, I believe.
However, I'd formed a different impression of the context for that post. I am under the impression that the major point was concerning the use of parenthesis in order to avoid misunderstandings re operator precedence. The example that Kat gave, with parenthesis, demonstrated a perfectly correct (but arguably suboptimal - because of the use of literals) syntax. For instance, the example could have been generalized to something like ...
if seqConn[1] = (condition_A or condition_B) then ...
which is just fine.
So without that sort of context, it would be presumptuous to assume that Kat's code is "incorrect".
I would think OP's post provides enough context...
Well ... maybe not so much, seeing that you and I see different 'context' for the post.
if we knew what the code intended by the code.
After spending several minutes rereading this line, I still do not understand what it means.
Yep - my mistake. I left out a 'r'. I'm surprised you didn't pick that one.
9. Re: Syntax for OR
- Posted by jimcbrown (admin) Mar 04, 2015
- 1615 views
However Jim, nobody actually said that those two fragments were identical. If somebody had said that, THEN one could say "you are incorrect" - but no one did say it. True, it might have been implied, but we do not KNOW that. It would still be an assumption on our part.
I feel that if there's an assumption, then when trying to address it, one should spell out what one assumes while offering a 'correction'.
Agreed. No argument from me here.
However, I'd formed a different impression of the context for that post.
So without that sort of context, it would be presumptuous to assume that Kat's code is "incorrect".
I would think OP's post provides enough context...
Well ... maybe not so much, seeing that you and I see different 'context' for the post.
Good point. I concede.
if we knew what the code intended by the code.
After spending several minutes rereading this line, I still do not understand what it means.
Yep - my mistake. I left out a 'r'. I'm surprised you didn't pick that one.
D'oh!
10. Re: Syntax for OR
- Posted by petelomax Mar 04, 2015
- 1630 views
It seems that this syntax is supported ?
if seqConn[1] = 1 or 3 then
and is equivalent to..
if seqConn[1] = 1 or seqConn[1] = 3 then
casey
As others have said that is not what it does, I believe the language construct you are looking for is
if find(seqConn[1],{1,3})!=0 then
The "!=0" could legally be omitted, but I think it clarifies the intent.
Perhaps the language should have the construct
if seqConn[1] in {1,3} then
but at present it does not, and I'm not sure if that would play nicely with maps - perhaps someone who uses them regularly could chime in.
Pete
11. Re: Syntax for OR
- Posted by ghaberek (admin) Mar 04, 2015
- 1624 views
I believe the language construct you are looking for is
if find(seqConn[1],{1,3})!=0 then
The "!=0" could legally be omitted, but I think it clarifies the intent.
Came here to say this. Leaving satisfied.
-Greg
12. Re: Syntax for OR
- Posted by Lnettnay Mar 04, 2015
- 1646 views
It seems that this syntax is supported ?
if seqConn[1] = 1 or 3 then
and is equivalent to..
if seqConn[1] = 1 or seqConn[1] = 3 then
casey
As said by others, this type of shortcut is not supported. The operator precedence rules means that in the absence of parenthesis,
if seqConn[1] = 1 or 3 then
and is really equivalent to..
if (seqConn[1] = 1) or (3) then
or to use really longhand ...
if (seqConn[1] = 1) then ... elsif (3) then ... end if
But the problem is that those two code segments are not equivalent!
if (seqConn[1] = 1) or (3) then
will always be true but
if (seqConn[1] = 1) then ... -- path A elsif (3) then ... -- path B end if
will only execute path A if seqConn[1] = 1 and will execute path B in all other cases.
Lonny
13. Re: Syntax for OR
- Posted by _tom (admin) Mar 04, 2015
- 1620 views
It seems that this syntax is supported ?
if seqConn[1] = 1 or 3 then
and is equivalent to..
if seqConn[1] = 1 or seqConn[1] = 3 then
casey
The way to resolve a syntax question is to write some code!
- Simplify: seqConn[1] could be an object; test with atoms first
- Execute: write some working code
-- test by runnning different values -- | -- v atom sc = 2 if sc = 1 or 3 then puts(1, "found" ) else puts(1, "not found" ) end if --> found -- not the intended result
What is going on?
Order of operations means sc = 1 is evaluated first. The result of this snippet may be either 0 (false) or 1 (true).
Next you evaluate one of two possible remaining expressions. You need to refer to logic true tables for this:
0 or 3 -- true 1 or 3 -- true
The "surprise" is that you always get true.
atom sc = 2 if sc = 1 or sc = 3 then puts(1, "found" ) else puts(1, "not found" ) end if --> not found
This code makes more sense.
atom sc = 3 if sc = ( 1 or 3 ) then puts(1, "found" ) else puts(1, "not found" ) end if --> not found
The parentheses get evaluated first:
1 or 3 -- true
Next you evaluate
sc = 1
Since 3 does not equal 1 you get "not found" which is not the "intended" result. The "trap" in this example that sc=1 works as intended and all other values work as intended.
If you think outside of the box, as Pete does, you end up with:
atom sc = 2 if find( sc, {1,3} ) then puts(1, "found" ) else puts(1, "not found" ) end if --> not found
This works as "intended."
An alternative approach:
atom sc = 3 switch sc do case 1, 3 then puts(1, "found" ) case else puts(1, "not found" ) end switch --> found
Rant... always answer a question with working code.
_tom
14. Re: Syntax for OR
- Posted by katsmeow Mar 04, 2015
- 1650 views
Use parentheses liberally, they come free with each OE installation.
if seqConn[1] = (1 or 3) thenI tend to use equal() on everything, saves crashing from unequal sequence lengths and other nonsense.
Kat
I'm sorry Kat, but that isn't correct.
How do we know test what he intended?, he didn't use parenthesis!
Kat
15. Re: Syntax for OR
- Posted by jimcbrown (admin) Mar 04, 2015
- 1675 views
How do we know test what he intended?, he didn't use parenthesis!
Good point. The OP - using a gender-neutral name - did not say which test was intended:
It seems that this syntax is supported ?
if seqConn[1] = 1 or 3 then
Or
and is equivalent to..
if seqConn[1] = 1 or seqConn[1] = 3 then
casey
If I had to guess though, I'd go with the second one. It seems very unlikely that the first test would ever be intended, since it is always true (and not in a place like a loop where one might want an always true test to perform an infinite loop).
16. Re: Syntax for OR
- Posted by katsmeow Mar 04, 2015
- 1657 views
How do we know test what he intended?, he didn't use parenthesis!
Good point. The OP - using a gender-neutral name - did not say which test was intended:
It seems that this syntax is supported ?
if seqConn[1] = 1 or 3 then
Or
and is equivalent to..
if seqConn[1] = 1 or seqConn[1] = 3 then
casey
If I had to guess though, I'd go with the second one. It seems very unlikely that the first test would ever be intended, since it is always true (and not in a place like a loop where one might want an always true test to perform an infinite loop).
I wasn't going to guess. The specified '1' and '3' may have been easier to type for this illustration than the actual numerals in the actual code. I knew when i posted the first time that '(1 or 3)' could be reduced, but the secondary point i was making is next year the OP may not realise what his code was doing, and may be guessing as much as we were. Parentheses eliminate much of the arbitrary, and are second to comments to explain the intended program flow.
Kat,
guessing jimcbrown will feel compelled to post a response.
17. Re: Syntax for OR
- Posted by jimcbrown (admin) Mar 04, 2015
- 1657 views
I wasn't going to guess.
But you did.
The specified '1' and '3' may have been easier to type for this illustration than the actual numerals in the actual code. I knew when i posted the first time that '(1 or 3)' could be reduced,
But (unless both numerals are zero) it's always reduced to the same value, regardless. I don't see how typing '(1 or 3)' is easier than just typing '1'.
but the secondary point i was making is next year the OP may not realise what his code was doing, and may be guessing as much as we were.
Aha! So Derek's interpretation was slighly off - this was a secondary point, not a major point!
I also support having the OP making nirs code as readable as possible by proper use of parentheses, as you suggest below.
Parentheses eliminate much of the arbitrary, and are second to comments to explain the intended program flow.
Absolutely.
guessing jimcbrown will feel compelled to post a response.
You guessed correctly.
18. Re: Syntax for OR
- Posted by katsmeow Mar 04, 2015
- 1659 views
I wasn't going to guess.
But you did.
I did not, it was completely a random grouping.
The specified '1' and '3' may have been easier to type for this illustration than the actual numerals in the actual code. I knew when i posted the first time that '(1 or 3)' could be reduced,
But (unless both numerals are zero) it's always reduced to the same value, regardless. I don't see how typing '(1 or 3)' is easier than just typing '1'.
It's not always reduced, i didn't reduce it, i typed it out, same as the OP did.
but the secondary point i was making is next year the OP may not realise what his code was doing, and may be guessing as much as we were.
Aha! So Derek's interpretation was slighly off - this was a secondary point, not a major point!
Why do you care so much? What Derek said is also valid.
I also support having the OP making nirs code as readable as possible by proper use of parentheses, as you suggest below.
This is the third(?) time you openly question the sex and/or gender of the OP. Why do you care so much? Is this like irc, where the answer depends on the OP's genitals or their cultural roles?
Parentheses eliminate much of the arbitrary, and are second to comments to explain the intended program flow.
Absolutely.
guessing jimcbrown will feel compelled to post a response.
You guessed correctly.
This series of snappy follow-ups, where you must respond to everything i post, and take apart to analyse everything i say, is usually the precursor to a fight.
Kat
19. Re: Syntax for OR
- Posted by jimcbrown (admin) Mar 04, 2015
- 1609 views
I did not, it was completely a random grouping.
Here's your response. I stand by my statement.
Use parentheses liberally, they come free with each OE installation.
if seqConn[1] = (1 or 3) thenI tend to use equal() on everything, saves crashing from unequal sequence lengths and other nonsense.
Kat
The specified '1' and '3' may have been easier to type for this illustration than the actual numerals in the actual code. I knew when i posted the first time that '(1 or 3)' could be reduced,
But (unless both numerals are zero) it's always reduced to the same value, regardless. I don't see how typing '(1 or 3)' is easier than just typing '1'.
It's not always reduced,
It is always reduced by the interpreter.
i didn't reduce it, i typed it out, same as the OP did.
Conceded. Still sounds like this should be (slightly) harder, not easier.
but the secondary point i was making is next year the OP may not realise what his code was doing, and may be guessing as much as we were.
Aha! So Derek's interpretation was slighly off - this was a secondary point, not a major point!
Why do you care so much? What Derek said is also valid.
Edit: Basically, I see this as meaning both Derek and I were off. But Derek's version was a whole lot closer and thus more correct than mine.
I think this merely reaffirms Derek's main point - for the purposes of clarity, it's best to spell out as much as possible, including what one's assumptions are.
I also support having the OP making nirs code as readable as possible by proper use of parentheses, as you suggest below.
This is the third(?) time
I haven't been keeping track.
you openly question the sex and/or gender of the OP. Why do you care so much? Is this like irc, where the answer depends on the OP's genitals or their cultural roles?
I'm not openly questioning the gender of the OP. I don't care about that, I'm simply refusing - unlike some others here - to assume that the OP is male until told otherwise.
This series of snappy follow-ups, where you must respond to everything i post, and take apart to analyse everything i say, is usually the precursor to a fight.
Then, perhaps it makes sense to take things off of the forum here. I think you and others have already provided all the necessary technical information to the OP to answer the OP's original question from all angles.
With that in mind, if you wish to make a response to this post, I invite you to reply to me privately through either _tom or ChrisB, by emailing them.
20. Re: Syntax for OR
- Posted by katsmeow Mar 04, 2015
- 1635 views
Then, perhaps it makes sense to take things off of the forum here. I think you and others have already provided all the necessary technical information to the OP to answer the OP's original question from all angles.
With that in mind, if you wish to make a response to this post, I invite you to reply to me privately through either _tom or ChrisB, by emailing them.
I thought the same yesterday, when the OP's question was quickly answered, and when it became more important for you to address me.
I still see no button for contacting the admin. Is the protocol still to sift thru all the posts until an email address is found, and hope it's correct and monitored?
Kat
21. Re: Syntax for OR
- Posted by jimcbrown (admin) Mar 04, 2015
- 1601 views
I still see no button for contacting the admin. Is the protocol still to sift thru all the posts until an email address is found, and hope it's correct and monitored?
Hmm. It's even worse than that. _tom's most current email has never been posted on the forum, so even shifting through posts won't help here.
Let me think about this. I'll have one of the other admins get back to you with a solution in a few days at most.