Steven Schveighoffer:

I would caution however, from my past experience, that looking at how well one language does vs. another is extremely subjective -- really good coders can do really well no matter what language they use.

But the "Hall of Mirrors"-large Haskell solution by tmoHaskell is elegant:
http://codepad.org/bxf3CYwW
http://www.go-hero.net/jam/12/name/tmoHaskell

That contains simple usage of pattern matching on values:

nextCell :: Hall -> (Int,Int) -> (Int,Int) -> (Ratio Int,Ratio Int)
            -> Maybe ((Int,Int), (Int,Int), (Ratio Int,Ratio Int))
nextCell hall (vx,vy) (ix,iy) (x,y) = do
    ((vx',ix',x'),(vy',iy',y')) <- case (x,y) of
        (0,0) -> corner (-1) (-1)
        (0,1) -> corner (-1)   1
        (1,0) -> corner   1  (-1)
        (1,1) -> corner   1    1
        (0,_) -> hitHorizontal (-1)
        (1,_) -> hitHorizontal 1
        (_,0) -> hitVertical (-1)
        (_,1) -> hitVertical 1
    return ((vx',vy'),(ix',iy'),(x',y'))


Switch on structs are useful:
http://d.puremagic.com/issues/show_bug.cgi?id=596

(1,_) -> hitHorizontal 1

becomes something like:

case tuple(1,void): r = hitHorizontal(1); break;

Or:
case tuple(1,_): r = hitHorizontal(1); break;

------------------------

One Scala solution to the "Speaking in Tongues" contains:

val map = new TreeMap[Char, Char]
" abcdefghijklmnopqrstuvwxyz".zip(" yhesocvxduiglbkrztnwjpfmaq").foreach(x => map.put(x._1, x._2))


That in Python you write with just:

dict(zip(" abcdefghijklmnopqrstuvwxyz", " yhesocvxduiglbkrztnwjpfmaq"))
{' ': ' ', 'a': 'y', 'c': 'e', 'b': 'h', 'e': 'o', ...

It's handy to have a similar AssociativeArray from pairs iterable in Phobos too (or even in object).

Bye,
bearophile

Reply via email to