lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 16/09/10 13:29, Roberto Ierusalimschy wrote:
[...]
> Pascal was quite confusing for me. I could never remember to add
> parentheses to expressions like "x >= 0 and x <= 10". To give 'and'
> and '*' the same priority is an example of a logical, simple, and bad
> decision.

Practically everyone I know --- including me --- use parentheses
everywhere in C simply because that's the only way to keep things
straight in our heads. I'd represent the above as '((x >= 0) && (x <=
10))', for example.

> A (the?) great source of confusion in C priorities is '&' and '|',
> which for historical reasons have a "wrong" priority.

The one that always gets me is this:

i = i + j<<10;

(<< has a lower priority than +!)

But what's the issue with & and |? & has a higher priority than |, which
is what I'd expect (boolean multiply vs boolean add). Of course, many
years of C programming may have twisted my mind...

-- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│
│ life←{ ↑1 ⍵∨.^3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵ }
│ --- Conway's Game Of Life, in one line of APL

Attachment: signature.asc
Description: OpenPGP digital signature