Hy <-> Python interop
By importing Hy, you can use Hy directly from Python!If you save the following in greetings.hy:
(defn greet [name] (print "hello from hy," name))
import hy
import greetings
greetings.greet("Foo")
If you save the following in greetings.py in Python:
def greet(name):
print("hello, %s" % (name))
(import greetings)
(.greet greetings "foo")
def greet(name, title="Sir"):
print("Greetings, %s %s" % (title,name))
and then in Hy:
(import greetings)
(.greet greetings "Foo")
(.greet greetings "Foo" "Darth")
(apply (. greetings greet) ["Foo"] {"title" "Lord"})
Greetings, Sir Foo
Greetings, Darth Foo
Greetings, Lord Foo
No comments:
Post a Comment