(PEP-308) Python's Conditional Selection Operators

Gareth McCaughan Gareth.McCaughan at pobox.com
Sun Feb 16 01:24:56 CET 2003


Stephen Horne wrote:

>  On Fri, 14 Feb 2003 18:34:32 -0800, Erik Max Francis <max at alcyone.com>
>  wrote:
>  
> > You say "standard versions" but there is no such thing in the realm of
> > computer science.  Python's and/or operators behave just like Lisp's,
> > for example, and Lisp has been around a very long time.
>  
>  But lisp has never been a defining standard for all programming
>  languages. It is quirky and somewhat different from anything in
>  programming that could be called a standard.

On the contrary: Common Lisp was, for instance, the first object-oriented
language to have an ANSI standard. :-) Yes, I know, you don't really
mean "standard", you mean "average". Well, if it comes to that, Python
isn't "standard" either. It's easy to write and easy to read, for instance;
those characteristics aren't "standard", alas.

>                                               For example, it is often
>  referred to as a functional language because it supports functions as
>  first class objects even though it is clearly an imperative language
>  in most ways with side effects all over the place - so it doesn't even
>  fit with the standard expectations of a single class of programming
>  language.

Ah, yes, providing the facilities needed to program in functional
style when appropriate as well as those needed to program in
imperative style when appropriate. Terrible, that. Certainly
non-standard. And, of course, a million miles away from anything
in Python. It wouldn't do to think about such a language in
connection with Python, would it?

>  As for the syntax, it is best compared with forth and miranda - all
>  three are obsessed with one syntactic construct (forth has postfix
>  operators, miranda has prefix operators, lisp has Lots of
>  Infuriatingly Stupid Paretheses. Important, yes. Powerful, yes.
>  Standard (as in conventional), no.

Ah, yes. We shouldn't consider the semantics of Lisp as any
sort of precedent, because it uses unusual syntax. Yup, that
sure makes a lot of sense.

>  The standard for boolean logic operators (even if it is just a de
>  facto standard) is that they operate on boolean parameters and return
>  boolean results. There are exceptions, and some have been around a
>  long time, but age in itself does not make something standard.

That's what happens in statically typed languages like C++ and Pascal
and Fortran. It has to. It's "standard" only in so far as static typing
is "standard". Python, as you may have noticed, is not a statically
typed language. So, what's "standard" in other dynamically typed
languages? Let's take a representative sample. (By the way, I mean
that; the examples weren't chosen to produce the results I want.
Before I checked, I thought Smalltalk's boolean operations were
unlike Python's and I had no idea which way JavaScript's went. I
chose the first four dynamically typed languages that occurred to
me.)

  - In most of the Lisp family, <and> and <or> behave as they do
    in Python.

  - In Perl, <&&>/<and> and <||>/<or> behave as <and> and <or> do
    in Python.

  - In Smalltalk, <and> and <or> are methods on boolean objects.
    They behave as much like Python's <and> and <or> as they could
    given the fundamental differences in the languages; in
    particular, they short-circuit and they may return a result
    of any type.

  - In JavaScript, <&&> and <||> behave as <and> and <or> do in
    Python.

I think it's clear what's "standard" in this domain.

-- 
Gareth McCaughan  Gareth.McCaughan at pobox.com
.sig under construc




More information about the Python-list mailing list