Compare commits

...

3 Commits

Author SHA1 Message Date
Scott Richmond
4da846d8d7 doc! works! 2024-06-04 13:28:20 -04:00
Scott Richmond
478bc8649e add runtime doc info 2024-06-04 13:04:53 -04:00
Scott Richmond
1842923fa3 clean up little bugs 2024-06-04 13:02:15 -04:00
3 changed files with 22 additions and 13 deletions

View File

@ -78,9 +78,15 @@
:typed (string (show-patt (get-in x [:data 1])) " as " (show-patt (get-in x [:data 0])))
:interpolated (get-in x [:token :lexeme])
:string (get-in x [:token :lexeme])
(error "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]
(def new (merge sett))
@ -125,6 +131,9 @@
:set (-> x (dissoc :^type) keys)
@[x]))
(defn print! [& args]
(print ;(map show args)))
(defn prn [x]
(pp x)
x)
@ -140,7 +149,7 @@
(defn set! [x] (set (x :value) x))
(def ctx {
"print" print
"print!" print!
"prn" prn
"eq" deep=
"bool" bool
@ -161,6 +170,7 @@
"type" ludus/type
"stringify" stringify
"show" show
"doc!" doc!
"concat" concat
"conj" conj
"disj" disj
@ -194,7 +204,6 @@
Used in current prelude but not yet in base:
into/2
doc
to_dict
)

View File

@ -358,8 +358,8 @@
# Depends on: good string representation of patterns
# For now, this should be enough to tall the thing
(defn- fnn [ast ctx]
(def {:name name :data clauses} ast)
(def the-fn @{:name name :^type :fn :body clauses :ctx ctx})
(def {:name name :data clauses :doc doc} ast)
(def the-fn @{:name name :^type :fn :body clauses :ctx ctx :doc doc})
(set (ctx name) the-fn))
(defn- is_placeholder [x] (= x :_))
@ -554,7 +554,7 @@
# (def cleaned (get-in parsed [:ast :data 1]))
# (pp cleaned)
# (interpret (parsed :ast) @{:^parent b/ctx})
(try (interpret (parsed :ast) @{})
(try (interpret (parsed :ast) @{:^parent b/ctx})
([e] (print "Ludus panicked!: "
(if (struct? e) (error (e :msg)) (error e)))))
)
@ -562,13 +562,14 @@
(do
(set source `
fn foo {
"a foo, a bar"
"a doc, another doc"
() -> :foo
(_) -> :bar
}
foo ()
doc! (foo)
`)
(def result (run))
# (b/show result)
(b/show result)
)

View File

@ -1132,15 +1132,14 @@
)
(do
# (comment
# (do
(comment
(def source `(foo as :bar, 12, :foo, _thing)
`)
(def scanned (s/scan source))
(print "\n***NEW PARSE***\n")
(def a-parser (new-parser scanned))
(def parsed (pattern a-parser))
(print (show-patt parsed))
)