Skip to content

Instantly share code, notes, and snippets.

@jd jd/gist:5320675
Created Apr 5, 2013

Embed
What would you like to do?
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
You can’t perform that action at this time.