doc! works!

This commit is contained in:
Scott Richmond 2024-06-04 13:28:20 -04:00
parent 478bc8649e
commit 4da846d8d7
2 changed files with 17 additions and 6 deletions

View File

@ -80,7 +80,13 @@
:string (get-in x [:token :lexeme]) :string (get-in x [:token :lexeme])
(error (string "cannot show pattern of unknown type " (x :type))))) (error (string "cannot show pattern of unknown type " (x :type)))))
(defn- docstring [fnn] :todo) (defn doc! [fnn]
(def {:name name :doc doc :body clauses} fnn)
(print "doccing " name)
(def patterns (map (fn [x] (-> x first show-patt)) clauses))
(print name)
(print (string/join patterns " "))
(print doc))
(defn- conj-set [sett value] (defn- conj-set [sett value]
(def new (merge sett)) (def new (merge sett))
@ -125,6 +131,9 @@
:set (-> x (dissoc :^type) keys) :set (-> x (dissoc :^type) keys)
@[x])) @[x]))
(defn print! [& args]
(print ;(map show args)))
(defn prn [x] (defn prn [x]
(pp x) (pp x)
x) x)
@ -140,7 +149,7 @@
(defn set! [x] (set (x :value) x)) (defn set! [x] (set (x :value) x))
(def ctx { (def ctx {
"print" print "print!" print!
"prn" prn "prn" prn
"eq" deep= "eq" deep=
"bool" bool "bool" bool
@ -161,6 +170,7 @@
"type" ludus/type "type" ludus/type
"stringify" stringify "stringify" stringify
"show" show "show" show
"doc!" doc!
"concat" concat "concat" concat
"conj" conj "conj" conj
"disj" disj "disj" disj
@ -194,7 +204,6 @@
Used in current prelude but not yet in base: Used in current prelude but not yet in base:
into/2 into/2
doc
to_dict to_dict
) )

View File

@ -554,7 +554,7 @@
# (def cleaned (get-in parsed [:ast :data 1])) # (def cleaned (get-in parsed [:ast :data 1]))
# (pp cleaned) # (pp cleaned)
# (interpret (parsed :ast) @{:^parent b/ctx}) # (interpret (parsed :ast) @{:^parent b/ctx})
(try (interpret (parsed :ast) @{}) (try (interpret (parsed :ast) @{:^parent b/ctx})
([e] (print "Ludus panicked!: " ([e] (print "Ludus panicked!: "
(if (struct? e) (error (e :msg)) (error e))))) (if (struct? e) (error (e :msg)) (error e)))))
) )
@ -562,12 +562,14 @@
(do (do
(set source ` (set source `
fn foo { fn foo {
"a foo, a bar" "a doc, another doc"
() -> :foo () -> :foo
(_) -> :bar (_) -> :bar
} }
doc! (foo)
`) `)
(def result (run)) (def result (run))
# (b/show result) (b/show result)
) )