Skip to content

Instantly share code, notes, and snippets.

@PEZ
Last active October 9, 2024 21:41
Show Gist options
  • Save PEZ/0890cf6d1f3b009d49d5a4980deedd07 to your computer and use it in GitHub Desktop.
Save PEZ/0890cf6d1f3b009d49d5a4980deedd07 to your computer and use it in GitHub Desktop.
Learn Datalog Today REPL Fiddle
(ns learndatalogtoday.repl-fiddle
(:require [learndatalogtoday.handler :as handler]
[datomic.client.api :as d]))
(defn exercise-chapter [n]
(reduce (fn [acc {:keys [question inputs :as exercise]}]
(conj acc [(count acc)
question ((fn [[query & args]]
(list 'comment
(apply list
(cond-> ['d/q \' (:value query) 'db]
(seq args) (into (map :value args))))))
inputs)]))
[]
(:exercises (handler/read-chapter n))))
(defn give-up [ch ex]
(-> ch
(handler/read-chapter)
:exercises
(get ex)
:inputs
first
:correct-value))
(def schema (handler/read-file "db/schema.edn"))
(def seed-data (handler/read-file "db/data.edn"))
(def db (handler/init-db "movies" schema seed-data))
(comment
(exercise-chapter 0) ; Evaluate to ignore
#_[[0 "Find all movies titles in the database."
(comment (d/q \' [:find ...] db))]]
;; Then remove ignore marker and the backslash, and add newlines wherever it makes sense
(give-up 0 0) ; Evaluate to peek
:rcf)
@PEZ
Copy link
Author

PEZ commented Oct 9, 2024

For fiddling with https://www.learndatalogtoday.org/ exercises in the REPL.

  1. Clone https://github.com/jonase/learndatalogtoday to your machine
  2. Start the REPL
  3. Load this file in the REPL
  4. Read a chapter on https://www.learndatalogtoday.org/ (or run the server locally if you're on a plane, say)
  5. Evaluate stuff like (exercise-chapter 0) to ignores, do some little cleanup
  6. Edit the query and evaluate the (d/q ...) forms

More resources:

@PEZ
Copy link
Author

PEZ commented Oct 9, 2024

It breaks down at chapter 9, I now notice. 😄

@PEZ
Copy link
Author

PEZ commented Oct 9, 2024

If you run the server locally, you can submit an exercise for chapter 9, without editing the placeholder rules, and look at the stdout from the REPL to see what your (d/q ...) expression should look like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment