Skip to content
This repository has been archived by the owner on May 27, 2022. It is now read-only.

print as last expression fails in notebook #16

Open
actsasgeek opened this issue Jun 13, 2015 · 3 comments
Open

print as last expression fails in notebook #16

actsasgeek opened this issue Jun 13, 2015 · 3 comments

Comments

@actsasgeek
Copy link

If you use print as the last expression in an s-expression:

(let [[a 1]]
  (print a))

You get the following error:

 File "<ipython-input-12-d8822250c158>", line 3
    return print(a)
               ^
SyntaxError: invalid syntax

Looking at the generated python, I can see why it is an error but because it works in the Hy REPL so I imagine it has something to do with the way Hy has been interfaced to the expectations of the notebook. Because the notebook only prints the return value of the last expression executed, using print statements for everything you want to see is a common pattern.

Thanks!

There is a bit of a kludge for now...

(let [[a 1] [b 2]
  (print a)
  None)
@bollwyvl
Copy link
Owner

Would probably work with python3, as print is a function. You could

From future import print_function

Or rather

(Import [future print_function])

Or whatever it would be in hy.

On 17:22, Sat, Jun 13, 2015 Steve Butcher [email protected] wrote:

If you use print as the last expression in an s-expression:

(let [[a 1]](print a))

You get the following error:

File "", line 3
return print(a)
^
SyntaxError: invalid syntax

Looking at the generated python, I can see why it is an error but
because it works in the Hy REPL so I imagine it has something to do with
the way Hy has been interfaced to the expectations of the notebook. Because
the notebook only prints the return value of the last expression executed,
using print statements for everything you want to see is a common pattern.

Thanks!

There is a bit of a kludge for now...

(let [[a 1] [b 2](print a)
None)


Reply to this email directly or view it on GitHub
#16.

@bollwyvl
Copy link
Owner

Just had a chance to try this out: indeed, running a hy_kernel backed by python3 works, no problem.

with hy backed by py2, this works:

(import [__future__ [print_function]])
(let [[a 1]]
  (print a))

How the hy repl makes the magic happen without the future is more of the dark AST arts that I am trying to avoid digging into. Until I figure out a way to solve some of those issues, crazy things like print and input will continue to be obnoxious. Hope the workaround helps!

@actsasgeek
Copy link
Author

thanks!

(but the dark arts are so much fun!)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants