Where statement
Tomek Sowiński
just at ask.me
Sun Jul 25 06:54:38 PDT 2010
bearophile wrote:
> Some people have proposed the introduction in Python of the 'where'
> statement. It is quite used in Haskell:
>
> printFreqsBySize genome keySize = do
> ht0 <- htNew keySize
> ht <- hashGenome genome keySize ht0
> l <- htToList ht
> htFree ht
> return $ map draw (sortBy sortRule l) ++ [""]
> where
> genomeLen = S.length genome
> draw :: (S.ByteString, Int) -> String
> draw (key, count) = printf "%s %.3f" (S.unpack key) pct
> where pct = (100 * (fromIntegral count) / total) :: Double
> total = fromIntegral (genomeLen - keySize + 1)
It exists in Haskell because functional languages can't describe sequences
(can't declare a temporary variable before the main expression because
there's no "before"). But I don't know Haskell so I may be wrong.
Anyway, where in D wouldn't bring enough return of investment to break even,
IMHO.
Tomek
More information about the Digitalmars-d
mailing list