Make first and rest fns instead of macros
car and cdr are still macros, but I'd recommend either making them fns or removing them.
This commit is contained in:
parent
5017e3c211
commit
849244f3b4
@ -149,6 +149,10 @@
|
|||||||
(setv f (get (.stack inspect) (+ n 1) 0))
|
(setv f (get (.stack inspect) (+ n 1) 0))
|
||||||
(get f.f_globals "__name__"))
|
(get f.f_globals "__name__"))
|
||||||
|
|
||||||
|
(defn first [coll]
|
||||||
|
"Return first item from `coll`"
|
||||||
|
(get coll 0))
|
||||||
|
|
||||||
(defn inc [n]
|
(defn inc [n]
|
||||||
"Increment n by 1"
|
"Increment n by 1"
|
||||||
(_numeric-check n)
|
(_numeric-check n)
|
||||||
@ -239,6 +243,10 @@
|
|||||||
(if (not (pred val))
|
(if (not (pred val))
|
||||||
(yield val)))))
|
(yield val)))))
|
||||||
|
|
||||||
|
(defn rest [coll]
|
||||||
|
"Get all the elements of a coll, except the first."
|
||||||
|
(slice coll 1))
|
||||||
|
|
||||||
(defn repeat [x &optional n]
|
(defn repeat [x &optional n]
|
||||||
"Yield x forever or optionally n times"
|
"Yield x forever or optionally n times"
|
||||||
(if (none? n)
|
(if (none? n)
|
||||||
@ -298,9 +306,9 @@
|
|||||||
(_numeric_check n)
|
(_numeric_check n)
|
||||||
(= n 0))
|
(= n 0))
|
||||||
|
|
||||||
(def *exports* '[calling-module-name cycle dec distinct disassemble drop
|
(def *exports* '[calling-module-name cycle dec distinct disassemble
|
||||||
drop-while empty? even? filter flatten float? gensym
|
drop drop-while empty? even? filter first flatten float?
|
||||||
inc instance? integer integer? iterable? iterate
|
gensym inc instance? integer integer? iterable? iterate
|
||||||
iterator? macroexpand macroexpand-1 neg? nil? none?
|
iterator? macroexpand macroexpand-1 neg? nil? none?
|
||||||
nth numeric? odd? pos? remove repeat repeatedly second
|
nth numeric? odd? pos? remove repeat repeatedly rest
|
||||||
string string? take take-nth take-while zero?])
|
second string string? take take-nth take-while zero?])
|
||||||
|
@ -70,12 +70,12 @@
|
|||||||
`(do ~@body)))
|
`(do ~@body)))
|
||||||
|
|
||||||
|
|
||||||
(defmacro-alias [car first] [thing]
|
(defmacro car [thing]
|
||||||
"Get the first element of a list/cons"
|
"Get the first element of a list/cons"
|
||||||
`(get ~thing 0))
|
`(get ~thing 0))
|
||||||
|
|
||||||
|
|
||||||
(defmacro-alias [cdr rest] [thing]
|
(defmacro cdr [thing]
|
||||||
"Get all the elements of a thing, except the first"
|
"Get all the elements of a thing, except the first"
|
||||||
`(slice ~thing 1))
|
`(slice ~thing 1))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user