if-expressions + list comprehensions

Leandro Lucarella llucax at gmail.com
Thu May 31 08:49:31 PDT 2007


Daniel Keep, el 29 de mayo a las 12:19 me escribiste:
> double[] as = [1.,2.,3.,4.,5.];
> double[] bs = foreach(a;as) a*a;
> 
> List comprehensions would be cooler still, but I'm not holding my breath
> on that one :P

More pythonic:

double[] bs = a * a foreach(a; as) if (a % 2);

would give you filtering too (leaving bs = [1.0, 9.0, 25.0]) =)

-- 
LUCA - Leandro Lucarella - Usando Debian GNU/Linux Sid - GNU Generation
------------------------------------------------------------------------
E-Mail / JID:     luca at lugmen.org.ar
GPG Fingerprint:  D9E1 4545 0F4B 7928 E82C  375D 4B02 0FE0 B08B 4FB2 
GPG Key:          gpg --keyserver pks.lugmen.org.ar --recv-keys B08B4FB2
------------------------------------------------------------------------
Ambition makes you look pretty ugly



More information about the Digitalmars-d mailing list