1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-30 07:03:02 +00:00

Fix compiler optimization for if.

Add pattern matching library.
This commit is contained in:
Calvin Rose
2018-12-07 23:57:19 -05:00
parent f2743aca36
commit b7d44ba742
3 changed files with 61 additions and 2 deletions

View File

@@ -60,7 +60,7 @@
(defmacro def-
"Define a private value that will not be exported."
[name & more]
~(def name :private ,;more))
~(def ,name :private ,;more))
(defn defglobal
"Dynamically create a global def."
@@ -614,6 +614,16 @@
(array/push res item)))
res)
(defn count
"Count the number of items in ind for which (pred item)
is true."
[pred ind]
(var counter 0)
(loop [item :in ind]
(if (pred item)
(++ counter)))
counter)
(defn keep
"Given a predicate, take only elements from an array or tuple for
which (pred element) is truthy. Returns a new array of truthy predicate results."