replace slice with cut

This commit is contained in:
Calem Bendell 2014-09-04 23:29:57 -04:00 committed by Gergely Nagy
parent 9fbd21adba
commit 61e4b9dfed
4 changed files with 21 additions and 21 deletions

View File

@ -1314,9 +1314,9 @@ class HyASTCompiler(object):
col_offset=expr.start_column,
targets=del_targets)
@builds("slice")
@builds("cut")
@checkargs(min=1, max=4)
def compile_slice_expression(self, expr):
def compile_cut_expression(self, expr):
expr.pop(0) # index
val = self.compile(expr.pop(0)) # target
@ -1600,7 +1600,7 @@ class HyASTCompiler(object):
# We then pass the other arguments to the function
expr[0] = HyExpression(
[HySymbol("slice"), tempvar, HyInteger(1)]
[HySymbol("cut"), tempvar, HyInteger(1)]
).replace(expr[0])
ret += self.compile(call)

View File

@ -57,7 +57,7 @@
(defmacro cdr [thing]
"Get all the elements of a thing, except the first"
`(slice ~thing 1))
`(cut ~thing 1))
(defmacro cond [&rest branches]
@ -104,7 +104,7 @@
[(empty? args) `(do ~@body)]
[(= (len args) 2) `(for* [~@args] ~@body)]
[true
(let [[alist (slice args 0 nil 2)]]
(let [[alist (cut args 0 nil 2)]]
`(for* [(, ~@alist) (genexpr (, ~@alist) [~@args])] ~@body))]))
@ -175,7 +175,7 @@
(defmacro defmacro/g! [name args &rest body]
(let [[syms (list (distinct (filter (fn [x] (and (hasattr x "startswith") (.startswith x "g!"))) (flatten body))))]]
`(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))))

View File

@ -291,18 +291,18 @@ def test_ast_bad_get():
cant_compile("(get 1)")
def test_ast_good_slice():
"Make sure AST can compile valid slice"
can_compile("(slice x)")
can_compile("(slice x y)")
can_compile("(slice x y z)")
can_compile("(slice x y z t)")
def test_ast_good_cut():
"Make sure AST can compile valid cut"
can_compile("(cut x)")
can_compile("(cut x y)")
can_compile("(cut x y z)")
can_compile("(cut x y z t)")
def test_ast_bad_slice():
"Make sure AST can't compile invalid slice"
cant_compile("(slice)")
cant_compile("(slice 1 2 3 4 5)")
def test_ast_bad_cut():
"Make sure AST can't compile invalid cut"
cant_compile("(cut)")
cant_compile("(cut 1 2 3 4 5)")
def test_ast_good_take():

View File

@ -536,11 +536,11 @@
(assert (= (car [1 2 3 4 5]) 1)))
(defn test-slice []
"NATIVE: test slice"
(assert (= (slice [1 2 3 4 5] 1) [2 3 4 5]))
(assert (= (slice [1 2 3 4 5] 1 3) [2 3]))
(assert (= (slice [1 2 3 4 5]) [1 2 3 4 5])))
(defn test-cut []
"NATIVE: test cut"
(assert (= (cut [1 2 3 4 5] 1) [2 3 4 5]))
(assert (= (cut [1 2 3 4 5] 1 3) [2 3]))
(assert (= (cut [1 2 3 4 5]) [1 2 3 4 5])))
(defn test-take []