Advertisement
Guest User

boxen.clj

a guest
Nov 14th, 2012
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;; Let's not repeat ourselves
  2. (def unix-good "This is a Unix box and therefore good")
  3. (def windows-bad "This is a Windows box and therefore bad")
  4. (def mac-superior "This is a Macintosh box and therefore far superior")
  5. (def not-box "This is not a box")
  6.  
  7. ;; Returning a string given some other string is not a unique and special
  8. ;; snowflake. Someone else did this before you did, so the language has it built
  9. ;; in. It's in an agent so it's easy to add to.
  10. (def boxen (agent {"Linux" unix-good
  11.                    "SunOS" unix-good
  12.                    "Mac OS" mac-superior
  13.                    "Windows NT" windows-bad
  14.                    "Windows 95" windows-bad}))
  15.  
  16. (defn get-box []
  17.   (get @boxen (System/getProperty "os.name") not-box))
  18.  
  19. ;; Oh, let's add something. Someone using this as a library could do this too.
  20.  
  21. (def osx-arrogant "This is both a Macintosh and a Unix box. I look down my nose at you.")
  22.  
  23. (send boxen assoc "Mac OS X" osx-arrogant)
  24.  
  25. ;; Did I mention this is all non-blocking and thread-safe?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement