init research

This commit is contained in:
2026-02-08 11:20:43 -10:00
commit bdf064f54d
3041 changed files with 1592200 additions and 0 deletions
+123
View File
@@ -0,0 +1,123 @@
(ns conversion
(:require [clojure.string :as string]))
;; This namespace has been used to convert the old `docs/index.Rmd` documentation to the new `notebooks/index.clj` documentation. Some additional manual editing was needed to make things work afterwards.
(set! *print-length* 1000)
(def example-doc
(slurp "docs/index.Rmd"
#_"https://raw.githubusercontent.com/scicloj/tablecloth/master/docs/index.Rmd"))
(defn chunk-end? [line]
(= line "```"))
(defn clojure-chunk-beginning? [line]
(re-matches #"```\{clojure.*\}" line))
(defn clojure-chunk-options [line]
(-> line
(string/replace #"^```\{clojure" "")
(string/replace #"\}$" "")))
(defn markdown->markdown-with-extracted-clojure-chunks [markdown]
(loop [lines (string/split markdown #"\n")
current-clojure-chunk-code nil
current-clojure-chunk-options nil
result []]
(if-let [current-line (first lines)]
(if current-clojure-chunk-code
(if (chunk-end? current-line)
(recur (rest lines)
nil
nil
(conj result {:clojure-chunk? true
:code current-clojure-chunk-code
:options current-clojure-chunk-options}))
(recur (rest lines)
(conj current-clojure-chunk-code current-line)
current-clojure-chunk-options
result))
(if (clojure-chunk-beginning? current-line)
(recur (rest lines)
[]
(clojure-chunk-options current-line)
result)
(recur (rest lines)
nil
nil
(conj result current-line))))
result)))
(defn clojure-chunk->markdown [{:keys [clojure-chunk? code options]}]
(when clojure-chunk?
(str "```{clojure"
options
"}\n"
(string/join "\n" code)
"\n```")))
(defn markdown-with-extracted-clojure-chunks->markdown [mwecc]
(->> mwecc
(map #(or (clojure-chunk->markdown %)
%))
(string/join "\n")
(format "%s\n")))
(comment
(->> example-doc
(spit "/tmp/0.Rmd"))
(->> example-doc
markdown->markdown-with-extracted-clojure-chunks
markdown-with-extracted-clojure-chunks->markdown
(spit "/tmp/a.Rmd"))
(->> example-doc
markdown->markdown-with-extracted-clojure-chunks
markdown-with-extracted-clojure-chunks->markdown
(= example-doc))
(->> example-doc
markdown->markdown-with-extracted-clojure-chunks
(partition-by string?)))
(defn inner-pr-str [s]
(let [s1 (pr-str s)
n (count s1)]
(subs s1 1 (dec n))))
(defn markdown-with-extracted-clojure-chunks->clojure [mwecc]
(->> mwecc
(partition-by string?)
(mapcat (fn [part]
(cond (-> part first string?) [(->> part
(map inner-pr-str)
(string/join "\n")
((fn [s]
(if (seq s)
(format "(md \"%s\")" s)
""))))]
(-> part first :clojure-chunk?) [(->> part
(mapcat
(fn [{:keys [code options]}]
code
#_(cons (format "^{:chunk-options \"%s\"}[]\n"
options)
code)))
(string/join "\n"))])))
(string/join "\n\n\n")
(format "
(ns index
(:require [scicloj.kindly.v3.kind :as kind]
[scicloj.kindly-default.v1.api :refer [md]]
[tablecloth.api :as tc]
[scicloj.note-to-test.v1.api :as note-to-test]))
%s")))
(->> example-doc
markdown->markdown-with-extracted-clojure-chunks
markdown-with-extracted-clojure-chunks->clojure
(spit "notebooks/index.clj"))
+12
View File
@@ -0,0 +1,12 @@
(ns gendocs
(:require [scicloj.clay.v2.api :as clay]))
(clay/make! {:format [:quarto :html]
:source-path "notebooks/index.clj"
:base-target-path "docs"})
;; beta54
(clay/make! {:format [:quarto :html]
:base-source-path "notebooks"
:source-path "index.clj"
:base-target-path "docs"})
+7
View File
@@ -0,0 +1,7 @@
(ns profile
(:require [clj-async-profiler.core :as prof]))
(defn -main []
(println "Profiling...")
(prof/profile (require '[tablecloth.api]))
(println "Done. See /tmp/clj-async-profiler/results/"))
+85
View File
@@ -0,0 +1,85 @@
(ns readme-generation
(:require [clojure.string :as str]
[clojure.pprint :as pp]))
(set! *print-length* 1000)
(defn chunk-end? [line]
(= line "```"))
(defn clojure-chunk-beginning? [line]
(re-matches #"```\{clojure.*\}" line))
(defn clojure-chunk-options [line]
(-> line
(str/replace #"^```\{clojure" "")
(str/replace #"\}$" "")))
(defn markdown->markdown-with-extracted-clojure-chunks [markdown]
(loop [lines (str/split markdown #"\n")
current-clojure-chunk-code nil
current-clojure-chunk-options nil
result []]
(if-let [current-line (first lines)]
(if current-clojure-chunk-code
(if (chunk-end? current-line)
(recur (rest lines)
nil
nil
(conj result {:clojure-chunk? true
:code current-clojure-chunk-code
:options current-clojure-chunk-options}))
(recur (rest lines)
(conj current-clojure-chunk-code current-line)
current-clojure-chunk-options
result))
(if (clojure-chunk-beginning? current-line)
(recur (rest lines)
[]
(clojure-chunk-options current-line)
result)
(recur (rest lines)
nil
nil
(conj result current-line))))
result)))
(defn markdown-with-extracted-clojure-chunks->markdown-evaluated [mwecc]
(->> mwecc
(map (fn [element]
(if (string? element)
element
(let [{:keys [code options]} element
options-map (-> options
str/trim
(str/split #"=")
(->> (map read-string)
(apply hash-map)))]
(str (format "```{clojure}\n%s\n```\n"
(->> code
(str/join "\n")))
(if (-> options-map
(get 'eval)
(= 'FALSE))
""
(let [result (->> code
(str/join "\n")
load-string)]
(case (-> options-map
(get 'results))
"hide" ""
"asis" (-> result
pp/pprint
with-out-str)))))))))
(str/join "\n")))
(defn generate! []
(->> "README-source.md"
slurp
markdown->markdown-with-extracted-clojure-chunks
markdown-with-extracted-clojure-chunks->markdown-evaluated
(spit "README.md")))
(comment
(generate!))