• Stars
    star
    1,819
  • Rank 25,522 (Top 0.6 %)
  • Language
    Clojure
  • License
    ISC License
  • Created over 3 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⚡️ Moldable Live Programming for Clojure

Clerk: Local-First Notebooks for Clojure

Clerk

Clojars Project

Moldable Live Programming for Clojure

🎪 View Demos📖 Book of Clerk 👩‍🎨 Using Clerk🪚 Development

Clerk takes a Clojure namespace and turns it into a notebook:

Clerk Screenshot

🎪 Demos

Clerk comes with a demo repo full of interesting use cases. Check them out and feel free to add your own via PRs.

⚖️ Rationale

Computational notebooks allow arguing from evidence by mixing prose with executable code. For a good overview of problems users encounter in traditional notebooks like Jupyter, see I don't like notebooks and What’s Wrong with Computational Notebooks? Pain Points, Needs, and Design Opportunities.

Specifically Clerk wants to address the following problems:

  • Less helpful than my editor
  • Notebook code being hard to reuse
  • Reproduction problems coming from out-of-order execution
  • Problems with archival and putting notebooks in source control

Clerk is a notebook library for Clojure that aims to address these problems by doing less, namely:

  • no editing environment, folks can keep using the editors they know and love
  • no new format: Clerk notebooks are either regular Clojure namespaces (interspersed with markdown comments) or regular markdown files (interspersed with Clojure code fences). This also means Clerk notebooks are meant to be stored in source control.
  • no out-of-order execution: Clerk notebooks always evaluate from top to bottom. Clerk builds a dependency graph of Clojure vars and only recomputes the needed changes to keep the feedback loop fast.
  • no external process: Clerk runs inside your Clojure process, giving Clerk access to all code on the classpath.

🚦 Status

ALPHA, expect breaking changes.

👩‍🎨 Using Clerk

To use Clerk in your project, you'll need Java 11+ and clojure. Add the following dependency to your deps.edn:

{:deps {io.github.nextjournal/clerk {:mvn/version "0.14.919"}}}

Require and start Clerk as part of your system start, e.g. in user.clj:

(require '[nextjournal.clerk :as clerk])

;; start Clerk's built-in webserver on the default port 7777, opening the browser when done
(clerk/serve! {:browse true})

;; either call `clerk/show!` explicitly
(clerk/show! "notebooks/rule_30.clj")

;; or let Clerk watch the given `:paths` for changes
(clerk/serve! {:watch-paths ["notebooks" "src"]})

;; start with watcher and show filter function to enable notebook pinning
(clerk/serve! {:watch-paths ["notebooks" "src"] :show-filter-fn #(clojure.string/starts-with? % "notebooks")})

;; Build a html file from the given notebook notebooks.
;; See the docstring for more options.
(clerk/build! {:paths ["notebooks/rule_30.clj"]})

You can then access Clerk at http://localhost:7777.

See the /notebooks folder in the Clerk repository for a number of sample notebooks.

Editor Workflow

For even better flow states, we recommend you bind clerk/show! to a shortcut in your favorite editor:

Emacs

In Emacs, add the following to your config:

(defun clerk-show ()
  (interactive)
  (when-let
      ((filename
        (buffer-file-name)))
    (save-buffer)
    (cider-interactive-eval
     (concat "(nextjournal.clerk/show! \"" filename "\")"))))

(define-key clojure-mode-map (kbd "<M-return>") 'clerk-show)

IntelliJ/Cursive

In IntelliJ/Cursive, you can set up REPL commands via:

  • going to Tools→REPL→Add New REPL Command, then
  • add the following command: (show! "~file-path");
  • make sure the command is executed in the nextjournal.clerk namespace;
  • lastly assign a shortcut of your choice via Settings→Keymap

Neovim + Conjure

With neovim + conjure one can use the following vimscript function to save the file and show it with Clerk:

function! ClerkShow()
  exe "w"
  exe "ConjureEval (nextjournal.clerk/show! \"" . expand("%:p") . "\")"
endfunction

nmap <silent> <localleader>cs :execute ClerkShow()<CR>

🪚 Developing Clerk

Make sure you have Babashka installed, and run:

bb dev :browse true

The will start everything needed to develop Clerk and open your default browser. You can connect your favorite editor to it using nREPL.

Any trailing arguments to bb dev will be forwarded to clojure -X and clerk/serve!. So if you prefer to not open your browser, leave out the :browse true arguments.

🐞 Known Issues

See notebooks/onwards.md.

Citing Clerk

If you are a researcher and use Clerk in your work, we encourage you to cite our work. You can use the following BibTeX citation:

@misc{clerk-github,
  author =  {Martin Kavalar and
             Jack Rusher},
  title = {{Clerk Source Code}},
  howpublished = {\url{https://github.com/nextjournal/clerk}},
  month        = feb,
  year         = 2023
}

More Repositories

1

clerk-demo

🤹 A bucket of interesting Clerk demos.
Clojure
162
star
2

clojure-mode

Clojure/Script mode for CodeMirror 6
Clojure
160
star
3

beholder

The Clojure directory watcher from Krell as a standalone library.
Clojure
116
star
4

clerk-slideshow

Clojure
53
star
5

lazo

Clojure
41
star
6

markdown

A cross-platform clojure/script parser for Markdown
Clojure
38
star
7

lurk

A log dashboard tool powered by Clerk and Lucene
Clojure
30
star
8

freerange

Clojure
29
star
9

simple-http-server

A simple http server implemented as thin Clojure wrapper around `SimpleWebServer` from JEP 408 for JDK 18+.
Clojure
25
star
10

lezer-clojure

This is a Clojure grammar for the lezer parser system.
JavaScript
23
star
11

advent-of-clerk

A template repo for folks wanting to do Advent of Code with Clerk.
Clojure
16
star
12

ssh-auth-github

Script to retrieve public SSH keys from teams on GitHub
Clojure
10
star
13

garden-cli

Command-line interface for application.garden
Clojure
10
star
14

viewers

Making you see things.
Clojure
8
star
15

clerkboard

It's Clerk showing a Dashboard
Clojure
8
star
16

book-of-clerk

The 📖 Book of Clerk
Clojure
6
star
17

lang-clojure

Clojure language support for the CodeMirror code editor
TypeScript
5
star
18

clerk-cljs-demo

A demo project showing a custom CLJS build for Clerk.
Clojure
4
star
19

clerk-test

Clerk integration tools for clojure kaocha test runner
Clojure
4
star
20

garden-cron

Background tasks for application.garden
Clojure
4
star
21

datalevin-example.apps.garden

A demo for setting up datalevin within application.garden projects
Clojure
4
star
22

clojurescript-graaljs

GraalJS build target support for ClojureScript
Clojure
3
star
23

clerk-analyzer-issues

Clojure
2
star
24

nextmirror

Experimental repo for prosemirror and figwheel-main
Clojure
2
star
25

clerk-website

Clerk’s face on the World Wide Web
Clojure
2
star
26

clerk-cljs-template

2
star
27

mediKanren-web

A web UI for mediKanren
Clojure
2
star
28

tafuta

Searching git repositories made easy.
Clojure
2
star
29

clerk-dwim

Proof of concept of a Do What I Mean Viewer for Clerk
Clojure
2
star
30

blog

The New Nextjournal Blog – Made with Clerk Garden
Clojure
1
star
31

infinit

Custom image for the Infinit Filesystem. Based on official alpine builds from infinit.sh.
Shell
1
star
32

guix-docker

Dockerfile for GNU Guix
1
star
33

garden-id

Authentication for application.garden
Clojure
1
star
34

garden-template

Default template for new projects for application.garden
Clojure
1
star
35

garden-email

Email library for application.garden.
Clojure
1
star
36

prosemirror-gapcursor-bug

Using the codemirror example from ProseMirror’s website to debug a potential gap cursor regression
JavaScript
1
star
37

clojure-mode-demo

Sample project showing how to use clojure-mode with shadow-cljs.
Clojure
1
star
38

clerkless

An empty shell of Clerk's Public API.
Clojure
1
star
39

cas-client

Clojure
1
star
40

cas

Library for storing content-addressed blobs to cloud buckets.
Clojure
1
star
41

demand_based_runner

resource limiting demand based runner sketch
Elixir
1
star