Skip to content

Instantly share code, notes, and snippets.

@japaz
Created December 15, 2011 22:36
Show Gist options
  • Select an option

  • Save japaz/1483269 to your computer and use it in GitHub Desktop.

Select an option

Save japaz/1483269 to your computer and use it in GitHub Desktop.
7L7W Clojure - Day 1
;Implement a function called (big st n) that returns true if a string st
;is longer than n characters.
(defn big [st n] (> (count st) n))
;Write a function called (collection-type col) that returns :list, :map,
;or :vector based on the type of collection col.
(defmulti collection-type class)
(defmethod collection-type clojure.lang.IPersistentList [arg] :list)
(defmethod collection-type clojure.lang.IPersistentMap [arg] :map)
(defmethod collection-type clojure.lang.IPersistentVector [arg] :vector)
(defmethod collection-type :default [arg] :unknown)
; user=> (collection-type ["one", "two", "three"])
; :vector
; user=> (collection-type {:chewie :wookie :lea :human})
; :map
; user=> (collection-type (hash-map :chewie :wookie :lea :human))
; :map
; user=> (collection-type (sorted-map :chewie :wookie :lea :human))
; :map
; user=> (collection-type (list "a" "b"))
; :list
; user=> (collection-type (quote ("a" "b")))
; :list
; user=> (collection-type '("a" "b"))
; :list
; user=> (collection-type 23)
; :unknown
; Examples using Clojure sequences
; http://clojure.org/sequences
; http://stackoverflow.com/questions/1989301/clojure-sequence-back-to-vector
; http://www.moxleystratton.com/article/clojure/for-non-lisp-programmers#sequences
; The formal definition of a Clojure function
; A script for quickly invoking the repl in your environment
; https://github.com/technomancy/leiningen
; lein repl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment