notespace.v2.tutorial-test

notespace.v2.tutorial-test - created by notespace, Fri Feb 21 19:51:56 CET 2020.
Checks: 1 PASSED 1 FAILED
Table of contents

Intro


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.


Computing and rendering


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.


Editor integration.


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)
  


Note kinds


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)
2

The 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 |


Labels


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.


(+ 1 2)
3

Tables


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)}))
xyz
0a0.9306756521265375
1b0.5527881298403585
2a0.9318112525831407
3b0.6960006417602711
4a0.019555399601652756
5b0.505459592930136
6a0.8897690306221971
7b0.6251469928982298
8a0.8565842328916234
9b0.5686972545834627
10a0.8935344784577192
11b0.8217562492127671
12a0.8946944958766943
13b0.6139392660332191
14a0.5110949625120452
15b0.6413521392981928
16a0.8318343424287312
17b0.2513566407004513
18a0.03933060442787595
19b0.5537179259632918
20a0.467200944638514
21b0.8786974246120673
22a0.3611175488583177
23b0.5108975979116976
24a0.11207813178767667
25b0.7512040121683663
26a0.9628861275766036
27b0.9271061476027258
28a0.737926406623811
29b0.8287381559019097
30a0.20983228168241053
31b0.30451463651771105
32a0.3812866658762274
33b0.03222369330799446
34a0.4535195998977166
35b0.18047797368358565
36a0.19322420847816302
37b0.19874451715196262
38a0.05539898886585959
39b0.994624375618123
40a0.9204519941684368
41b0.46311133119574177
42a0.9498111801268082
43b0.6783276008364486
44a0.5359378904205215
45b0.01343764522115376
46a0.941327231591634
47b0.25443375630101417
48a0.19871355850204853
49b0.16924163243291612
50a0.5338205163161657
51b0.5017170498638587
52a0.7157670459430944
53b0.5128173740148497
54a0.7224532244973003
55b0.7863896759573096
56a0.2033153442525385
57b0.3680956067073241
58a0.8447992583391176
59b0.49209270904285285
60a0.7004170479613459
61b0.2659402207607907
62a0.28361448273063006
63b0.09014706809866968
64a0.07479951434440268
65b0.16080372390041298
66a0.5413043840252859
67b0.7834440705401453
68a0.6789385591995577
69b0.07089147011507302
70a0.9649284187246719
71b0.8302076301217496
72a0.86384346137848
73b0.5024607097650652
74a0.19061879457441055
75b0.10796126879019774
76a0.6386633541714559
77b0.48860717984347934
78a0.19758142815898794
79b0.2133848635079646
80a0.4761459204783719
81b0.32386887121501295
82a0.7143850872787376
83b0.41034716914434877
84a0.5071425070035382
85b0.10820257629867602
86a0.6040341142293669
87b0.03625245067886196
88a0.12176877266094299
89b0.02736575820736864
90a0.7693591921696361
91b0.5559405634871661
92a0.3004932563937712
93b0.891463043418189
94a0.0665496143758113
95b0.3127314020282367
96a0.8353406656217024
97b0.8293924795645312
98a0.6921896986620485

Graphics


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}]]

Tests


One may use the check function to create tests using arbitrar functions.


(->> (+ 1 2)
      (check = 3))
[:PASSED 3]

(check pos? -9)
[:FAILED -9]

Checks: 1 PASSED 1 FAILED
notespace.v2.tutorial-test - created by notespace, Fri Feb 21 19:51:56 CET 2020.