Created
April 5, 2013 16:31
-
-
Save jd/5320675 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/hy/compiler.py b/hy/compiler.py | |
index 24ba107..22687ca 100644 | |
--- a/hy/compiler.py | |
+++ b/hy/compiler.py | |
@@ -157,6 +157,19 @@ class HyASTCompiler(object): | |
return self._mangle_branch([branch]) | |
@builds("if") | |
+ def wraps_if_expression(self, expr): | |
+ return ast.Expr( | |
+ value=ast.Lambda( | |
+ lineno=expr.start_line, | |
+ col_offset=expr.start_column, | |
+ args=ast.arguments(args=[], | |
+ defaults=[], | |
+ vararg=None, | |
+ kwargs=None), | |
+ body=self.compile_if_expression(expr)), | |
+ lineno=expr.start_line, | |
+ col_offset=expr.start_column) | |
+ | |
def compile_if_expression(self, expr): | |
expr.pop(0) | |
try: | |
@@ -175,11 +188,11 @@ class HyASTCompiler(object): | |
elif len(expr) > 1: | |
raise TypeError("if expects 2 or 3 arguments, got %d" % (len(expr) + 2)) | |
- return ast.If(test=test, | |
- body=body, | |
- orelse=orel, | |
- lineno=expr.start_line, | |
- col_offset=expr.start_column) | |
+ return ast.IfExp(test=test, | |
+ body=body, | |
+ orelse=orel, | |
+ lineno=expr.start_line, | |
+ col_offset=expr.start_column) | |
@builds("print") | |
def compile_print_expression(self, expr): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment