Fix 'direction' of 'drop' function

This commit is contained in:
John Jacobsen 2013-04-21 15:46:31 -05:00
parent fef571855b
commit f69c6243e8
2 changed files with 3 additions and 12 deletions

View File

@ -697,21 +697,12 @@ class HyASTCompiler(object):
expr.pop(0) expr.pop(0)
n = self.compile(expr.pop(0)) n = self.compile(expr.pop(0))
seq = self.compile(expr.pop(0)) seq = self.compile(expr.pop(0))
zero = ast.Num(n=0,
lineno=expr.start_line,
col_offset=expr.start_column)
upper = ast.UnaryOp(op=ast.USub(),
operand=n,
lineno=expr.start_line,
col_offset=expr.start_column)
if upper.operand.n == 0:
return seq
return ast.Subscript( return ast.Subscript(
lineno=expr.start_line, lineno=expr.start_line,
col_offset=expr.start_column, col_offset=expr.start_column,
value=seq, value=seq,
slice=ast.Slice(lower=zero, slice=ast.Slice(lower=n,
upper=upper, upper=None,
step=None), step=None),
ctx=ast.Load()) ctx=ast.Load())

View File

@ -386,7 +386,7 @@
(defn test-drop [] (defn test-drop []
"NATIVE: test drop" "NATIVE: test drop"
(assert (= (drop 0 [2 3]) [2 3])) (assert (= (drop 0 [2 3]) [2 3]))
(assert (= (drop 1 [2 3]) [2])) (assert (= (drop 1 [2 3]) [3]))
(assert (= (drop 2 [2 3]) []))) (assert (= (drop 2 [2 3]) [])))