Where statement

KennyTM~ kennytm at gmail.com
Sun Jul 25 08:06:45 PDT 2010


On Jul 25, 10 21:54, Tomek Sowiński wrote:
> 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.
>

No.

quadraticSum a b = let aSquared = a*a
                        bSquared = b*b in
                          aSquared + bSquared

> Anyway, where in D wouldn't bring enough return of investment to break even,
> IMHO.
>
>
> Tomek



More information about the Digitalmars-d mailing list