replace slice
with cut
This commit is contained in:
parent
9fbd21adba
commit
61e4b9dfed
@ -1314,9 +1314,9 @@ class HyASTCompiler(object):
|
|||||||
col_offset=expr.start_column,
|
col_offset=expr.start_column,
|
||||||
targets=del_targets)
|
targets=del_targets)
|
||||||
|
|
||||||
@builds("slice")
|
@builds("cut")
|
||||||
@checkargs(min=1, max=4)
|
@checkargs(min=1, max=4)
|
||||||
def compile_slice_expression(self, expr):
|
def compile_cut_expression(self, expr):
|
||||||
expr.pop(0) # index
|
expr.pop(0) # index
|
||||||
val = self.compile(expr.pop(0)) # target
|
val = self.compile(expr.pop(0)) # target
|
||||||
|
|
||||||
@ -1600,7 +1600,7 @@ class HyASTCompiler(object):
|
|||||||
|
|
||||||
# We then pass the other arguments to the function
|
# We then pass the other arguments to the function
|
||||||
expr[0] = HyExpression(
|
expr[0] = HyExpression(
|
||||||
[HySymbol("slice"), tempvar, HyInteger(1)]
|
[HySymbol("cut"), tempvar, HyInteger(1)]
|
||||||
).replace(expr[0])
|
).replace(expr[0])
|
||||||
|
|
||||||
ret += self.compile(call)
|
ret += self.compile(call)
|
||||||
|
@ -57,7 +57,7 @@
|
|||||||
|
|
||||||
(defmacro cdr [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))
|
`(cut ~thing 1))
|
||||||
|
|
||||||
|
|
||||||
(defmacro cond [&rest branches]
|
(defmacro cond [&rest branches]
|
||||||
@ -104,7 +104,7 @@
|
|||||||
[(empty? args) `(do ~@body)]
|
[(empty? args) `(do ~@body)]
|
||||||
[(= (len args) 2) `(for* [~@args] ~@body)]
|
[(= (len args) 2) `(for* [~@args] ~@body)]
|
||||||
[true
|
[true
|
||||||
(let [[alist (slice args 0 nil 2)]]
|
(let [[alist (cut args 0 nil 2)]]
|
||||||
`(for* [(, ~@alist) (genexpr (, ~@alist) [~@args])] ~@body))]))
|
`(for* [(, ~@alist) (genexpr (, ~@alist) [~@args])] ~@body))]))
|
||||||
|
|
||||||
|
|
||||||
@ -175,7 +175,7 @@
|
|||||||
(defmacro defmacro/g! [name args &rest body]
|
(defmacro defmacro/g! [name args &rest body]
|
||||||
(let [[syms (list (distinct (filter (fn [x] (and (hasattr x "startswith") (.startswith x "g!"))) (flatten body))))]]
|
(let [[syms (list (distinct (filter (fn [x] (and (hasattr x "startswith") (.startswith x "g!"))) (flatten body))))]]
|
||||||
`(defmacro ~name [~@args]
|
`(defmacro ~name [~@args]
|
||||||
(let ~(HyList (map (fn [x] `[~x (gensym (slice '~x 2))]) syms))
|
(let ~(HyList (map (fn [x] `[~x (gensym (cut '~x 2))]) syms))
|
||||||
~@body))))
|
~@body))))
|
||||||
|
|
||||||
|
|
||||||
|
@ -291,18 +291,18 @@ def test_ast_bad_get():
|
|||||||
cant_compile("(get 1)")
|
cant_compile("(get 1)")
|
||||||
|
|
||||||
|
|
||||||
def test_ast_good_slice():
|
def test_ast_good_cut():
|
||||||
"Make sure AST can compile valid slice"
|
"Make sure AST can compile valid cut"
|
||||||
can_compile("(slice x)")
|
can_compile("(cut x)")
|
||||||
can_compile("(slice x y)")
|
can_compile("(cut x y)")
|
||||||
can_compile("(slice x y z)")
|
can_compile("(cut x y z)")
|
||||||
can_compile("(slice x y z t)")
|
can_compile("(cut x y z t)")
|
||||||
|
|
||||||
|
|
||||||
def test_ast_bad_slice():
|
def test_ast_bad_cut():
|
||||||
"Make sure AST can't compile invalid slice"
|
"Make sure AST can't compile invalid cut"
|
||||||
cant_compile("(slice)")
|
cant_compile("(cut)")
|
||||||
cant_compile("(slice 1 2 3 4 5)")
|
cant_compile("(cut 1 2 3 4 5)")
|
||||||
|
|
||||||
|
|
||||||
def test_ast_good_take():
|
def test_ast_good_take():
|
||||||
|
@ -536,11 +536,11 @@
|
|||||||
(assert (= (car [1 2 3 4 5]) 1)))
|
(assert (= (car [1 2 3 4 5]) 1)))
|
||||||
|
|
||||||
|
|
||||||
(defn test-slice []
|
(defn test-cut []
|
||||||
"NATIVE: test slice"
|
"NATIVE: test cut"
|
||||||
(assert (= (slice [1 2 3 4 5] 1) [2 3 4 5]))
|
(assert (= (cut [1 2 3 4 5] 1) [2 3 4 5]))
|
||||||
(assert (= (slice [1 2 3 4 5] 1 3) [2 3]))
|
(assert (= (cut [1 2 3 4 5] 1 3) [2 3]))
|
||||||
(assert (= (slice [1 2 3 4 5]) [1 2 3 4 5])))
|
(assert (= (cut [1 2 3 4 5]) [1 2 3 4 5])))
|
||||||
|
|
||||||
|
|
||||||
(defn test-take []
|
(defn test-take []
|
||||||
|
Loading…
Reference in New Issue
Block a user