Martin Kavalar / Jan 21 2021 / Published
Rule 30
Rule 30 in ClojureScript to demonstrate clojure-mode.
🔪 Structural editing:
Barfing 🤮 & Slurping 🥤
Forward
⌃
+←
/→
Backward
⌃
+⌥
+←
/→
💗 Grow/shrink selection
⌥
+↑
/↓
✂️ Unwrap
⌥
+s
🧙 form-wise evaluation
☝️ eval-at-cursor
⌥
+↵
🎚 eval-top-level
⌥
+⇧
+↵
🧫 eval-cell
⌘
+↵
(def rule
{[1 1 1] 0
[1 1 0] 0
[1 0 1] 0
[1 0 0] 1
[0 1 1] 1
[0 1 0] 1
[0 0 1] 1
[0 0 0] 0})
(->> (assoc (vec (repeat 33 0)) 16 1)
(iterate (mapv rule
(partition 3 1 (repeat 0) (cons 0 %))))
(take 17))
ClojureScript
→
🔮 Viewers
The following cell registers the custom viewers. This api is still alpha and subject to change.
(require [nextjournal.viewer :as v])
(v/register-viewers!
{:number :cell ;; use the cell viewer for numbers
:cell (v/view-as :hiccup
[:div.inline-block {:class (if (zero? %)
"bg-white border-solid border-2 border-black"
"bg-black")
:style {:width 16 :height 16}}])
:vector (fn [x options]
(->> x
(map (partial v/inspect options))
(into [:div.flex.inline-flex])
(v/view-as :hiccup)))
:list (fn [x options]
(->> x
(map (partial v/inspect options))
(into [:div.flex.flex-col])
(v/view-as :hiccup)))})
ClojureScript
→