Re:Loop: a programming language for the JVM inspired by Hask...
by Hemospectrum on Tuesday May 29, 2012 @07:02PM
(#4040451)
The list comprehension rules seem to be lifted straight from Python, where the "foo for bar" part always comes first.
Was anyone else confused that this,
# filter list => [ 'ipod', 'ipad', 'iphone' ]
('i' + p) for p in ['mac', 'pod', 'pad', 'phone'] if p.startsWith('p')
applies a filter against the list, rather than limit what gets prefixed with an 'i'?
I'm assuming then there's some code to keep the mapping and the entire list as well. Something like this?
('i' + p) if p.startsWith('p') for p in ['mac', 'pod', 'pad', 'phone']
It just seemed surprising to me that an if statement can cause a change in the list length.
Edit: Ah this seems to be how filtering works in python