What is the explanation?

R

Richard Bos

Nick said:
Spectrum Basic did that well before Perl IIRC. Useful for writing
things like:
PRINT a$ OR 'nothing'

YDNRC. That statement is illegal in Speccy BASIC, and even
PRINT a OR 4
prints 1 regardless of the value of a.

Richard
 
R

Richard Bos

Which ignores the point made upstream that the English language is ambiguous
WRT the word "or".

Do you want a Coke or a Pepsi?

No. I agree with my computer on this.

Richard
 
N

Nick

YDNRC. That statement is illegal in Speccy BASIC, and even
PRINT a OR 4
prints 1 regardless of the value of a.

Hmm. QL Basic then? I certainly remember it from some Sinclair
programming.
 
M

Michael Foukarakis

Kenneth said:
On 2/27/2010 1:16 AM, Tadpole wrote:
[...]
if ( (x != 7) || (x != 8))
printf ("%d  ",x); [...]
Question 2 :  I dont want 7 and  8 to be printed.  X is not to be 7
or 8. But why they are still printed?
Because 8 it not equal to 7, and 7 is not equal to 8.  It is not
possible for "x != 7" and "x != 8" to both be false.
if ( (x != 7) && (x != 8) )
To a computer, the concepts of "and" and "or" are not exactly the
same as in spoken human communication.
Consider "show me a list of clients living in New York and New
Jersey".  If you tell a computer:
    if ( state == state_NY && state == state_NJ )
you're not going to get very many hits, because the state cannot be
both New York _and_ New Jersey at the same time.
The "correct" way to ask is "show me a list of clients whose address
is either New York _or_ New Jersey":
    if ( state == state_NY || state == state_NJ )

Which ignores the point made upstream that the English language is ambiguous
WRT the word "or".

No it doesn't, no it isn't, and !(x == a || x == b) is equivalent to
(x != a && x != b).
Do you want a Coke or a Pepsi?

Yes. I want a Coke, or a Pepsi. Make haste.
 
P

Phil Carmody

Tadpole said:
No. The answer is always 1. . I have tested it and it gives me 1 and no
other number.

Wrong thing to do. Testing proves nothing. Only looking at the
language definition tells what you should expect from a language
contruct. Testing just tells you if a particular implementation
follows that standard in that particular case.

Phil
 
R

Richard Bos

Nick said:
Hmm. QL Basic then? I certainly remember it from some Sinclair
programming.

Possibly. The QL manual isn't clear (it only talks of "true" and
"false", never of their numerical values). However, one (not entirely
default) emulator seems to think not.

Richard
 
N

Nick

Possibly. The QL manual isn't clear (it only talks of "true" and
"false", never of their numerical values). However, one (not entirely
default) emulator seems to think not.

I'm now baffled. I came across it many years ago, and can't think where
else it might be. It seems to be a Python idiom, but my experience was
a long time before that. I liked it so much I made my own language do
it. Most odd.
 
P

Phil Carmody

Nick said:
I'm now baffled. I came across it many years ago, and can't think where
else it might be. It seems to be a Python idiom, but my experience was
a long time before that. I liked it so much I made my own language do
it. Most odd.

Perl's older than python by quite a way. Is there any chance you're
thinking of that?

Phil
 
K

Keith Thompson

Phil Carmody said:
Perl's older than python by quite a way. Is there any chance you're
thinking of that?

Using "||" or "or" for control flow is a common Perl idiom:

open $FILE, '<', "foo.txt" or die "foo.txt: $!\n";

which is equivalent to:

if (not open $FILE, '<', "foo.txt") {
die "foo.txt: $!\n";
}

And Perl got it from Bourne shell programming.
 
D

Dave Hansen

Perl's older than python by quite a way. Is there any chance you're
thinking of that?

For sufficiently small values of "quite a way" (Perl: 1987, Python:
1989).

Regards,

-=Dave
 
N

Nick

Phil Carmody said:
Perl's older than python by quite a way. Is there any chance you're
thinking of that?

Definitely pre-Perl. I've never seriously done any Perl - and certainly
not enough to have picked this up. And I certainly didn't invent it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top