Merge branch 'f/and-and-or' of git://github.com/algernon/hy into pr-79

This commit is contained in:
Paul R. Tagliamonte 2013-04-07 18:15:54 -04:00
commit 3f84da8771
2 changed files with 31 additions and 0 deletions

View File

@ -546,6 +546,21 @@ class HyASTCompiler(object):
lineno=operator.start_line, lineno=operator.start_line,
col_offset=operator.start_column) col_offset=operator.start_column)
@builds("and")
@builds("or")
@checkargs(min=2)
def compile_logical_or_and_and_operator(self, expression):
ops = {"and": ast.And,
"or": ast.Or}
operator = expression.pop(0)
values = []
for child in expression:
values.append (self.compile(child))
return ast.BoolOp(op=ops[operator](),
lineno=operator.start_line,
col_offset=operator.start_column,
values=values)
@builds("=") @builds("=")
@builds("!=") @builds("!=")
@builds("<") @builds("<")

View File

@ -406,6 +406,22 @@
(assert (= -_- "what?")))) (assert (= -_- "what?"))))
(defn test-and []
"NATIVE: test the and function"
(let [[and123 (and 1 2 3)]
[and-false (and 1 False 3)]]
(assert (= and123 3))
(assert (= and-false False))))
(defn test-or []
"NATIVE: test the or function"
(let [[or-all-true (or 1 2 3 True "string")]
[or-some-true (or False "hello")]
[or-none-true (or False False)]]
(assert (= or-all-true 1))
(assert (= or-some-true "hello"))
(assert (= or-none-true False))))
; FEATURE: native hy-eval ; FEATURE: native hy-eval
; ;
; - related to bug #64 ; - related to bug #64