Last active
October 9, 2024 21:41
-
-
Save PEZ/0890cf6d1f3b009d49d5a4980deedd07 to your computer and use it in GitHub Desktop.
Learn Datalog Today REPL Fiddle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
It breaks down at chapter 9, I now notice. 😄
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
For fiddling with https://www.learndatalogtoday.org/ exercises in the REPL.
(exercise-chapter 0)
to ignores, do some little cleanup(d/q ...)
formsMore resources: