Skip to content

tekacs/hy-clojure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hy-clojure

Wrap Python from Clojure via Hy using the excellent libpython-clj (JNA)

For those who would like Python interop but would prefer to write using (some) editor support or without giving up on Lisp syntax. :)

With this pattern, from Clojure you can write Hy code inside a macro and have it run in a Python VM:

(require '[hy-clojure.core :refer [hy!]])

(hy! (do (import pickle) (pickle.dumps [1 2 3])))
;; => b'\x80\x03]q\x00(K\x01K\x02K\x03e.'

In order to stop your IDE from raising issues, you can quote your Hy code. You can also use Python libraries trivially.

(require '[hy-clojure.core :refer [hyq!]])

(hyq!
 '(do (import spacy)
      (setv nlp (.load spacy "en_core_web_sm"))
      (setv text "Hello, world!")
      (nlp text)))

TODO

  • [easy] Allow the caller to pass locals the Hy interpreter
  • [easy] Add tests
  • [medium] Allow inline substitution of variables into Hy forms in the macro:
    (let [clj# "clojure!"] (hy! (print clj#)))
  • [???] Support sending reader macros to hy via the macro

About

Wrap Python from Clojure via Hy using libpython-clj (JNA)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published