COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

What is the explanation?

• Email
• Follow

```Hi,
Can anyone explain what is happening?
int x=0;
srand (time(NULL));
for (int i=0;i <100; i++)
{x =rand ()%9;
if ( x !=( 7||8))
printf ("%d  ",x);
}

Result of Print
5 8 7 4 8 3 0 7 2 8 2 7 6 7 5 7 8 3 0 0 6 5 0 4 7 6 5 8 5 2 0 2 0 6 4 8 7 3
2 6
2 3 6 2 3 7 2 5 5 6 3 7 2 3 7 4 4 2 5 6 0 4 5 4 4 5 0 5 6 7 5 3 6 3 2 0 5 0
0 5
7 5 8 6 3 2 2 8 3 6 8
Press any key to continue . . .

Question 1 :  Why is 1 missing here?

int x=0;
srand (time(NULL));
for (int i=0;i <100; i++)
{x =rand ()%9;
if ( (x != 7) || (x != 8))
printf ("%d  ",x);
}

Result of print
3 1 2 8 5 6 2 4 8 2 8 3 1 4 8 6 1 6 7 1 0 4 7 4 0 6 4 8 5 8 2 0 1 1 7 8 2 6
7 7
0 3 1 2 1 6 2 4 1 2 1 8 2 0 2 7 8 8 1 6 0 5 3 1 3 7 3 3 6 5 2 1 2 4 7 3 6 6
3 0
4 2 2 1 4 1 7 1 4 4 3 4 8 0 7 1 2 6 4 7
Press any key to continue . . .

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?
What is the correct statement to write?

Thank you
Khoon

```
 0
Reply tskhoon (58) 2/27/2010 6:16:14 AM

See related articles to this posting

```In article <4b88b869\$1_1@news.tm.net.my>, Tadpole <tskhoon@streamyx.com> wrote:
>if ( (x != 7) || (x != 8))

&&

--bks

```
 0
Reply bks (113) 2/27/2010 6:20:59 AM

```Thank you  Teacher.
I got it

"Bradley K. Sherman" <bks@panix.com> wrote in message
> In article <4b88b869\$1_1@news.tm.net.my>, Tadpole <tskhoon@streamyx.com>
> wrote:
>>if ( (x != 7) || (x != 8))
>
>               &&
>
>    --bks
>

```
 0
Reply tskhoon (58) 2/27/2010 6:36:13 AM

```Le 27/02/2010 07:16, Tadpole a �crit :

[...]
> if ( x !=( 7||8))

> Question 1 :  Why is 1 missing here?

The value of (7||8) is 1.

--
Richard
```
 0
Reply abulmo (47) 2/27/2010 8:03:28 AM

```"Richard Delorme" <abulmo@nospam.fr> wrote in message
> Le 27/02/2010 07:16, Tadpole a �crit :
>
> [...]
>> if ( x !=( 7||8))
>
>> Question 1 :  Why is 1 missing here?
>
> The value of (7||8) is 1.
>
> --
> Richard

Hi Richard,
Kindly explain why  or how (7||8) is 1 ?
I am amazed.

Khoon

```
 0
Reply tskhoon (58) 2/27/2010 10:50:56 AM

```Tadpole <tskhoon@streamyx.com> writes:
> "Richard Delorme" <abulmo@nospam.fr> wrote in message
>> Le 27/02/2010 07:16, Tadpole a �crit :
>>
>> [...]
>>> if ( x !=( 7||8))
>>
>>> Question 1 :  Why is 1 missing here?
>>
>> The value of (7||8) is 1.

> Hi Richard,
> Kindly explain why  or how (7||8) is 1 ?
> I am amazed.

The specs say so is the brief answer:

6.5.14 Logical OR operator
Syntax
1         logical-OR-expression:
logical-AND-expression
logical-OR-expression || logical-AND-expression
Constraints
2 Each of the operands shall have scalar type.

Semantics
3 The || operator shall yield 1 if either of its operands compare
unequal to 0; otherwise, it yields 0. The result has type int.

The && and || operators also perform left to right evaluation and if
the condition is met by the first operand itself, they will not
evaluate the rest of the operands. So in this case the literal 7 is
unequal to zero (C's value for boolean false), so the expression
yields one.

```
 0
