Skip to content

Instantly share code, notes, and snippets.

@jd
Created April 5, 2013 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jd/5320675 to your computer and use it in GitHub Desktop.
Save jd/5320675 to your computer and use it in GitHub Desktop.
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