notespace.v2.tutorial-test

notespace.v2.tutorial-test - created by notespace, Mon Feb 24 15:54:07 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."

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:

kindsymbolrender source?value-rendering
:codenotevpretty printing
:voidnote-voidvx
:mdnote-mdxas markdown
:as-mdnote-as-mdvas markdown
:hiccupnote-hiccupxas hiccup
:as-hiccupnote-as-hiccupvas 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.9400242502710994
1b0.3913157476510357
2a0.8048419446657448
3b0.25773687191389005
4a0.4825616644354872
5b0.85469162030071
6a0.8765808622825985
7b0.13607336697909256
8a0.2628994853460147
9b0.6804937186379718
10a0.8279450777210935
11b0.6259765029627088
12a0.8686362341967813
13b0.06366966164262722
14a0.6182313721350469
15b0.24330650663593034
16a0.22859145690965832
17b0.21521673137710295
18a0.5007678471874754
19b0.8531791715937265
20a0.4029136870551121
21b0.6874893933774809
22a0.15463228436784582
23b0.3870736226346261
24a0.8628744186297539
25b0.7127293139045561
26a0.05485118370544295
27b0.11065382476534247
28a0.4222439906762592
29b0.0069971358642249015
30a0.13799465147017775
31b0.12153291874282368
32a0.9674962656453775
33b0.45359888096554657
34a0.3210588258348307
35b0.8587502065808386
36a0.4006915824181193
37b0.5732641355002869
38a0.7137546770324776
39b0.5395175284179126
40a0.756737868331609
41b0.7127470334125644
42a0.42779758890781827
43b0.6038329280965028
44a0.28583229391894693
45b0.4391854416568489
46a0.7315197876169706
47b0.4438468968161924
48a0.4022368283995619
49b0.7144675020252703
50a0.9241033029553638
51b0.9224066539061563
52a0.7921428427242647
53b0.04201872943415541
54a0.7109584387767923
55b0.44399229645771143
56a0.6462315565142189
57b0.9278373879088332
58a0.05024877058088262
59b0.6312982651033026
60a0.9366385163260367
61b0.6782692230673221
62a0.4102903581375026
63b0.9820022411530951
64a0.8933818723610153
65b0.7689274463818949
66a0.12852999507221108
67b0.23280253249966087
68a0.3519159145093642
69b0.7623271765616378
70a0.0950327102848717
71b0.541594848023831
72a0.44132274904991553
73b0.0262182080719231
74a0.29688675395424835
75b0.013697271460011429
76a0.16175663615061497
77b0.310263909925637
78a0.85465923655004
79b0.5443225471438795
80a0.7601070675117979
81b0.5756276766785573
82a0.05801399924131345
83b0.42703453458385565
84a0.454448157964057
85b0.34019302894428827
86a0.5648279512934778
87b0.6867161513811738
88a0.9806937271044117
89b0.2015572853640023
90a0.36662022664683835
91b0.6356138210444008
92a0.6389784097390983
93b0.13060252138677508
94a0.34283414230504206
95b0.7223138275279074
96a0.002637641184393247
97b0.5903620523967478
98a0.2274889299309827

Graphics

Graphics can be rendered as hiccup. Here is an example using SVG.

[:svg {:height 100, :width 100}
  [:circle
   {:cx 50,
    :cy 50,
    :fill "#d7d2c3",
    :r 40,
    :stroke "#3e3c3f",
    :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, Mon Feb 24 15:54:07 CET 2020.