1. brain gymnastics
- Posted by Tor Gausen <tor.gausen at C2I.NET> Jun 01, 2000
- 538 views
Check out this perfectly legal (promise!) Euphoria program, what value do you suppose will be printed? integer i i = 1 i = -i i /= i+1 +i = +i i *= i-1 -i = -i ? i
2. Re: brain gymnastics
- Posted by simulat <simulat at INTERGATE.BC.CA> Jun 01, 2000
- 508 views
This program sure behaves strangely on my system. It should give divide by zero error at i /= i+1 but it doesn't - but it will if you remove the line following. Huh? Bye Martin ----- Original Message ----- From: Tor Gausen <tor.gausen at C2I.NET> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Thursday, June 01, 2000 1:38 AM Subject: brain gymnastics > Check out this perfectly legal (promise!) Euphoria > program, what value do you suppose will be printed? > > integer i > > i = 1 > > i = -i > > i /= i+1 > > +i = +i > > i *= i-1 > > -i = -i > > ? i >
3. Re: brain gymnastics
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET> Jun 01, 2000
- 523 views
And it will also give divide by zero error *at the final print i* if you just insert a print i right after i /= i+1 !?! Dan Moyer -----Original Message----- >This program sure behaves strangely on my system. >It should give divide by zero error at i /= i+1 but it doesn't - but it will >if you remove the line following. >Huh? > >Bye >Martin > >----- Original Message ----- >From: Tor Gausen <tor.gausen at C2I.NET> >To: <EUPHORIA at LISTSERV.MUOHIO.EDU> >Sent: Thursday, June 01, 2000 1:38 AM >Subject: brain gymnastics > > >> Check out this perfectly legal (promise!) Euphoria >> program, what value do you suppose will be printed? >> >> integer i >> >> i = 1 >> >> i = -i >> >> i /= i+1 >> >> +i = +i >> >> i *= i-1 >> >> -i = -i >> >> ? i >>
4. Re: brain gymnastics
- Posted by Colin Taylor <ctaylor at RACSA.CO.CR> Jun 01, 2000
- 499 views
This program is easier to understand if you format it like this: integer i i = 1 i = -i i /= i+1+(i = +i) -- this statement originally on 2 lines i *= i-1-(i = -i) -- this statement originally on 2 lines ? i Colin Taylor ----- Original Message ----- From: Tor Gausen <tor.gausen at C2I.NET> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Thursday, June 01, 2000 3:38 AM Subject: brain gymnastics > Check out this perfectly legal (promise!) Euphoria > program, what value do you suppose will be printed? > > integer i > > i = 1 > > i = -i > > i /= i+1 > > +i = +i > > i *= i-1 > > -i = -i > > ? i >
5. Re: brain gymnastics
- Posted by Jeff Zeitlin <jzeitlin at CYBURBAN.COM> Jun 02, 2000
- 498 views
On Fri, 2 Jun 2000 00:01:53 -0400, Tor Gausen <tor.gausen at C2I.NET> wrote: > Check out this perfectly legal (promise!) Euphoria > program, what value do you suppose will be printed? > integer i > i = 1 > i = -i > i /= i+1 You should get an error here, at run time - you're dividing by zero. > +i = +i > i *= i-1 > -i = -i > ? i -- Jeff Zeitlin jzeitlin at cyburban.com
6. Re: brain gymnastics
- Posted by Jeff Zeitlin <jzeitlin at CYBURBAN.COM> Jun 02, 2000
- 480 views
Whoops - Jeff is just a little red-faced, having forgotten that a line break is _not_ a statement separator in Euphoria... -- Jeff Zeitlin jzeitlin at cyburban.com
7. Re: brain gymnastics
- Posted by =?iso-8859-1?B?U2tvZGE=?= <tone.skoda at SIOL.NET> Jun 03, 2000
- 510 views
> Whoops - Jeff is just a little red-faced, having forgotten that a > line break is _not_ a statement separator in Euphoria... > i /= i+1 You should get an error here, at run time - you're dividing by zero. > +i = +i Now I understand! This shouldnt be like this!?
8. Re: brain gymnastics
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> Jun 04, 2000
- 484 views
> > integer i > > i = 1 > > i = -i > > i /= i+1 [note a] > > +i = +i [note b] > > i *= i-1 [note c] > > -i = -i > > ? i integer i i = 1 i = -1 i = i / ( i + 1 + ( i = +i ) ) i = i * ( ( i -1 ) - (i = -i) ) ? i Does precize the same. notice: a sign is first considered to be part of a calculating (i.e. statement contiuator: 3 + 4; 5 - 7) secondly part of the number (i.e. sign: -3; + 4) .. notice: self reflecting calculations (such as *=, /=, +=, -=) convert to this form: [left] [*/+-]= [right] [left] = [left] [*/+-] ( [right] ) Everything on the right is used on the calculation. So: i /= i -1 +i = +i Converts to: i = i / ( i -1 + (i = +i) ) And will therefor not crash. More cynically explained: euphoria can be just as messy as C. Ralf N.
9. Re: brain gymnastics
- Posted by "Carl R. White" <cyrek at BIGFOOT.COM> Jun 05, 2000
- 545 views
On Sun, 4 Jun 2000 15:10:33 +0200, Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> wrote: >> > integer i >> > i =3D 1 >> > i =3D -i >> > i /=3D i+1 [note a] >> > +i =3D +i [note b] >> > i *=3D i-1 [note c] >> > -i =3D -i >> > ? i > >integer i >i =3D 1 >i =3D -1 >i =3D i / ( i + 1 + ( i =3D +i ) ) >i =3D i * ( ( i -1 ) - (i =3D -i) ) >? i > >Does precize the same. Run the two programs as they stand, Ralf. Yours returns '2'. The first returns '0'... I made the same mistake right after I'd figured out the linebreak trick... I've noticed those who have tried to solve Tor's problem have all been doing the same thing: There's a tendency to see (things like): a *=3D a + b + c =3D d -- Uh-oh. ...as: a =3D a * (a + b + (c =3D d)) -- Multiply 'a' by (a + b) if c !=3D d, and (a + b + 1) if c =3D d. ...when we should be reading it as: a =3D a * ((a + b + c) =3D d) -- Make 'a' zero if (a + b + c) =3D d, leave it alone otherwise. Yet in situations like this: if a + b + c =3D d then... ...we know exactly what the expression means! I reckon that this is some kind of "codical" illusion, and also a darn good argument for using parentheses to make expressions more readable. Carl -- Insert clich=E9 about inserting witty comment here, here.