Proposed new syntax

Steve D'Aprano steve+python at pearwood.info
Fri Aug 18 01:05:03 EDT 2017


On Fri, 18 Aug 2017 06:28 am, Ian Kelly wrote:

> On Thu, Aug 17, 2017 at 1:19 PM, Pavol Lisy <pavol.lisy at gmail.com> wrote:
>> On 8/17/17, Gregory Ewing <greg.ewing at canterbury.ac.nz> wrote:
>>> Steve D'Aprano wrote:
>>>> If he wanted declarative semantics, why didn't he argue for declarative
>>>> syntax
>>>> like "select...where", instead of choosing procedural syntax which matches
>>>> the
>>>> actual procedural semantics given?
>>>
>>> I don't agree that the word "for" necessarily implies proceduralness.
>>
>> With this logic (I humbly think that) word "while" neither
>> necessarilly implies proceduralness.
> 
> "while" implies a condition that is currently true and may at some
> point stop being true. To me, that sequentiality does imply
> proceduralness.

For loops and comprehensions (in Python) are inherently procedural, so it's a
good match. If you want to ignore the documented semantics of Python
comprehensions, their fundamental similarities to generator expressions, and
their actual behaviour, in order to say that they aren't procedural, that's
okay, it a free planet. (Sometimes.)

But if you do that, then logically you must also allow that "while" is likewise
not procedural. Otherwise you're just showing a double-standard.

[Aside: comprehensions are also functional in the sense that they return a
result (unlike a loop, which is imperative) but not in the sense that the order
of execution is unspecified.]


> "for", to quote from Merriam-Webster, indicates "equivalence in
> exchange". A precise definition seems hard to nail down, but there's
> no such implication there.


Webster 1913 includes well over a dozen definitions for the word "for", so I'm
sure that Merrian-Webster would be similar. I don't know why you cherry picked
that one definition out of so many. I think this is more appropriate:

   8. Indicating the space or time through which an action or
      state extends; hence, during; in or through the space or
      time of.

"for x in seq" indicates that x extends through the space of seq, in a manner of
speaking.

Or for something more recent, and more relevant, how about foldoc, the Free
On-line Dictionary of Computing?

    for loop
    for

       <programming> A loop construct found in many procedural
       languages which repeatedly executes some instructions while a
       condition is true.

       [examples snipped]

       The for loop is an alternative way of writing a while loop
       that is convenient because the loop control logic is collected
       in a single place.  It is also closely related to the repeat
       loop.



Sounds pretty definitively procedural to me.

But as Lewis Carrol wrote:

     “When I use a word, Humpty Dumpty said, in a rather scornful tone, 
     it means just what I choose it to mean, neither more nor less.

     The question is, said Alice, whether you can make words mean so many
     different things.

     The question is, said Humpty Dumpty, which is to be master — that’s all.”


Of course we can choose any definition or meaning we like for the word "for" in
comprehensions, and insist that it doesn't actually mean what the "for" in
for-statement means. We're the master of language, not language of us!

But if we can do that, we can likewise do the same for "while".

You can't have it both ways:

(1) if we can ignore the proceduralness of "for", then we can ignore the
proceduralness of "while" and put it in a comprehension;

(2) if we *cannot* ignore the proceduralness of "while", then we likewise cannot
ignore the proceduralness of "for", therefore comprehensions are fundamentally
procedural and that objection against "while" is neutered.


There may be other objections against "while", but any that revolve around the
declarativeness or non-proceduralness of comprehensions are logically invalid.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list