Address
Also improve docs for dofile and related functions.
(def buf (buffer "(" name))
(while (< index arglen)
(buffer/push-string buf " ")
- (buffer/format buf "%p" (in args index))
+ (buffer/format buf "%j" (in args index))
(set index (+ index 1)))
(array/push modifiers (string buf ")\n\n" docstr))
# Build return value
(defn run-context
"Run a context. This evaluates expressions of janet in an environment,
and is encapsulates the parsing, compilation, and evaluation.
+ Returns (in environment :exit-value environment) when complete.
opts is a table or struct of options. The options are as follows:\n\n\t
:chunks - callback to read into a buffer - default is getline\n\t
:on-parse-error - callback when parsing fails - default is bad-parse\n\t
@{})
(defn dofile
- "Evaluate a file and return the resulting environment."
- [path & args]
- (def {:exit exit-on-error
- :source source
+ "Evaluate a file and return the resulting environment. :env, :expander, and
+ :evaluator are passed through to the underlying run-context call.
+ If exit is true, any top level errors will trigger a call to (os/exit 1)
+ after printing the error."
+ [path &keys
+ {:exit exit
:env env
:expander expander
- :evaluator evaluator} (table ;args))
+ :evaluator evaluator}]
(def f (if (= (type path) :core/file)
path
(file/open path :rb)))
(defn chunks [buf _] (file/read f 2048 buf))
(defn bp [&opt x y]
(def ret (bad-parse x y))
- (if exit-on-error (os/exit 1))
+ (if exit (os/exit 1))
ret)
(defn bc [&opt x y z]
(def ret (bad-compile x y z))
- (if exit-on-error (os/exit 1))
+ (if exit (os/exit 1))
ret)
(unless f
(error (string "could not find file " path)))
:on-status (fn [f x]
(when (not= (fiber/status f) :dead)
(debug/stacktrace f x)
- (if exit-on-error (os/exit 1) (eflush))))
+ (if exit (os/exit 1) (eflush))))
:evaluator evaluator
:expander expander
:source (if path-is-file "<anonymous>" spath)}))
any errors encountered at the top level in the module will cause (os/exit 1)
to be called. Dynamic bindings will NOT be imported."
[path & args]
- (def argm (map (fn [x]
- (if (keyword? x)
- x
- (string x)))
- args))
+ (def argm (map |(if (keyword? $) $ (string $)) args))
(tuple import* (string path) ;argm))
(defmacro use
"Similar to import, but imported bindings are not prefixed with a namespace
identifier. Can also import multiple modules in one shot."
[& modules]
- ~(do ,;(map (fn [x] ~(,import* ,(string x) :prefix "")) modules)))
+ ~(do ,;(map |~(,import* ,(string $) :prefix "") modules)))
###
###
the repl in."
[&opt chunks onsignal env]
(default env (make-env))
- (default chunks (fn [buf p] (getline (string "repl:"
+ (default chunks
+ (fn [buf p]
+ (getline
+ (string
+ "repl:"
((parser/where p) 0)
":"
(parser/state p :delimiters) "> ")
