This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user=> (use 'clj-wiki.repl) | |
nil | |
user=> (examples contains?) | |
------------------------- | |
clojure.core/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. | |
nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Proof-of-concept "examples" function. Pulls from http://clojure-examples.appspot.com/ | |
;; | |
;; Note: Doesn't pretty up the Markdown syntax much yet. It should remove link | |
;; markup and possibly indent code. | |
(ns clj-wiki.repl | |
(:use clojure.java.io | |
clojure.contrib.json) | |
(:import java.net.URLEncoder)) | |
(defn examples [f] | |
(let [fns (:ns (meta f)) | |
fname (str (:name (meta f))) | |
url (str "http://clojure-examples.appspot.com/" | |
fns "/" (URLEncoder/encode fname "UTF-8") | |
"?format=json") | |
raw-content (-> (:raw-content (read-json (slurp (reader url)))) | |
(.replace "\r\n" "\n") | |
(.replaceAll "~{3,}((?:.|[\n])+?)~{3,}[\n]" | |
"$1") | |
(.replaceAll ">{3,}[\n]((?:.|[\n])+?)>{3,}[\n]?" | |
"=> $1") | |
(.replaceAll "\n{3,}", "\n\n") | |
(.trim))] | |
(println (str "-------------------------\n" | |
fns "/" fname "\n\n" | |
raw-content)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment