Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to print HyExpression in python?

Tags:

hy

how to print a object HyExpression as

HyExpression([
    HyExpression([
      HySymbol('/'),
      HyInteger(2)]),
    HyExpression([
      HyString('ceil')])])

as

'((/ 2) ("ceil"))'

in console ?

like image 855
Xu Qinghan Avatar asked Mar 27 '26 06:03

Xu Qinghan


1 Answers

ah! I have found the answer and its as follows hy_repr!

just use in .py

from hy.contrib.hy_repr import hy_repr

input_rule_list = '["🚱?" ((/ 2) ("ceil"))]'
expr_input_list = hy.read_str(input_rule_list) #HyExpression 

#do something with this expr

print(hy_repr(expr_rule_parsed))

(cond [((get predicators "🚱?") 🏷) [((/ 2)) (("ceil"))]])

Cool!

like image 53
Xu Qinghan Avatar answered Mar 29 '26 21:03

Xu Qinghan