1. Syntax for OR

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

new topic     » topic index » view message » categorize

2. Re: Syntax for OR

cp said...

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: Syntax for OR


Use parentheses liberally, they come free with each OE installation.

if seqConn[1] = (1 or 3) then 
I tend to use equal() on everything, saves crashing from unequal sequence lengths and other nonsense.

Kat

new topic     » goto parent     » topic index » view message » categorize

4. Re: Syntax for OR

katsmeow said...


Use parentheses liberally, they come free with each OE installation.

if seqConn[1] = (1 or 3) then 
I 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

new topic     » goto parent     » topic index » view message » categorize

5. Re: Syntax for OR

Lnettnay said...
katsmeow said...


Use parentheses liberally, they come free with each OE installation.

if seqConn[1] = (1 or 3) then 
I 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".

Lnettnay said...
(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 ...

alternative said...

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.

new topic     » goto parent     » topic index » view message » categorize

6. Re: Syntax for OR

cp said...

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 
new topic     » goto parent     » topic index » view message » categorize

7. Re: Syntax for OR

DerekParnell said...

I'm sorry Lonny, but what isn't correct?

Erm, you state it below:

DerekParnell said...

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:

alternative said...
    1. 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.

DerekParnell said...

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

DerekParnell said...

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.

new topic     » goto parent     » topic index » view message » categorize

8. Re: Syntax for OR

jimcbrown said...
DerekParnell said...

I'm sorry Lonny, but what isn't correct?

Erm, you state it below:

DerekParnell said...

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

jimcbrown said...

From the context of the original post, I interpreted katsmeow's post to mean:

alternative said...
    1. 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.

jimcbrown said...
DerekParnell said...

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.

jimcbrown said...
DerekParnell said...

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.

new topic     » goto parent     » topic index » view message » categorize

9. Re: Syntax for OR

DerekParnell said...

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.

DerekParnell said...

However, I'd formed a different impression of the context for that post.

jimcbrown said...
DerekParnell said...

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.

DerekParnell said...
jimcbrown said...
DerekParnell said...

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!

new topic     » goto parent     » topic index » view message » categorize

10. Re: Syntax for OR

cp said...

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

new topic     » goto parent     » topic index » view message » categorize

11. Re: Syntax for OR

petelomax said...

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

-Greg

new topic     » goto parent     » topic index » view message » categorize

12. Re: Syntax for OR

DerekParnell said...
cp said...

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

new topic     » goto parent     » topic index » view message » categorize

13. Re: Syntax for OR

cp said...

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

new topic     » goto parent     » topic index » view message » categorize

14. Re: Syntax for OR

Lnettnay said...
katsmeow said...


Use parentheses liberally, they come free with each OE installation.

if seqConn[1] = (1 or 3) then 
I 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

new topic     » goto parent     » topic index » view message » categorize

15. Re: Syntax for OR

katsmeow said...

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:

cp said...

It seems that this syntax is supported ?

if seqConn[1] = 1 or 3 then 

Or

cp said...

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

new topic     » goto parent     » topic index » view message » categorize

16. Re: Syntax for OR

jimcbrown said...
katsmeow said...

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:

cp said...

It seems that this syntax is supported ?

if seqConn[1] = 1 or 3 then 

Or

cp said...

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.

new topic     » goto parent     » topic index » view message » categorize

17. Re: Syntax for OR

katsmeow said...

I wasn't going to guess.

But you did.

katsmeow said...

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

katsmeow said...

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.

katsmeow said...

Parentheses eliminate much of the arbitrary, and are second to comments to explain the intended program flow.

Absolutely.

katsmeow said...

guessing jimcbrown will feel compelled to post a response.

You guessed correctly.

new topic     » goto parent     » topic index » view message » categorize

18. Re: Syntax for OR

jimcbrown said...
katsmeow said...

I wasn't going to guess.

But you did.

I did not, it was completely a random grouping.

jimcbrown said...
katsmeow said...

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.

jimcbrown said...
katsmeow said...

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.

jimcbrown said...

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?

jimcbrown said...
katsmeow said...

Parentheses eliminate much of the arbitrary, and are second to comments to explain the intended program flow.

Absolutely.

katsmeow said...

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

new topic     » goto parent     » topic index » view message » categorize

19. Re: Syntax for OR

katsmeow said...

I did not, it was completely a random grouping.

Here's your response. I stand by my statement.

katsmeow said...


Use parentheses liberally, they come free with each OE installation.

if seqConn[1] = (1 or 3) then 
I tend to use equal() on everything, saves crashing from unequal sequence lengths and other nonsense.

Kat

katsmeow said...
jimcbrown said...
katsmeow said...

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.

katsmeow said...

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.

katsmeow said...
jimcbrown said...
katsmeow said...

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.

katsmeow said...
jimcbrown said...

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.

katsmeow said...

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.

katsmeow said...

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.

new topic     » goto parent     » topic index » view message » categorize

20. Re: Syntax for OR

jimcbrown said...

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

new topic     » goto parent     » topic index » view message » categorize

21. Re: Syntax for OR

katsmeow said...

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.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu