Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Ruby is beautiful

Name: Anonymous 2009-08-26 15:25

class Cycle
    def cycle(*args)
      args[((@_cycles ||= Hash.new(-1))[args.hash] += 1) % args.size]
    end
end

More beautiful code plees?

Name: Anonymous 2009-08-27 16:53

import Data.Map
import Data.IORef

newCycle =
   do state <- newIORef empty
      let memoCycle args =
             do modifyIORef state $ alter (Just . maybe (cycle args) tail) args
                fmap (head . (!args)) $ readIORef state
      return memoCycle

main =
   do foo <- newCycle
      putStrLn =<< foo ["hax","my","anus"]
      putStrLn =<< foo ["hax","my","anus"]
      putStrLn =<< foo ["achieve","satori"]
      putStrLn =<< foo ["hax","my","anus"]
      putStrLn =<< foo ["hax","my","anus"]

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List