Talk:List comprehensions

From Rosetta Code

The Pop11 example does not use the sort of syntax specified in the requirements. --TBH 09:22, 23 May 2008 (MDT)

Remove Algol?

As it states, it is not a list comprehension. This would allow those languages with, or that can construct, the extra syntax to not be hidden amongst multiple languages showing nested loops. --Paddy3118 04:13, 16 April 2009 (UTC)

Some requirements sound strange. Common lisp would be out too. E too. After all, Erlang and the second (and to me first too) Haskell example too. Python too. Clojure too, for how I can understand Clojure. This is because some languages use de facto their way of expressing (nested) "for" loops (language syntax may hide this, but it is what it happens). Maybe just Mathematica can be saved... The most correct example should say it like as general set, and then be able to put some constraints over variables (like ... But doing so in most languages it means to generate the values in the range, that is using a "for" loop syntax (the word for does not need to appear!). And this rules out also syntax like (for x from 1 to n), or for x in 1..n, or A <- lists:seq(1,N), or x <- [1..n], or for x in xrange(1,n+1). I would delete the first requirements, it is subtly ambiguous. --ShinTakezou 21:10, 16 April 2009 (UTC)

Hi ShinTakezou, I think what truly makes it a list comprehension, is that the language designers have created another syntax, separate from for-loops, aping the main syntactic components of the set builder notation (the /List comprehension article overview tries to show this. If the language designer doesn't give attempt to give a list comprehension in its language then although for-loops would work, what is the point? Python and Haskel do give separate syntax and although the Python list comprehension does include the 'for' keyword, it is separate from a for statement in the syntax of the language. --Paddy3118 16:53, 19 April 2009 (UTC)

I stumble always upon this syntactical stones and interpretational mass. C too can have list comprehension with a proper (set of) preprocessor macros...? Would it be cheating...? Yes and no... aren't languages designed someway so that syntactical sugar can be added? And shouldn't we on RC show how easy it could be even if not already given that syntax by design, and compare with langs having the syntax already hard-wired? (Of course, if it won't waste ten pages to do so...!)
Anyway this is related to how a languages express loops... Nothing to say about Python, ... I've (almost) discontinued my Haskell studies, but on RC itself I can see Haskell has no for-loops as other languages... of course it can be "simulated"... (some examples use a forM or forM_, but at Loop Structures it is shown how that can be implemented... and likely as it is indeed implemented in Control.Monad, in fact forM is mapM with its arguments flipped and implementation of mapM is here). Id est Haskell has no real for-loop and the most obvious way of "looping" over values is to use a "list". So, there's no a separated syntax for for-loops and list (comprehension)... and so the first constraint says us Haskell can't have list comprehension... --ShinTakezou 18:17, 19 April 2009 (UTC)

Hi again ShinTakezou, things are never likely to be clear cut, but my thinking on languages is that if list comprehensions are not part of 'standard practice'/in the reference for that language, then even if a computation can be done to mimic list comprehensions, you might never see such list comprehension work-alike in use in example code of that language from books or their website. It would be the problem that I would have with languages that have macro facilities such as C and maybe Lisp, where someone creates a particular macro definition for a list comprehension and says "look, this language can do it"! How likely is some other programmer to use that implementation when they want to use a list comprehension in that language? How likely are they to be taught that "this is how you do list comprehensions" in the language. In Python, Haskel, and Javascript it is clear-cut, go seeking list comprehensions in those languages and you will be taught the one thing and they will say that it is their languages advised way of supporting set-builder type notation for building lists/iterables. I guess it boils down to "It is a Lisp comprehension because the language designers say it is, and because they had set builder notation in-mind when they were creating the syntax". --Paddy3118 04:47, 20 April 2009 (UTC)