Skip to content
/ janet Public
forked from janet-lang/janet

Commit

Permalink
Add forever macro and add names to anon fns.
Browse files Browse the repository at this point in the history
Adding names to anon functions that may error improves
stack traces, especially for user visible traces.
  • Loading branch information
bakpakin committed Jul 7, 2020
1 parent a1feb32 commit f580d2e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
All notable changes to this project will be documented in this file.

## Unreleased - ???
- Add `forever` macro.
- Add `any?` predicate to core.
- Add `jpm list-pkgs` subcommand to see which package aliases are in the listing.
- Add `jpm list-installed` subcommand to see which packages are installed.
Expand Down
17 changes: 11 additions & 6 deletions src/boot/boot.janet
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,11 @@
(with-syms [iter]
~(do (var ,iter ,n) (while (> ,iter 0) ,;body (-- ,iter)))))

(defmacro forever
"Evaluate body forever in a loop, or until a break statement."
[& body]
~(while true ,;body))

(defmacro each
"Loop over each value in ds. Returns nil."
[x ds & body]
Expand Down Expand Up @@ -2173,12 +2178,12 @@
(buffer/push-string buf "\n")))
(var returnval nil)
(run-context {:chunks chunks
:on-compile-error (fn [msg errf &]
:on-compile-error (fn compile-error [msg errf &]
(error (string "compile error: " msg)))
:on-parse-error (fn [p x]
:on-parse-error (fn parse-error [p x]
(error (string "parse error: " (parser/error p))))
:fiber-flags :i
:on-status (fn [f val]
:on-status (fn on-status [f val]
(if-not (= (fiber/status f) :dead)
(error val))
(set returnval val))
Expand Down Expand Up @@ -2770,17 +2775,17 @@
"k" (fn [&] (set *compile-only* true) (set *exit-on-error* false) 1)
"n" (fn [&] (set *colorize* false) 1)
"m" (fn [i &] (setdyn :syspath (in args (+ i 1))) 2)
"c" (fn [i &]
"c" (fn c-switch [i &]
(def e (dofile (in args (+ i 1))))
(spit (in args (+ i 2)) (make-image e))
(set *no-file* false)
3)
"-" (fn [&] (set *handleopts* false) 1)
"l" (fn [i &]
"l" (fn l-switch [i &]
(import* (in args (+ i 1))
:prefix "" :exit *exit-on-error*)
2)
"e" (fn [i &]
"e" (fn e-switch [i &]
(set *no-file* false)
(eval-string (in args (+ i 1)))
2)
Expand Down

0 comments on commit f580d2e

Please sign in to comment.