diff --git a/hy/compiler.py b/hy/compiler.py index cd00530..f3ddb81 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -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) diff --git a/hy/core/macros.hy b/hy/core/macros.hy index b0c06db..30e1f56 100644 --- a/hy/core/macros.hy +++ b/hy/core/macros.hy @@ -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)))) diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index 7ef5451..0931840 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -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(): diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index 352ecf5..d70410a 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -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 []