HS pick runtime: guard nil inputs so pick first/last/items/match/matches don't hang
- hs-pick-first/last/random/items/slice: short-circuit nil or non-list (strings flow through unchanged). - New hs-pick-match / hs-pick-matches wrappers around regex-match / regex-find-all, also nil-safe; compiler routes pick-match / pick-matches through them. Unblocks 'pick first from null returns null' and 'pick match from null returns null' which previously looped past step_limit.
This commit is contained in:
@@ -818,7 +818,7 @@
|
|||||||
(quote set!)
|
(quote set!)
|
||||||
(quote it)
|
(quote it)
|
||||||
(list
|
(list
|
||||||
(quote regex-match)
|
(quote hs-pick-match)
|
||||||
(hs-to-sx (nth ast 1))
|
(hs-to-sx (nth ast 1))
|
||||||
(hs-to-sx (nth ast 2)))))
|
(hs-to-sx (nth ast 2)))))
|
||||||
((= head (quote pick-matches))
|
((= head (quote pick-matches))
|
||||||
@@ -826,7 +826,7 @@
|
|||||||
(quote set!)
|
(quote set!)
|
||||||
(quote it)
|
(quote it)
|
||||||
(list
|
(list
|
||||||
(quote regex-find-all)
|
(quote hs-pick-matches)
|
||||||
(hs-to-sx (nth ast 1))
|
(hs-to-sx (nth ast 1))
|
||||||
(hs-to-sx (nth ast 2)))))
|
(hs-to-sx (nth ast 2)))))
|
||||||
((= head (quote prop-is))
|
((= head (quote prop-is))
|
||||||
|
|||||||
@@ -1767,37 +1767,67 @@
|
|||||||
hs-slice
|
hs-slice
|
||||||
(fn
|
(fn
|
||||||
(col start end)
|
(col start end)
|
||||||
(let
|
(cond
|
||||||
((s (if (nil? start) 0 start))
|
((nil? col) nil)
|
||||||
(e (if (nil? end) (len col) (+ end 1))))
|
((not (list? col)) col)
|
||||||
(slice col s e))))
|
(true
|
||||||
|
(let
|
||||||
|
((s (if (nil? start) 0 start))
|
||||||
|
(e (if (nil? end) (len col) (+ end 1))))
|
||||||
|
(slice col s e))))))
|
||||||
|
|
||||||
(define
|
(define
|
||||||
hs-pick-first
|
hs-pick-first
|
||||||
(fn
|
(fn
|
||||||
(col n)
|
(col n)
|
||||||
(let ((m (if (< n (len col)) n (len col)))) (slice col 0 m))))
|
(cond
|
||||||
|
((nil? col) nil)
|
||||||
|
((not (list? col)) col)
|
||||||
|
(true
|
||||||
|
(let ((m (if (< n (len col)) n (len col)))) (slice col 0 m))))))
|
||||||
|
|
||||||
(define
|
(define
|
||||||
hs-pick-last
|
hs-pick-last
|
||||||
(fn
|
(fn
|
||||||
(col n)
|
(col n)
|
||||||
(let
|
(cond
|
||||||
((total (len col)))
|
((nil? col) nil)
|
||||||
(let
|
((not (list? col)) col)
|
||||||
((start (if (< n total) (- total n) 0)))
|
(true
|
||||||
(slice col start total)))))
|
(let
|
||||||
|
((total (len col)))
|
||||||
|
(let
|
||||||
|
((start (if (< n total) (- total n) 0)))
|
||||||
|
(slice col start total)))))))
|
||||||
|
|
||||||
(define
|
(define
|
||||||
hs-pick-random
|
hs-pick-random
|
||||||
(fn
|
(fn
|
||||||
(col n)
|
(col n)
|
||||||
(if
|
(cond
|
||||||
(nil? n)
|
((nil? col) nil)
|
||||||
(first col)
|
((not (list? col)) col)
|
||||||
(let ((m (if (< n (len col)) n (len col)))) (slice col 0 m)))))
|
((nil? n) (first col))
|
||||||
|
(true
|
||||||
|
(let ((m (if (< n (len col)) n (len col)))) (slice col 0 m))))))
|
||||||
|
|
||||||
(define hs-pick-items (fn (col start end) (slice col start end)))
|
(define
|
||||||
|
hs-pick-items
|
||||||
|
(fn
|
||||||
|
(col start end)
|
||||||
|
(cond
|
||||||
|
((nil? col) nil)
|
||||||
|
((not (list? col)) col)
|
||||||
|
(true (slice col start end)))))
|
||||||
|
|
||||||
|
(define
|
||||||
|
hs-pick-match
|
||||||
|
(fn
|
||||||
|
(regex haystack)
|
||||||
|
(cond
|
||||||
|
((nil? haystack) nil)
|
||||||
|
((nil? regex) nil)
|
||||||
|
(true (regex-match regex haystack)))))
|
||||||
|
|
||||||
(define
|
(define
|
||||||
hs-sorted-by
|
hs-sorted-by
|
||||||
|
|||||||
@@ -818,7 +818,7 @@
|
|||||||
(quote set!)
|
(quote set!)
|
||||||
(quote it)
|
(quote it)
|
||||||
(list
|
(list
|
||||||
(quote regex-match)
|
(quote hs-pick-match)
|
||||||
(hs-to-sx (nth ast 1))
|
(hs-to-sx (nth ast 1))
|
||||||
(hs-to-sx (nth ast 2)))))
|
(hs-to-sx (nth ast 2)))))
|
||||||
((= head (quote pick-matches))
|
((= head (quote pick-matches))
|
||||||
@@ -826,7 +826,7 @@
|
|||||||
(quote set!)
|
(quote set!)
|
||||||
(quote it)
|
(quote it)
|
||||||
(list
|
(list
|
||||||
(quote regex-find-all)
|
(quote hs-pick-matches)
|
||||||
(hs-to-sx (nth ast 1))
|
(hs-to-sx (nth ast 1))
|
||||||
(hs-to-sx (nth ast 2)))))
|
(hs-to-sx (nth ast 2)))))
|
||||||
((= head (quote prop-is))
|
((= head (quote prop-is))
|
||||||
|
|||||||
@@ -1767,37 +1767,67 @@
|
|||||||
hs-slice
|
hs-slice
|
||||||
(fn
|
(fn
|
||||||
(col start end)
|
(col start end)
|
||||||
(let
|
(cond
|
||||||
((s (if (nil? start) 0 start))
|
((nil? col) nil)
|
||||||
(e (if (nil? end) (len col) (+ end 1))))
|
((not (list? col)) col)
|
||||||
(slice col s e))))
|
(true
|
||||||
|
(let
|
||||||
|
((s (if (nil? start) 0 start))
|
||||||
|
(e (if (nil? end) (len col) (+ end 1))))
|
||||||
|
(slice col s e))))))
|
||||||
|
|
||||||
(define
|
(define
|
||||||
hs-pick-first
|
hs-pick-first
|
||||||
(fn
|
(fn
|
||||||
(col n)
|
(col n)
|
||||||
(let ((m (if (< n (len col)) n (len col)))) (slice col 0 m))))
|
(cond
|
||||||
|
((nil? col) nil)
|
||||||
|
((not (list? col)) col)
|
||||||
|
(true
|
||||||
|
(let ((m (if (< n (len col)) n (len col)))) (slice col 0 m))))))
|
||||||
|
|
||||||
(define
|
(define
|
||||||
hs-pick-last
|
hs-pick-last
|
||||||
(fn
|
(fn
|
||||||
(col n)
|
(col n)
|
||||||
(let
|
(cond
|
||||||
((total (len col)))
|
((nil? col) nil)
|
||||||
(let
|
((not (list? col)) col)
|
||||||
((start (if (< n total) (- total n) 0)))
|
(true
|
||||||
(slice col start total)))))
|
(let
|
||||||
|
((total (len col)))
|
||||||
|
(let
|
||||||
|
((start (if (< n total) (- total n) 0)))
|
||||||
|
(slice col start total)))))))
|
||||||
|
|
||||||
(define
|
(define
|
||||||
hs-pick-random
|
hs-pick-random
|
||||||
(fn
|
(fn
|
||||||
(col n)
|
(col n)
|
||||||
(if
|
(cond
|
||||||
(nil? n)
|
((nil? col) nil)
|
||||||
(first col)
|
((not (list? col)) col)
|
||||||
(let ((m (if (< n (len col)) n (len col)))) (slice col 0 m)))))
|
((nil? n) (first col))
|
||||||
|
(true
|
||||||
|
(let ((m (if (< n (len col)) n (len col)))) (slice col 0 m))))))
|
||||||
|
|
||||||
(define hs-pick-items (fn (col start end) (slice col start end)))
|
(define
|
||||||
|
hs-pick-items
|
||||||
|
(fn
|
||||||
|
(col start end)
|
||||||
|
(cond
|
||||||
|
((nil? col) nil)
|
||||||
|
((not (list? col)) col)
|
||||||
|
(true (slice col start end)))))
|
||||||
|
|
||||||
|
(define
|
||||||
|
hs-pick-match
|
||||||
|
(fn
|
||||||
|
(regex haystack)
|
||||||
|
(cond
|
||||||
|
((nil? haystack) nil)
|
||||||
|
((nil? regex) nil)
|
||||||
|
(true (regex-match regex haystack)))))
|
||||||
|
|
||||||
(define
|
(define
|
||||||
hs-sorted-by
|
hs-sorted-by
|
||||||
|
|||||||
Reference in New Issue
Block a user