1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-27 00:40:26 +00:00

Make match macro prettier.

This commit is contained in:
Calvin Rose 2019-01-18 15:24:58 -05:00
parent 26818a5e5c
commit 5ba969f91d

View File

@ -1079,7 +1079,7 @@ value, one key will be ignored."
[pattern expr onmatch seen] [pattern expr onmatch seen]
(cond (cond
(and (symbol? pattern) (not (keyword? pattern))) (symbol? pattern)
(if (get seen pattern) (if (get seen pattern)
~(if (= ,pattern ,expr) ,(onmatch) ,sentinel) ~(if (= ,pattern ,expr) ,(onmatch) ,sentinel)
(do (do
@ -1138,8 +1138,7 @@ value, one key will be ignored."
((fn aux [i] ((fn aux [i]
(cond (cond
(= i len-1) (get cases i) (= i len-1) (get cases i)
(< i len-1) (do (< i len-1) (with-syms [$res]
(def $res (gensym))
~(if (= ,sentinel (def ,$res ,(match-1 (get cases i) $x (fn [] (get cases (inc i))) @{}))) ~(if (= ,sentinel (def ,$res ,(match-1 (get cases i) $x (fn [] (get cases (inc i))) @{})))
,(aux (+ 2 i)) ,(aux (+ 2 i))
,$res)))) 0))) ,$res)))) 0)))