On Sat, Apr 5, 2008 at 7:32 PM, Brandon S. Allbery KF8NH
<[EMAIL PROTECTED]> wrote>
>  On Apr 5, 2008, at 15:07 , John M. Dlugosz wrote:
>
> > What is a "list comprehension"?  I've seen that term bantered around here.
> >
>
>  The term comes from Haskell and Python; it's a shorthand notation for list
> generation and filtering.
>
>     [x | x <- some expression involving y, y = some range expression] --
> haskell syntax

You've got the order mixed up there.  Variables are bound left-to-right on
the right side of the bar:

  [ (x,y) | x <- [1..3], y <- replicate x "foo" ]

Gives:

  [ (1,"foo"), (2,"foo"), (2,"foo"), (3,"foo"), (3,"foo"), (3,"foo") ]

(replicate should be pretty obvious:  replicate 4 0 = [0,0,0,0])

Luke

Reply via email to