Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^10: next unless condition

by oiskuu (Hermit)
on Apr 06, 2016 at 22:19 UTC ( #1159769=note: print w/replies, xml ) Need Help??


in reply to Re^9: next unless condition
in thread next unless condition

Quirks and programming. The topic reminded me of an old C book flush with anecdotal wisdom and insight (though old by now: it predates C99). The following note is preserved there:

From decvax!harpo!npoiv!alice!research!dmr
Date: Fri Oct 22 01:04:10 1982
Subject: Operator precedence
Newsgroups: net.lang.c

The priorities of && || vs. == etc. came about in the following way.

Early C had no separate operators for & and && or | and ||. (Got that?) Instead it used the notion (inherited from B and BCPL) of "truth-value context": where a Boolean value was expected, after "if" and "while" and so forth, the & and | operators were interpreted as && and || are now; in ordinary expressions, the bitwise interpretations were used. It worked out pretty well, but was hard to explain. (There was the notion of "top-level operators" in a truth-value context.)

The precedence of & and | were as they are now. Primarily at the urging of Alan Snyder, the && and || operators were added. This successfully separated the concepts of bitwise operations and short-circuit Boolean evaluation. However, I had cold feet about the precedence problems. For example, there were lots of programs with things like

	if (a==b & c==d) ...

In retrospect it would have been better to go ahead and change the precedence of & to higher than ==, but it seemed safer just to split & and && without moving & past an existing operator. (After all, we had several hundred kilobytes of source code, and maybe 3 installations....)

Dennis Ritchie 

So, yes, the short-circuiting behavior was part of C from very beginning, even before logical && || were introduced. (And the explanation why bitwise operators have the wrong precedence in C and most other C-like languages.)

Replies are listed 'Best First'.
Re^11: next unless condition
by choroba (Bishop) on Apr 06, 2016 at 22:44 UTC
    Wow. So Perl wasn't the first to introduce "context"!

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Wow. So Perl wasn't the first to introduce "context"!

      Far from it. Indeed, the "context free language" in reality, is an almost mythological beast. Almost none exist; and (IMO) none of those that do, are useful.

      I'm not enough of an aficionado of language development to assert the absolute origin; but every language that allows you to compare 3.5 < 3 -- and that's most of them -- by auto-promotion of integers to a real, to allow comparisons and numerical operations, is being "context aware".

      Which puts those that decry Perl's context awareness as some kind of aberration and would deem it verboten, whether by best practice or auto-critiquing, firmly in the camp of the "I'm too lazy to understand it, so nobody is allowed to use it" school of thinking. Luckily, most programmers have a mind of their own.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1159769]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2018-11-21 18:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (247 votes). Check out past polls.

    Notices?