Skip to content

Instantly share code, notes, and snippets.

@jkk jkk/example usage
Created Jul 9, 2010

What would you like to do?
user=> (use 'clj-wiki.repl)
user=> (examples contains?)
`contains?` is intended for use on key-based collections such as sets and maps:
(contains? {:foo 1 :bar 2} :foo)
=> true
(contains? #{:fred :ethel :lucy} :ethel)
=> true
When using `contains?` on vectors, be aware that it checks for the existence of the given _index_, not _value_:
; :b is not a valid index
(contains? [:a :b :c] :b)
=> false
; 1 is a valid index
(contains? [:a :b :c] 1)
=> true
If you want to check for the existence of a _value_ in a collection (in linear time), use [some](/clojure.core/some).
`contains?` does not work on lists in any meaningful way.
;; Proof-of-concept "examples" function. Pulls from
;; Note: Doesn't pretty up the Markdown syntax much yet. It should remove link
;; markup and possibly indent code.
(ns clj-wiki.repl
(defn examples [f]
(let [fns (:ns (meta f))
fname (str (:name (meta f)))
url (str ""
fns "/" (URLEncoder/encode fname "UTF-8")
raw-content (-> (:raw-content (read-json (slurp (reader url))))
(.replace "\r\n" "\n")
(.replaceAll "~{3,}((?:.|[\n])+?)~{3,}[\n]"
(.replaceAll ">{3,}[\n]((?:.|[\n])+?)>{3,}[\n]?"
"=> $1")
(.replaceAll "\n{3,}", "\n\n")
(println (str "-------------------------\n"
fns "/" fname "\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.