Reply santosh.k83 (3969) 2/27/2010 11:07:47 AM

```"Tadpole" <tskhoon@streamyx.com> writes:

> "Richard Delorme" <abulmo@nospam.fr> wrote in message
>> Le 27/02/2010 07:16, Tadpole a �crit :
>>
>> [...]
>>> if ( x !=( 7||8))
>>
>>> Question 1 :  Why is 1 missing here?
>>
>> The value of (7||8) is 1.
>>
>> --
>> Richard
>
> Hi Richard,
> Kindly explain why  or how (7||8) is 1 ?
> I am amazed.
>
> Khoon

Any nonzero value in C is treated as true, 7 is nonzero and || operator
yields 1(true) if one of his operands is true. Also remember, that if
first operand is true, then there is no need to evaluate the second.
```
 0
Reply dmz1 (6) 2/27/2010 11:12:47 AM

```On 2010-02-27, Tadpole <tskhoon@streamyx.com> wrote:
> Kindly explain why  or how (7||8) is 1 ?

All non-zero values are true.  (x||y) is 1 if either x is true or y is true.

-s
--
Copyright 2010, all wrongs reversed.  Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
```
 0
Reply usenet-nospam (2309) 2/27/2010 8:11:24 PM

```In article <slrnhoivec.1a8.usenet-nospam@guild.seebs.net>, Seebs <usenet-nospam@seebs.net> writes:
> On 2010-02-27, Tadpole <tskhoon@streamyx.com> wrote:
>> Kindly explain why  or how (7||8) is 1 ?
>
> All non-zero values are true.  (x||y) is 1 if either x is true or y is true.

.... or both are true.

(Or perhaps my English is failing me; in that case, sorry.)

lacos
```
 0
Reply lacos (176) 2/27/2010 9:27:39 PM

```On 2010-02-27, Ersek, Laszlo <lacos@ludens.elte.hu> wrote:
> In article <slrnhoivec.1a8.usenet-nospam@guild.seebs.net>, Seebs <usenet-nospam@seebs.net> writes:
>> On 2010-02-27, Tadpole <tskhoon@streamyx.com> wrote:
>>> Kindly explain why  or how (7||8) is 1 ?
>>
>> All non-zero values are true.  (x||y) is 1 if either x is true or y is true.
>
> ... or both are true.
>
> (Or perhaps my English is failing me; in that case, sorry.)

English in general is failing you; the word "or" is ambiguous.

-s
--
Copyright 2010, all wrongs reversed.  Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
```
 0
Reply usenet-nospam (2309) 2/27/2010 10:12:11 PM

```Tadpole wrote:
)
) "Richard Delorme" <abulmo@nospam.fr> wrote in message
)> Le 27/02/2010 07:16, Tadpole a ?crit :
)>
)> [...]
)>> if ( x !=( 7||8))
)>
)>> Question 1 :  Why is 1 missing here?
)>
)> The value of (7||8) is 1.
)>
)> --
)> Richard
)
) Hi Richard,
) Kindly explain why  or how (7||8) is 1 ?
) I am amazed.

What do you expect the value of (7||8) to be ?

SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
```
 0
Reply willem7123 (117) 2/27/2010 10:39:26 PM

```On Sat, 27 Feb 2010 22:39:26 +0000 (UTC), in comp.lang.c, Willem
<willem@snail.stack.nl> wrote:

>)
>) "Richard Delorme" <abulmo@nospam.fr> wrote in message
>)> Le 27/02/2010 07:16, Tadpole a ?crit :
>)>
>)> [...]
>)>> if ( x !=( 7||8))
>)>
>)>> Question 1 :  Why is 1 missing here?
>)>
>)> The value of (7||8) is 1.
>)>
>)> --
>)> Richard
>)
>) Hi Richard,
>) Kindly explain why  or how (7||8) is 1 ?
>) I am amazed.
>
>What do you expect the value of (7||8) to be ?

I would not expect it to be 1.  I would just expect it to not be zero.

```
 0
Reply nobody79 (33) 2/28/2010 3:33:05 AM

```>>)
>>) Hi Richard,
>>) Kindly explain why  or how (7||8) is 1 ?
>>) I am amazed.
>>
>>What do you expect the value of (7||8) to be ?
>
> I would not expect it to be 1.  I would just expect it to not be zero.

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

```
 0
Reply tskhoon (58) 2/28/2010 4:43:31 AM

```Tadpole <tskhoon@streamyx.com> writes:

>>>)
>>>) Hi Richard,
>>>) Kindly explain why  or how (7||8) is 1 ?
>>>) I am amazed.
>>>
>>>What do you expect the value of (7||8) to be ?
>>
>> I would not expect it to be 1.  I would just expect it to not be
>> zero.
>
> No.  The answer is always 1. .  I have tested it and it gives me 1
> and no other number.

In such matters of minutiae, it's often better to actually check the
standard rather than check the visible behaviour of your particular
compiler.

But in this case, the standard mandates that the || op yield 1 if
either of it's operands is non-zero. I guess it's restricted to 1,
and not any non-zero value, for consistency and aesthetics.

```
 0
Reply santosh.k83 (3969) 2/28/2010 6:23:59 AM

```Scott wrote:
) On Sat, 27 Feb 2010 22:39:26 +0000 (UTC), in comp.lang.c, Willem
)<willem@snail.stack.nl> wrote:
)>What do you expect the value of (7||8) to be ?
)
) I would not expect it to be 1.  I would just expect it to not be zero.

Perhaps you should switch to Perl.  There, (a||b) is defined as (a?a:b)
(But, obviously, with a only being evaluated once).
And, incidentally, (a&&b) is defined as (a?b:a).

In C, the result of any boolean operator is always 0 or 1.
Dunno why, perhaps because existing compilers did it that way and
code existed that used the result of the boolean for arithmetics.

SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
```
 0
Reply willem7123 (117) 2/28/2010 10:08:27 AM

```Willem <willem@snail.stack.nl> writes:

> Scott wrote:
> ) On Sat, 27 Feb 2010 22:39:26 +0000 (UTC), in comp.lang.c, Willem
> )<willem@snail.stack.nl> wrote:
> )>What do you expect the value of (7||8) to be ?
> )
> ) I would not expect it to be 1.  I would just expect it to not be zero.
>
> Perhaps you should switch to Perl.  There, (a||b) is defined as (a?a:b)
> (But, obviously, with a only being evaluated once).
> And, incidentally, (a&&b) is defined as (a?b:a).
>
> In C, the result of any boolean operator is always 0 or 1.
> Dunno why, perhaps because existing compilers did it that way and
> code existed that used the result of the boolean for arithmetics.

Spectrum Basic did that well before Perl IIRC.  Useful for writing
things like:
PRINT a\$ OR 'nothing'
--
Online waterways route planner            | http://canalplan.eu
Plan trips, see photos, check facilities  | http://canalplan.org.uk
```
 0
Reply 3-nospam (285) 2/28/2010 10:41:04 AM

```On 2010-02-28, Nick <3-nospam@temporary-address.org.uk> wrote:
> Spectrum Basic did that well before Perl IIRC.  Useful for writing
> things like:
> PRINT a\$ OR 'nothing'

Lisp!

(or a1 a2 a3 ... an)

The arguments ai are evaluated in order, stopping at the first one which
yields true (a value other than nil), in which case that value is the
result.  Otherwise, the result is nil.

This feature is described in the Lisp 1.5 manual whose preface is dated
August 17, 1962. (Appendix A, Functions and Constants in the LISP
System).
```
 0
Reply kkylheku (2499) 2/28/2010 1:14:17 PM

```On Sun, 28 Feb 2010 10:08:27 +0000 (UTC), in comp.lang.c, Willem
<willem@snail.stack.nl> wrote:

>Scott wrote:
>) On Sat, 27 Feb 2010 22:39:26 +0000 (UTC), in comp.lang.c, Willem
>)<willem@snail.stack.nl> wrote:
>)>What do you expect the value of (7||8) to be ?
>)
>) I would not expect it to be 1.  I would just expect it to not be zero.
>
>Perhaps you should switch to Perl.

Eh.  No.  Just...no.

>In C, the result of any boolean operator is always 0 or 1.
>Dunno why, perhaps because existing compilers did it that way and
>code existed that used the result of the boolean for arithmetics.

Yes, yet writing C according to my stated assumption above still yeilds
semantically correct code.  And it keeps me in the right frame of mind,
without having to stop to think about it, to handle languages where
"true==1" isn't necessarily so, ultimately producing fewer bugs.
```
 0
Reply nobody79 (33) 2/28/2010 4:47:18 PM

```On 2010-02-28, Willem <willem@snail.stack.nl> wrote:
> Perhaps you should switch to Perl.  There, (a||b) is defined as (a?a:b)
> (But, obviously, with a only being evaluated once).
> And, incidentally, (a&&b) is defined as (a?b:a).

Ruby is the same way, at least with ||.

> In C, the result of any boolean operator is always 0 or 1.

PHP is the same way, at least with ||.

.... Note that if you happen to be doing two projects, both web based, one in
Ruby and one in PHP, this is a particularly irritating difference.

Although it's an extension, GNU C has a very nice way to express that:
a ?: b

I actually sorta wish that ISO C would pick that one up, it's very expressive.

-s
--
Copyright 2010, all wrongs reversed.  Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
```
 0
Reply usenet-nospam (2309) 2/28/2010 5:33:17 PM

```Scott wrote:
) On Sun, 28 Feb 2010 10:08:27 +0000 (UTC), in comp.lang.c, Willem
)<willem@snail.stack.nl> wrote:
)
)>Scott wrote:
)>) On Sat, 27 Feb 2010 22:39:26 +0000 (UTC), in comp.lang.c, Willem
)>)<willem@snail.stack.nl> wrote:
)>)>What do you expect the value of (7||8) to be ?
)>)
)>) I would not expect it to be 1.  I would just expect it to not be zero.
)>
)>Perhaps you should switch to Perl.
)
) Eh.  No.  Just...no.
)
)>In C, the result of any boolean operator is always 0 or 1.
)>Dunno why, perhaps because existing compilers did it that way and
)>code existed that used the result of the boolean for arithmetics.
)
) Yes, yet writing C according to my stated assumption above still yeilds
) semantically correct code.  And it keeps me in the right frame of mind,
) without having to stop to think about it, to handle languages where
) "true==1" isn't necessarily so, ultimately producing fewer bugs.

I was under the mistaken impression that I was talking to the same person
who was amazed that (7||8) yielded 1.  You know, the one that my question
was directed to.  Of course, I should have checked the name.  My apology.

SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
```
 0
Reply willem7123 (117) 2/28/2010 6:01:03 PM

```Scott wrote:

> Yes, yet writing C according to my stated assumption above
> still yeilds semantically correct code.
> And it keeps me in the right frame of mind,
> without having to stop to think about it, to handle languages where
> "true==1" isn't necessarily so, ultimately producing fewer bugs.

In C, it's better to think of it this way: (true != 0 && false == 0)

--
pete
```
 0
Reply pfiland (6614) 3/1/2010 3:10:34 AM

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

> What is the correct statement to write?

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 )

--
Kenneth Brody
```
 0
Reply kenbrody (1879) 3/1/2010 5:10:06 PM

```Kenneth Brody wrote:

> 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.
>
>> What is the correct statement to write?
>
> 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".

Do you want a Coke or a Pepsi?

```
 0
Reply r124c4u1022 (2303) 3/1/2010 5:17:58 PM

```Nick <3-nospam@temporary-address.org.uk> wrote:

> 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
```
 0
Reply raltbos (821) 3/1/2010 9:14:29 PM

```"osmium" <r124c4u102@comcast.net> wrote:

> Kenneth Brody wrote:
>
> > To a computer, the concepts of "and" and "or" are not exactly the
> > same as in spoken human communication.

> 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
```
 0
Reply raltbos (821) 3/1/2010 9:35:34 PM

```raltbos@xs4all.nl (Richard Bos) writes:

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

Hmm.  QL Basic then?  I certainly remember it from some Sinclair
programming.
--
Online waterways route planner            | http://canalplan.eu
Plan trips, see photos, check facilities  | http://canalplan.org.uk
```
 0
Reply 3-nospam (285) 3/1/2010 10:33:38 PM

```On Mar 1, 7:17=A0pm, "osmium" <r124c4u...@comcast.net> wrote:
> Kenneth Brody wrote:
> > On 2/27/2010 1:16 AM, Tadpole wrote:
> > [...]
> >> if ( (x !=3D 7) || (x !=3D 8))
> >> printf ("%d =A0",x);
> > [...]
> >> Question 2 : =A0I dont want 7 and =A08 to be printed. =A0X is not to b=
e 7
> >> or 8. But why they are still printed?
>
> > Because 8 it not equal to 7, and 7 is not equal to 8. =A0It is not
> > possible for "x !=3D 7" and "x !=3D 8" to both be false.
>
> >> What is the correct statement to write?
>
> > if ( (x !=3D 7) && (x !=3D 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". =A0If you tell a computer:
>
> > =A0 =A0 if ( state =3D=3D state_NY && state =3D=3D 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":
>
> > =A0 =A0 if ( state =3D=3D state_NY || state =3D=3D state_NJ )
>
> Which ignores the point made upstream that the English language is ambigu=
ous
> WRT the word "or".

No it doesn't, no it isn't, and !(x =3D=3D a || x =3D=3D b) is equivalent t=
o
(x !=3D a && x !=3D b).

> Do you want a Coke or a Pepsi?

Yes. I want a Coke, or a Pepsi. Make haste.
```
 0
Reply electricdelta (73) 3/2/2010 11:28:25 AM

```On 3/1/2010 4:35 PM, Richard Bos wrote:
> "osmium"<r124c4u102@comcast.net>  wrote:
>
>> Kenneth Brody wrote:
>>
>>> To a computer, the concepts of "and" and "or" are not exactly the
>>> same as in spoken human communication.
>
>> 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.

Q:  Do you know if the baby is going to be a boy or a girl?
A1: Yes.
A2: Well, I would certainly hope it is.

Q:  Do you know what time it is?
A:  [looks at watch] Yes.

--
Kenneth Brody
```
 0
Reply kenbrody (1879) 3/3/2010 7:58:00 PM

```"Tadpole" <tskhoon@streamyx.com> writes:
>>>)
>>>) Hi Richard,
>>>) Kindly explain why  or how (7||8) is 1 ?
>>>) I am amazed.
>>>
>>>What do you expect the value of (7||8) to be ?
>>
>> I would not expect it to be 1.  I would just expect it to not be zero.
>
> 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
--
I find the easiest thing to do is to k/f myself and just troll away
-- David Melville on r.a.s.f1
```
 0
Reply thefatphil_demunged (1651) 3/5/2010 8:46:12 AM

```Nick <3-nospam@temporary-address.org.uk> wrote:

> raltbos@xs4all.nl (Richard Bos) writes:
>
> >
> >> 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.
>
> 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
```
 0
Reply raltbos (821) 3/10/2010 2:14:33 PM

```raltbos@xs4all.nl (Richard Bos) writes:

>
>> raltbos@xs4all.nl (Richard Bos) writes:
>>
>> >
>> >> 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.
>>
>> 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.

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.
--
Online waterways route planner            | http://canalplan.eu
Plan trips, see photos, check facilities  | http://canalplan.org.uk
```
 0
Reply 3-nospam (285) 3/10/2010 6:19:27 PM

```Nick <3-nospam@temporary-address.org.uk> writes:
> raltbos@xs4all.nl (Richard Bos) writes:
>>> raltbos@xs4all.nl (Richard Bos) writes:
>>> >
>>> >> 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.
>>>
>>> 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.
>
> 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
--
I find the easiest thing to do is to k/f myself and just troll away
-- David Melville on r.a.s.f1
```
 0
Reply thefatphil_demunged (1651) 3/11/2010 11:53:30 PM

```Phil Carmody <thefatphil_demunged@yahoo.co.uk> writes:
>> raltbos@xs4all.nl (Richard Bos) writes:
>>>> raltbos@xs4all.nl (Richard Bos) writes:
>>>> >
>>>> >> 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.
>>>>
>>>> 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.
>>
>> 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?

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.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
```
 0
Reply kst-u (21963) 3/12/2010 12:42:37 AM

```On Mar 11, 5:53=A0pm, Phil Carmody <thefatphil_demun...@yahoo.co.uk>
wrote:

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

-=3DDave
```
 0
Reply iddw (680) 3/12/2010 3:46:25 PM

```Phil Carmody <thefatphil_demunged@yahoo.co.uk> writes:

>> raltbos@xs4all.nl (Richard Bos) writes:
>>>> raltbos@xs4all.nl (Richard Bos) writes:
>>>> >
>>>> >> 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.
>>>>
>>>> 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.
>>
>> 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?

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.
--
Online waterways route planner            | http://canalplan.eu
Plan trips, see photos, check facilities  | http://canalplan.org.uk
```
 0
Reply 3-nospam (285) 3/13/2010 8:52:36 AM

34 Replies
61 Views

Similar Articles

12/11/2013 12:52:07 PM
page loaded in 558879 ms. (0)

Similar Artilces:

Projects With Explanations
I was wondering if anyone is aware of any websites or books that cover the stated goals and display the completed code for various programs, and also includes in detail the explanations for what each and every character and line does.(I'm most interested in Assembly and C++). Thanks a lot. Darren Harris Staten Island, New York. <Searcher7@mail.con2.com> wrote in message news:1120755186.352470.10090@g43g2000cwa.googlegroups.com... > I was wondering if anyone is aware of any websites or books that cover > the stated goals and display the completed code for various programs, ...

subroutine explanation
I have some code created to takes some rules from external file and apply these rules on text file. My perl experience is somewhat limited and I was wondering if soneone on this group can give me an explanation of it. sub apply_rules { my (\$_txt, \$_rules) = @_; for (keys %{\$_rules}) { my \$exp = \$_; \$exp =~ s{\s}{\\s*}g; my \$re = \$_rules->{\$_}; my \$rslt; eval ("\\$rslt = \\$\\$_txt =~ s{\$exp}{\$re}gis"); printf " >Replaced '\$exp' %d times.\n", \$rslt; } } fred <fred78980@yahoo.com> wrote in comp.lang.perl.misc: > I have some...

Explanation of nullptr
I was googling for a discussion/explanation of the proposed "nullptr" keyword, but all I found were the proposals (n1488 and n2431), which were a bit bare-bones for a non-language-lawyer like myself, and some discussions to which "nullptr" was sort of tangential. Is there a good explanation/discussion of the ins and outs of "nullptr", by people who know what they're talking about, somewhere on the web? -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] On Feb 10, 4:49 pm...

RE explanation 29481
Could someone give me an explanation for each part of this regular expression ? /\b((?:(?=[a-z])[^aeiou])*[aeiou](?:(?=[a-z])[^aeiou])*)\b/ig Many thanks julia_2683@hotmail.com wrote: > Could someone give me an explanation for each part of this regular > expression ? > > /\b((?:(?=[a-z])[^aeiou])*[aeiou](?:(?=[a-z])[^aeiou])*)\b/ig Why? I'd suggest that you look it up at first hand: perldoc perlre and ask a question if there is anything specific you can't figure out that way. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl julia_2683...

makeExe.bat
Hello, An explanation of makeExe.bat (http://premshree.resource-locator.com/j/post.php?id=152) has been appended to (http://www.devx.com/opensource/Article/20247/0/page/3) "Create Python Executables Automatically" (http://www.devx.com/opensource/Article/20247/). -Premshree Pillai ===== -Premshree [http://www.qiksearch.com/] ________________________________________________________________________ Yahoo! India Insurance Special: Be informed on the best policies, services, tools and more. Go to: http://in.insurance.yahoo.com/licspecial/index.html ...

Best Power Over Ethernet Explanation
www.RouterGod.com ...

Need an example of tabular with explanation
I urgently need an example of table to play with. langlands@InterTwine.zzn.com ~~~~~~~~~~~~~~~~~~~~~ If you consider the content of this post to be particularly offensive, disgusting or plain illegal, it is probably 'designer abuse', a message designed specifically to hurt the remailer's reputation/existence. http://groups.google.com/groups?selm=6THHPRAL38002.4374074074%40anonymous&oe=UTF-8&output=gplain Some people hate this remailer so badly that, for example, they did not hesitate to celebrate the death of 148 French tourists in a plane crash. Those people seceded fr...

Time Machine Explanation for the Non-Geek
I'm interested in just how a Time Machine backup is structured, and I'll say right up front that I'm only minimally versed in UNIX and its internals. Is there a non-geeky document available that would provide a simple explanation? -- James Leo Ryan ..... Austin, Texas ..... taliesinsoft@me.com In article <0001HW.C5177EB20034B2CCB01AD9AF@News.Individual.NET>, TaliesinSoft <taliesinsoft@me.com> wrote: > I'm interested in just how a Time Machine backup is structured, and I'll say > right up front that I'm only minimally versed in UNIX and its int...

Online tutorials/explanations on code generation?
Hi all, I allready wrote several (small) interpreters, VMs, and coded in assembly for several CPUs. Next thing I'd like to try, is writing an compiler. Of course I could build something that somehow outputs assembly. But i'd like to have a quick overview of whats the "usual" method of doing this elegantly, and retargetable. (and I'd like to avoid browsing through such a beast as the GCC sources for that, or buying a book) So, can someone recommend a free site that highlights what happens between "fully parsed code" and "assembly output" - How opcod...

Seeking explanation for dual modems in 9680C
Trying to make sense of a friend's Pavilion 9680C that needed reformatting. He's lost the manuals but does have the restore CDs. Everything appears to have installed correctly even though there was an error message during the process. The thing I've never seen is the dual modem setup. There's only one listed in the device manager, a Conexant model. I pulled the other one out (labeled DSL-V90 modem w/ Lucent chipset), ran the Win98 'diagnostics' and the Conexant responded fine. Since the Lucent/DSL modem has only RJ-11 jacks instead of the RJ-45 I would expect for D...

Searching for explanations on the way a processor works
Hello, This question was maybe answered before, but I couldn't find it on the group. I'm searching for an explanation of the way instructions are interpreted by a processor, on the hardware point of view. I know about the bloc organization, but not about the low-level (logic gates) organization. For example, I would like to know how the circuits that correspond to an instruction are activated: is the opcode compared (using AND gates) to a matrix that contains every possible opcode, and the matching circuit is fed with the instruction? Do you know a good and detailed reference (on-line,...

Re: NeedURGENT CEIL Function Explanation #5
The Constant function calculates the minimum number of bytes for a particular range of integers. ======online doc======================= CONSTANT('EXACTINT' <, nbytes>) nbytes is a numeric value that is the number of bytes. Range: 2-8 Default: 8 The exact integer is the largest integer k such that all integers less than or equal to k in absolute value have an exact representation in a SAS numeric variable of length nbytes. This information can be useful to know before you trim a SAS numeric variable from the default 8 bytes of storage to a lower number of bytes to save storage...

problem with timing simulation (clear explanation of problem)
Hi all, to be more clear about my problem with timing simulation after i implement it using xilinx it is creating one TIME_SIM.VHD and TIME_SIM.SDF file under the folder "timing" it has an identifier "X_INV_PP" in both files when i compile TIME_SIM.VHD it is giving an error "Unknown identifier "X_INV_PP"" Cannot find component declaration did anyone come across similar kind of problem.please help me out thanks, Regards Ramakrishna you need to compile the simmprim vhdl library first. in your \$XILINX directory under /vhdl/src/simprims (replace \$XILIN...

Updated Stratix II Power Specs & Explanation
Hi, Today we released our updated power specs for Stratix II. Some highlights of the updates found in the Stratix II Early Power Estimator V2.1 tool: (1) Reduced static power by up to 47%. We've measured many units from across the product family, and have the data to tighten the spec compared to our previous conservative/estimated values. The amount of change varies from family member to family member, and is a function of junction temperature and whether typical or worst-case silicon is selected. (2) Static current on the VccPD rail now reflected (it is tiny) (3) There is no more i...

Online explanation of Dijkstra's Guarded Command Language
Hi, Google didn't find me a 'Dijkstra's Guarded Command Language' description. Can some one point me to an online reference. I'm interested in methods of 'transforming code' , other than lisp. I've started analysing M. Brandis' these of 1995 re. `guarded single-assignment form' compiler. [ for Oberon] His explanations, repeatedly branch off into discussions of optimisation, disrupting the flow of the basic understanding. Perhaps an understanding first of 'Guarded Command Language' would help ? This problem of resisting interesting s...

Where can I find a clear, thorough explanation of join tables etc.?
I'm relatively new to FM (8) and am trying to build a database for what seems to be an unorthodox purpose: keeping track of complex writing notes (i'm a playwright). For now I have tables for SECTIONS (acts, scenes etc) TOPICS (characters, themes etc) IDEAS (all kinds) TASKS and SOURCES (books, articles etc) and I've been attempting to create many to many relationships between these tables using unique ids and join tables that are linked in a kind of star formation with IDEAS at the center. Anyways, I realize this is probably not the ideal approach and I'm trying to get a st...

Re: Online explanation of Dijkstra's Guarded Command Language
(Chris Glur) wrote: > # > # Google didn't find me a 'Dijkstra's Guarded Command Language' > # description. Can some one point me to an online reference. SM Ryan wrote: > University of Texas has his papers on-line: > http://www.cs.utexas.edu/users/EWD/ > Perhaps somewhere in there. Yes, Thanks !! 3 articles on 'Dijkstra's Guarded Command Language' seen. 2 in *.pdf format [images of his type-written manuscripts] I fetched. It's good quality stuff. Tedious to re-type and try to understand at the same time. Some trivialising of Dijkstra's...

Where can I find a clear, thorough explanation of join tables etc.? #2
I'm relatively new to FM (8) and am trying to build a database for what seems to be an unorthodox purpose: keeping track of complex writing notes (i'm a playwright). For now I have tables for SECTIONS (acts, scenes etc) TOPICS (characters, themes etc) IDEAS (all kinds) TASKS and SOURCES (books, articles etc) and I've been attempting to create many to many relationships between these tables using unique ids and join tables that are linked in a kind of star formation with IDEAS at the center. Anyways, I realize this is probably not the ideal approach and I'm trying to get a st...

need explanation: something that works with \ operator doesnt work with lsqnonlin function
Hi, I have a LINEAR problem that I can solve using \ (slash) operator. I need to solve a NON_LINEAR version of this problem. For this I suppose I should use LSQNONLIN. I tried to use it and it doesn't work. I then tried for debug to plug into LSQNONLIN my linear problem and it doesnot work as well. Do you have an explanation to this? Thanks a lot for any help ...

further explanation re: FAQ 4.41 How can I remove duplicate elements from a list or array?
I just finished a small Perl program that goes through my outgoing Exchange server logs to harvest outgoing email address that are then added to my whitelist. I'm more of a Perl hack than hacker, so I won't post my dirty code that gets me to an array called @addresses containing all of the addresses in the outgoing mail logs, properly formatted. That array contained more than one copy of many of the email addresses. So I checked this NG (as I have many times before) and found the above captioned FAQ, using one of the suggested code snippets works perfectly, and all is well, but I still...