0

I would like to convert the following to Hy, but I can't seem to figure out how to do it; is there perhaps a way to convert a string of python code to the hy syntax? I don't know if py would work because the evaluated result of f_back may not be safe.

import ast, inspect
def test(f_back):
    return ast.literal_eval(f"inspect.currentframe(){'.f_back' * f_back}")
ShadowRylander
  • 361
  • 2
  • 8

1 Answers1

1

You could always evaluate x = x.f_back repeatedly in a loop instead of using metaprogramming for this.

To address the more general question, Hy itself only implements the Hy-to-Python direction, not Python to Hy. There's Hikaru Ikuta's py2hy, which doesn't work with recent releases of Hy, but he's recently talked about updating it, so that may change soon.

Kodiologist
  • 2,984
  • 18
  • 33