Proposed new syntax

Rustom Mody rustompmody at gmail.com
Fri Aug 11 22:41:31 EDT 2017


On Friday, August 11, 2017 at 8:33:32 PM UTC+5:30, Ian wrote:
> The grand-daddy of them all, NPL (which actually called them "set
> comprehensions" after mathematics):
> 
> setofeven(X) <= <:x: x in X & even(x) :>

Thanks for reminding of NPL; will add it to my history summary at
http://blog.languager.org/2015/04/cs-history-1.html

> 
> 
> Nothing about any of these suggests a loop or a requirement for serial
> processing. Granted, there are other languages I've not listed here
> that use loop syntax like Python.
> 
> 
> >> Though ‘for’ is used elsewhere in Python to mean iteration, ‘for’ also
> >> has strong connotation in mathematics for set-based operations (“the
> >> result is foo for all bar, if baz”). So the same confusion doesn't
> >> occur: this is a comprehension which is about set-based thinking, which
> >> is supported by all the semantic connotations of the syntax.
> >
> > I don't understand this. I *think* what you're saying is "I have internalised
> > the explicit for-loop and think of it as a filter plus a map and no longer
> > think of it as a for-loop", but I'm not sure.
> 
> More like, "Python has externalized the list comprehension as a for
> loop despite the rich tradition to the contrary."

Very true.

Like Occam's razor, we have a Guido-razor "Minimize new keywords” which helps compatibility across language versions but not comprehension (of not just comprehensions!)

Actually list comprehensions go further than NPL to SETL except that they were
called ‘set-formers’ not ‘set-comprehensions'

[ My conjecture: The word ‘comprehension’ used this way in English is 
meaningless and is probably an infelicious translation of something which makes sense in German]

Interestingly from the SETL manual [4 page 22] about Set-formers in SETL (SETL term for set-comprehension)
“The  SETL iterator  has  exactly  the  same  form  as  a  loop  iterator, except  that  the  keyword for is  omitted”

History-Capsule (as I understand it):

List comprehensions in python (2.0 c. 2000) come from haskell [1] [2] 
Haskell (c. 1990) got it from Miranda
Miranda (c. 1980) got it from SETL [4]
SETL (c. 1960) main innovation was sets, sequences and 'set-builder notation'
whose SETL name was 'set-former' nowadays called comprehension notation
SETL, as best as I know, is the first computer language using the math notation

… which itself goes back to Zermelo (c. 1930) who gave his axiomatization for set theory…
…Containing the comprehension-axiom [3]
…Which was needed to avoid problems like Russell's paradox

R = {x | x ∉ x}
is disallowed, since allows to directly derive the contradiction
R∉R iff  R∈R

So the axiom-of-comprehension mandated by Zermelo/Fraenkel is that one must define R from some previous set P
R = {x ∈ P | x ∉ x}
which in more programmerish notation becomes
R = {x | x ∈ P,  x ∉ x}
which renders the x ∉ x harmless
Or more pythonically:
R = {x for x in P if  x not in x}


[1] https://docs.python.org/3/whatsnew/2.0.html
[2] https://docs.python.org/3/howto/functional.html
[3] https://en.wikipedia.org/wiki/Axiom_schema_of_specification
[4] http://cs.nyu.edu/~bacon/setl/doc-legacy/setlprog.pdf



More information about the Python-list mailing list