etymology of "list comprehension"?

M

mh

I googled and wiki'ed, but couldn't find a concise clear answer
as to how python "list comprehensions" got their name.

Who picked the name? What was the direct inspiration, another
language? What language was the first to have such a construct?

I get that it's based on set notation.

Thanks!
Mark
 
C

Chris Rebert

I googled and wiki'ed, but couldn't find a concise clear answer
as to how python "list comprehensions" got their name.

Who picked the name? What was the direct inspiration, another
language? What language was the first to have such a construct?

According to Wikipedia, the SETL programming language was the first
one to have such a construct. My understanding is that Python took the
idea from Haskell, where the concept has the same name. The term
"comprehension" for the concept was first used in the NPL programming
language (Wikipedia again).

Cheers,
Chris
 
M

mh

Chris Rebert said:
the term
"comprehension" for the concept was first used in the NPL programming
language (Wikipedia again).

Ah, thanks... and does "comprehension" have any special computer
science meaning?
 
T

Terry Reedy

I googled and wiki'ed, but couldn't find a concise clear answer
as to how python "list comprehensions" got their name.

Who picked the name? What was the direct inspiration, another
language? What language was the first to have such a construct?

I get that it's based on set notation.

The etymology of 'com-prehend' is with-grab, where prehend comes from
the same Latin verb as prehensile (able to grab). A set comprehension
(which has also been called things like 'set-builder notation') includes
or grabs the whole set in one expression, instead of listing members
one-by-one.

tjr
 
P

Paul Rubin

Ah, thanks... and does "comprehension" have any special computer
science meaning?

It is from mathematical set theory. If you write something like

{ p | [some logical expression indicating that p is prime] }

then that denotes a set (the set of all prime numbers). That every
such formula names a set is called the axiom of comprehension. The
above notation is sometimes called set-builder notation.

Frege's original system of logic (late 19th century), now called
"naive set theory" had "unrestricted comprehension" which meant
you could say anything at all where the logical expression went.
This made the system inconsistent, because of Russell's paradox
("c is the class of all classes that are not members of themselves.
So is c a member of itself?").

Axiomatic set theory has a restricted axiom of comprehension that
requires the logical expression to be a first order formula with
a certain syntax, to avoid such paradoxes.

Anyway, list comprehensions in programming languages got their
name because of their resemblance to set-builder notation that
invoked the axiom of comprehension.
 
J

James Harris

Ah, thanks... and does "comprehension" have any special computer
science meaning?

Good question. It seems that comprehension in this case relates to
comprehensiveness - i.e. a note of how complete a set is. From the
list at

http://www.onelook.com/?w=comprehension&ls=a

check out in particular Merriam-Webster meanings 2a and 2b, and
Wikipedia for comprehension (logic).
 
T

Terry Reedy

Paul said:
Ah, thanks... and does "comprehension" have any special computer
science meaning?

It is from mathematical set theory. If you write something like

{ p | [some logical expression indicating that p is prime] }

then that denotes a set (the set of all prime numbers). That every
such formula names a set is called the axiom of comprehension. The
above notation is sometimes called set-builder notation.

Frege's original system of logic (late 19th century), now called
"naive set theory" had "unrestricted comprehension" which meant
you could say anything at all where the logical expression went.
This made the system inconsistent, because of Russell's paradox
("c is the class of all classes that are not members of themselves.
So is c a member of itself?").

Axiomatic set theory has a restricted axiom of comprehension that
requires the logical expression to be a first order formula with
a certain syntax, to avoid such paradoxes.

Anyway, list comprehensions in programming languages got their
name because of their resemblance to set-builder notation that
invoked the axiom of comprehension.

Thank you for this info. I suspected something along this line but
could not quite remember.
 
M

Martin v. Löwis

Ah, thanks... and does "comprehension" have any special computer
science meaning?

Paul already explained the maths, but I find that the etymology remains
unclear still. In any case, the Wikipedia article
Axiom_schema_of_specification says that the following names are used
for this axiom:
- axiom schema of specification,
- axiom schema of separation,
- subset axiom scheme or
- axiom schema of restricted comprehension

I think the "comprehension" definition goes back to this definition from
logic:

# In logic, the comprehension of an object is the totality of
# intensions, that is, attributes, characters, marks, properties, or
# qualities, that the object possesses, or else the totality of
# intensions that are pertinent to the context of a given discussion.

So you get an "intensional" definition of a set: give me all object
with a certain comprehension - as opposed to "extensional" definition,
such as "the set of all capitals consists of Paris, London, Berlin,
Madrid, ..."

The definition in logic, in turn, matches my understanding of the
English word "to comprehend": If I know all attributes, marks,
etc of an object, I understand it fully, i.e. I comprehend it.

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top