This is a notespace – a namespace that is a sequence of notes. It is intented to be a tutorial about creating and using notespaces.
It is recommended to read this notespace alongside its rendered result.
To use notespace, require the namespace notespace.v2.note, bringing the symbols of the relevant note kinds to your own namespace using :refer. For example, if you want to use notes of kind :md, you may like to (require '[notespace.v2.note :refer [note-md]]). More about note kinds – below.
To see your rendered results with a live-reload experience, require the namespace notespace.v2.live-reload too. This will setup a live-reload server using Ring and Mirador, and will open a browser showing the rendered data.
To compute and render the whole notespace, call:
(notespace.v2.note/compute-this-notespace!)
To compute and rerender a certain note, call:
(notespace.v2.note/compute-note-at-line! line)
where line is one of the lines of the file that are taken by that note.
The notespace library is still experimental. In the (not unlikely) that something breaks, our current recommendation to reload the main notespace namespace, so that the broken state will overridden.
(require 'notespace.v2.note :reload)
Soon things will be more robust.
It is handy to be able to invoke the API functions using commands (and keybindings) of your editor. All you need is to figure out how to make your editor call Clojure functions and pass them the current line of the cursor.
In Emacs, one may do this using the following Elisp code:
(defun notespace/compute-note-at-line ()
(interactive)
(save-buffer)
(cider-interactive-eval
(concat "(notespace.v2.note/compute-note-at-line! "
(number-to-string (count-lines 1 (point)))
")")
(cider-interactive-eval-handler nil (point))
nil
nil)))
(defun notespace/compute-this-notespace ()
(interactive)
(save-buffer)
(cider-interactive-eval
"(notespace.v2.note/compute-this-notespace!)"
(cider-interactive-eval-handler nil (point))
nil
nil)
We can have all kinds of different notes. The different kinds behave differently when rendered.
This one is a note of kind :md. When rendered, it renders as markdown and does not show the source string.
The following is a 'regular' note, of kind :code. When renders, it shows both the source code and the printed return value.
(def x 1) (+ x 1)2The following is a note of kind :void. It shows the source, but does not show the output.
(+ 1 2)The following is a note of kind :hiccup. It does not show the source, and renders the return value as hiccup.
Sometimes, we may want to render things as markdown or hiccup, but do want to see the source too. The following two kinds of notes are useful in those cases.
This is a note of kind :as-md. Shows the source, renders as markdown.
The following is a note of kind :as-hiccup. Shows the source, renders as hiccup.
(->> 4 range (map (fn [i] [:li i])) (into [:ul]))Here is the summary of the note kinds we mentioned: (Sorry for this strange table. Markdown tables do not render properly at the moment.)
| kind | symbol | render source? | value-rendering |
| code | note | v | pretty printing |
| void | note-void | v | x |
| md | note-md | x | as markdown |
| as-md | note-as-md | v | as markdown |
| hiccup | note-hiccup | x | as hiccup |
| as-hiccup | note-as-hiccu | v | as hiccup |
In the definition of the following note, we begin with a keyword: :label-example. This keyword is called the label of the note, and it is not rendered. It creates a link to that note from the table-of-contents.
It may be handy to render data in interactive tables. We have some auxiliary functions to render this using the DataTables JS library.
(require '[notespace.v2.table :as table]) (table/->datatable (for [i (range 99)] {:x i, :y (if (even? i) "a" "b"), :z (rand)}))| x | y | z |
|---|---|---|
| 0 | a | 0.9306756521265375 |
| 1 | b | 0.5527881298403585 |
| 2 | a | 0.9318112525831407 |
| 3 | b | 0.6960006417602711 |
| 4 | a | 0.019555399601652756 |
| 5 | b | 0.505459592930136 |
| 6 | a | 0.8897690306221971 |
| 7 | b | 0.6251469928982298 |
| 8 | a | 0.8565842328916234 |
| 9 | b | 0.5686972545834627 |
| 10 | a | 0.8935344784577192 |
| 11 | b | 0.8217562492127671 |
| 12 | a | 0.8946944958766943 |
| 13 | b | 0.6139392660332191 |
| 14 | a | 0.5110949625120452 |
| 15 | b | 0.6413521392981928 |
| 16 | a | 0.8318343424287312 |
| 17 | b | 0.2513566407004513 |
| 18 | a | 0.03933060442787595 |
| 19 | b | 0.5537179259632918 |
| 20 | a | 0.467200944638514 |
| 21 | b | 0.8786974246120673 |
| 22 | a | 0.3611175488583177 |
| 23 | b | 0.5108975979116976 |
| 24 | a | 0.11207813178767667 |
| 25 | b | 0.7512040121683663 |
| 26 | a | 0.9628861275766036 |
| 27 | b | 0.9271061476027258 |
| 28 | a | 0.737926406623811 |
| 29 | b | 0.8287381559019097 |
| 30 | a | 0.20983228168241053 |
| 31 | b | 0.30451463651771105 |
| 32 | a | 0.3812866658762274 |
| 33 | b | 0.03222369330799446 |
| 34 | a | 0.4535195998977166 |
| 35 | b | 0.18047797368358565 |
| 36 | a | 0.19322420847816302 |
| 37 | b | 0.19874451715196262 |
| 38 | a | 0.05539898886585959 |
| 39 | b | 0.994624375618123 |
| 40 | a | 0.9204519941684368 |
| 41 | b | 0.46311133119574177 |
| 42 | a | 0.9498111801268082 |
| 43 | b | 0.6783276008364486 |
| 44 | a | 0.5359378904205215 |
| 45 | b | 0.01343764522115376 |
| 46 | a | 0.941327231591634 |
| 47 | b | 0.25443375630101417 |
| 48 | a | 0.19871355850204853 |
| 49 | b | 0.16924163243291612 |
| 50 | a | 0.5338205163161657 |
| 51 | b | 0.5017170498638587 |
| 52 | a | 0.7157670459430944 |
| 53 | b | 0.5128173740148497 |
| 54 | a | 0.7224532244973003 |
| 55 | b | 0.7863896759573096 |
| 56 | a | 0.2033153442525385 |
| 57 | b | 0.3680956067073241 |
| 58 | a | 0.8447992583391176 |
| 59 | b | 0.49209270904285285 |
| 60 | a | 0.7004170479613459 |
| 61 | b | 0.2659402207607907 |
| 62 | a | 0.28361448273063006 |
| 63 | b | 0.09014706809866968 |
| 64 | a | 0.07479951434440268 |
| 65 | b | 0.16080372390041298 |
| 66 | a | 0.5413043840252859 |
| 67 | b | 0.7834440705401453 |
| 68 | a | 0.6789385591995577 |
| 69 | b | 0.07089147011507302 |
| 70 | a | 0.9649284187246719 |
| 71 | b | 0.8302076301217496 |
| 72 | a | 0.86384346137848 |
| 73 | b | 0.5024607097650652 |
| 74 | a | 0.19061879457441055 |
| 75 | b | 0.10796126879019774 |
| 76 | a | 0.6386633541714559 |
| 77 | b | 0.48860717984347934 |
| 78 | a | 0.19758142815898794 |
| 79 | b | 0.2133848635079646 |
| 80 | a | 0.4761459204783719 |
| 81 | b | 0.32386887121501295 |
| 82 | a | 0.7143850872787376 |
| 83 | b | 0.41034716914434877 |
| 84 | a | 0.5071425070035382 |
| 85 | b | 0.10820257629867602 |
| 86 | a | 0.6040341142293669 |
| 87 | b | 0.03625245067886196 |
| 88 | a | 0.12176877266094299 |
| 89 | b | 0.02736575820736864 |
| 90 | a | 0.7693591921696361 |
| 91 | b | 0.5559405634871661 |
| 92 | a | 0.3004932563937712 |
| 93 | b | 0.891463043418189 |
| 94 | a | 0.0665496143758113 |
| 95 | b | 0.3127314020282367 |
| 96 | a | 0.8353406656217024 |
| 97 | b | 0.8293924795645312 |
| 98 | a | 0.6921896986620485 |
Graphics can be rendered as hiccup. Here is an example using SVG.
[:svg {:height 100, :width 100} [:circle {:cx 50, :cy 50, :fill "lightgrey", :r 40, :stroke "purple", :stroke-width 4}]]One may use the check function to create tests using arbitrar functions.
(->> (+ 1 2) (check = 3))[:PASSED 3](check pos? -9)[:FAILED -9]