Skip to content

Commit 1c7a55f

Browse files
committed
better way of writing this macro
1 parent 1bf379e commit 1c7a55f

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

project.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
(defproject clojure-python "0.1.0"
1+
(defproject clojure-python "0.1.1"
22
:description "Improve seamlessness of Clojure Jython interop."
33
:dependencies [[org.clojure/clojure "1.3.0"]
44
[org.python/jython-standalone "2.5.2"]]
5-
:dev-dependencies [[midje "1.3.0-RC4"]]
5+
:dev-dependencies [[midje "1.3.0"]]
66
:main clojure-python.core)

src/clojure_python/core.clj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@
3434
if multiple arguments are given, the first is assumed
3535
to be a library that has been imported,
3636
and the others are objects to import from this library"
37-
([] nil)
3837
([lib] ; import a library
3938
`(do (.exec *interp* (str "import " ~(name lib)))
4039
(def ~lib
4140
(-> *interp*
4241
.getLocals
4342
(.__getitem__ ~(name lib))
44-
.__dict__))
45-
(print ~lib)))
46-
([lib object] ; import object from a library
47-
`(do (def ~object (.__finditem__ ~lib ~(name object)))
48-
(print ~object)))
49-
([lib object & more-objects] ; import multiple objects
50-
`(do (py-import ~lib ~object)
51-
(py-import ~lib ~@more-objects))))
43+
.__dict__)))
44+
(print ~lib))
45+
([lib & objects] ; import object from a library
46+
(cons 'do
47+
(mapcat
48+
(fn [obj]
49+
`((def ~obj (.__finditem__ ~lib ~(name obj)))
50+
(print ~obj)))
51+
objects))))
5252

5353
(defmacro import-fn
5454
"this is like import but it defines the imported item

0 commit comments

Comments
 (0)