notespace.v2.tutorial-test

notespace.v2.tutorial-test - created by notespace, Sun Feb 23 02:50:11 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, save the file and call:

(notespace.v2.note/compute-this-notespace!)

To compute and rerender a certain note, save the file and 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) case where something breaks, our current recommendation to reset the system's state.

(notespace.v2.note/reset-state!)

Soon things will be more robust.

Sometimes, the live-reload stops happening. A browser refresh sometimes fixes that.


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.944910805153535
1b0.06528071876098762
2a0.02099904420141374
3b0.5176130856197618
4a0.6422456406710981
5b0.46432828532519066
6a0.1588724497271814
7b0.9019199133639857
8a0.2658534719121989
9b0.9119500065169838
10a0.9740783020769015
11b0.8487991703523143
12a0.8613150556459549
13b0.2867712011858231
14a0.8459959052066137
15b0.8832654732530346
16a0.6259002823528518
17b0.2874218090466162
18a0.14421167373090515
19b0.5943426906479073
20a0.36315406127860506
21b0.591248009482284
22a0.382068534052459
23b0.5318817310082414
24a0.6896040514226315
25b0.41795455454817565
26a0.5115127812019598
27b0.6607904027210956
28a0.7448415419887555
29b0.5826817165531222
30a0.5601964693901613
31b0.9264168259005882
32a0.12595324700078803
33b0.4443084350400912
34a0.0471452174771515
35b0.6967420514477484
36a0.5182584658063562
37b0.5073133822816196
38a0.12990276591809435
39b0.5902013446247812
40a0.026532273704245823
41b0.8193141378209571
42a0.23391532529644665
43b0.47236780804758727
44a0.5243725605438725
45b0.7214439447219068
46a0.9940200675548954
47b0.2103960564274262
48a0.4340945648837977
49b0.9550143762423319
50a0.6982539831553599
51b0.1110377063238438
52a0.2255138138743057
53b0.6054518786122509
54a0.0658006132529464
55b0.8362045533098674
56a0.5792044816448719
57b0.8732842041927541
58a0.11374390863600037
59b0.9894691335703185
60a0.5982968352644512
61b0.20199300931273045
62a0.07139987690384908
63b0.49755702464197404
64a0.6726042449695261
65b0.863836862375929
66a0.7863485309858252
67b0.3727984508825758
68a0.5998464492637245
69b0.7072887478251579
70a0.8328897833591594
71b0.4356715482600527
72a0.3509623691601864
73b0.40352093961585234
74a0.5814988909200716
75b0.10098340248058246
76a0.42998286357185
77b0.19440882256330594
78a0.81695823607648
79b0.38689897092297787
80a0.12365944270217477
81b0.8408153066991837
82a0.10319450780849038
83b0.8929422621196549
84a0.06202244610961194
85b0.1974550194004563
86a0.9844506525450191
87b0.6112579315630735
88a0.41826803023934767
89b0.5994282094846639
90a0.2852749627949951
91b0.08483599621741211
92a0.7648505066700306
93b0.03555198331058829
94a0.22591022064897193
95b0.6070657798308688
96a0.07238247470466408
97b0.9049063901940214
98a0.8050177878335606

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, Sun Feb 23 02:50:11 CET 2020.