[comp.lang.icon] alternation surprise

naz@hslrswi.hasler.ascom.ch (Norman H. Azadian) (03/12/91)

I know my postings are starting to sound like an idiot's tour
of Icon.  Anyway, here's another "gotcha" I stumbled over.

	procedure main()
	local flag, x
		flag := 1
		(\flag)  |  (x := runerr(500))
		(\flag)  |  x := runerr(500)
	end

This dies on line 5, which I did not expect.  I guess alternation
has lower priority than assignment.  Pardon me while I go out and
stock up on parenthesis.

NHA
-- 
PAPER:  Norman Azadian; Ascom AG; Belpstrasse 23; 3000 Berne 14; Switzerland
INTERNET:  naz%hslrswi.uucp@uunet.uu.net
UUCP:   ...{uunet,ukc,mcvax,...}!chx400!hslrswi!naz
VOICE:  +41 31 63 2178            BITNET: naz%hslrswi.UUCP@cernvax.BITNET

goer@quads.uchicago.edu (Richard L. Goerwitz) (03/13/91)

Na@hslrswi.hasler.ascom.ch (Norman H. Azadian) writes:

>I know my postings are starting to sound like an idiot's tour
>of Icon.

If you want a real laugh, try taking a look at icon-group traffic
from, say, three years or so ago (when I was still just learning the
language).  The archives are on cs.arizona.edu (much to my chagrin
:-).

>
>	procedure main()
>	local flag, x
>		flag := 1
>		(\flag)  |  (x := runerr(500))
>		(\flag)  |  x := runerr(500)
>	end
>
>This dies on line 5, which I did not expect.  I guess alternation
>has lower priority than assignment.  Pardon me while I go out and
>stock up on parenthesis.

My golden rule, for a long time , was "conjunction has the lowest prece-
of any infix operation."  Everything else I parenthesized.

You may find that the precedence of alternation makes more sense if you
think of the very common idiom -

    intext :=open(\filename) | &input

-Richard