From 855a9a01fc85a03fe3b76086732022fc1127c9b1 Mon Sep 17 00:00:00 2001 From: Michael Camilleri Date: Mon, 22 Feb 2021 12:38:56 +0900 Subject: [PATCH 1/5] Allow source location in run-context to be updated --- src/boot/boot.janet | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 931eaabc..c5f92089 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -2098,7 +2098,7 @@ :on-parse-error on-parse-error :fiber-flags guard :evaluator evaluator - :source where + :source default-where :parser parser :read read :expander expand} opts) @@ -2108,9 +2108,11 @@ (default on-compile-error bad-compile) (default on-parse-error bad-parse) (default evaluator (fn evaluate [x &] (x))) - (default where "") + (default default-where "") (default guard :ydt) + (var where default-where) + # Evaluate 1 source form in a protected manner (defn eval1 [source &opt l c] (def source (if expand (expand source) source)) @@ -2163,11 +2165,16 @@ (while parser-not-done (if (env :exit) (break)) (buffer/clear buf) - (if (= (chunks buf p) :cancel) + (match (= (chunks buf p)) + :cancel (do # A :cancel chunk represents a cancelled form in the REPL, so reset. (:flush p) (buffer/clear buf)) + + [:source new-where] + (set where new-where) + (do (var pindex 0) (var pstatus nil) From f381a9c773374b38e3e2fecc9b30214a64f4fb5a Mon Sep 17 00:00:00 2001 From: Michael Camilleri Date: Mon, 22 Feb 2021 12:50:44 +0900 Subject: [PATCH 2/5] Check that new source location is a string --- src/boot/boot.janet | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index c5f92089..c3082919 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -2173,7 +2173,9 @@ (buffer/clear buf)) [:source new-where] - (set where new-where) + (if (string? new-where) + (set where new-where) + (set where default-where)) (do (var pindex 0) From 1f8c2781ddab114de94447d247e52e79ce3076d7 Mon Sep 17 00:00:00 2001 From: John Gabriele Date: Tue, 23 Feb 2021 22:24:59 -0500 Subject: [PATCH 3/5] `sort` doc Clarify doc for `sort` and `sorted`. Also in `sort`, changed arg name. --- src/boot/boot.janet | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 931eaabc..246f8dd2 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -778,9 +778,12 @@ a) (defn sort - "Sort an array in-place. Uses quick-sort and is not a stable sort." - [a &opt before?] - (sort-help a 0 (- (length a) 1) (or before? <))) + ``Sort `ind` in-place, and return it. Uses quick-sort and is not a stable sort. + + If a `before?` comparator function is provided, sorts elements using that; + otherwise uses `<`.`` + [ind &opt before?] + (sort-help ind 0 (- (length ind) 1) (or before? <))) (defn sort-by ``Returns `ind` sorted by calling @@ -789,7 +792,10 @@ (sort ind (fn [x y] (< (f x) (f y))))) (defn sorted - "Returns a new sorted array without modifying the old one." + ``Returns a new sorted array without modifying the old one. + + If a `before?` comparator function is provided, sorts elements using that; + otherwise uses `<`.`` [ind &opt before?] (sort (array/slice ind) before?)) From 0e44ce5cbab2a4bf116047eef5f9ee79881d1f97 Mon Sep 17 00:00:00 2001 From: John Gabriele Date: Tue, 23 Feb 2021 22:26:53 -0500 Subject: [PATCH 4/5] Update boot.janet --- src/boot/boot.janet | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 246f8dd2..ab30f496 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -780,7 +780,7 @@ (defn sort ``Sort `ind` in-place, and return it. Uses quick-sort and is not a stable sort. - If a `before?` comparator function is provided, sorts elements using that; + If a `before?` comparator function is provided, sorts elements using that, otherwise uses `<`.`` [ind &opt before?] (sort-help ind 0 (- (length ind) 1) (or before? <))) @@ -794,7 +794,7 @@ (defn sorted ``Returns a new sorted array without modifying the old one. - If a `before?` comparator function is provided, sorts elements using that; + If a `before?` comparator function is provided, sorts elements using that, otherwise uses `<`.`` [ind &opt before?] (sort (array/slice ind) before?)) From be7dab4d17bdcdc379aa98f1602b84cbfe20a1ef Mon Sep 17 00:00:00 2001 From: John Gabriele Date: Tue, 23 Feb 2021 22:30:42 -0500 Subject: [PATCH 5/5] Update boot.janet --- src/boot/boot.janet | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index ab30f496..c9be359f 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -787,7 +787,7 @@ (defn sort-by ``Returns `ind` sorted by calling - a function `f` on each element and comparing the result with <.`` + a function `f` on each element and comparing the result with `<`.`` [f ind] (sort ind (fn [x y] (< (f x) (f y))))) @@ -801,7 +801,7 @@ (defn sorted-by ``Returns a new sorted array that compares elements by invoking - a function `f` on each element and comparing the result with <.`` + a function `f` on each element and comparing the result with `<`.`` [f ind] (sorted ind (fn [x y] (< (f x) (f y)))))