Implement the (and) function
The function takes at least two arguments, and turns it into a pythonic and statement, which returns the last True-ish value, or False. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
This commit is contained in:
parent
3cc165545d
commit
f03b538787
@ -546,6 +546,18 @@ class HyASTCompiler(object):
|
|||||||
lineno=operator.start_line,
|
lineno=operator.start_line,
|
||||||
col_offset=operator.start_column)
|
col_offset=operator.start_column)
|
||||||
|
|
||||||
|
@builds("and")
|
||||||
|
@checkargs(min=2)
|
||||||
|
def compile_and_operator(self, expression):
|
||||||
|
operator = expression.pop(0)
|
||||||
|
values = []
|
||||||
|
for child in expression:
|
||||||
|
values.append (self.compile(child))
|
||||||
|
return ast.BoolOp(op=ast.And(),
|
||||||
|
lineno=operator.start_line,
|
||||||
|
col_offset=operator.start_column,
|
||||||
|
values=values)
|
||||||
|
|
||||||
@builds("=")
|
@builds("=")
|
||||||
@builds("!=")
|
@builds("!=")
|
||||||
@builds("<")
|
@builds("<")
|
||||||
|
@ -406,6 +406,13 @@
|
|||||||
(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))))
|
||||||
|
|
||||||
; FEATURE: native hy-eval
|
; FEATURE: native hy-eval
|
||||||
;
|
;
|
||||||
; - related to bug #64
|
; - related to bug #64
|
||||||
|
Loading…
x
Reference in New Issue
Block a user