Skip to content

Commit 2ff6dcc

Browse files
committed
improve these macros
1 parent ff6ef14 commit 2ff6dcc

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

src/clojure_python/core.clj

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,42 +41,41 @@
4141
(-> *interp*
4242
.getLocals
4343
(.__getitem__ ~(name lib))
44-
.__dict__)))
45-
(print ~lib))
44+
.__dict__))))
4645
([lib & objects] ; import object from a library
4746
(cons 'do
48-
(mapcat
47+
(map
4948
(fn [obj]
50-
`((def ~obj (.__finditem__ ~lib ~(name obj)))
51-
(print ~obj)))
49+
`(def ~obj (.__finditem__ ~lib ~(name obj))))
5250
objects))))
5351

54-
(defmacro import-fn
55-
"this is like import but it defines the imported item
56-
as a native function that applies the python wrapper calls"
57-
([lib fun]
58-
`(def ~fun (py-fn ~lib ~fun)))
59-
([lib fun & more-funs]
60-
`(do (import-fn ~lib ~fun)
61-
(import-fn ~lib ~@more-funs))))
62-
6352
(defmacro py-fn
6453
"create a native clojure function applying the python
6554
wrapper calls on a python function at the top level of the library
6655
use this where lambda is preferred over named function"
6756
[lib fun]
68-
`(let [f# (.__finditem__
69-
~lib
57+
`(let [f# (.__finditem__
58+
~lib
7059
~(name fun))]
7160
(fn [& args#]
7261
(call f# args#))))
7362

74-
(defmacro __
63+
(defmacro import-fn
64+
"this is like import but it defines the imported item
65+
as a native function that applies the python wrapper calls"
66+
[lib fun & funs]
67+
(cons 'do
68+
(map
69+
(fn [fun]
70+
`(def ~fun (py-fn ~lib ~fun)))
71+
(cons fun funs))))
72+
73+
(defmacro __
7574
"access attribute of class or attribute of attribute of (and so on) class"
7675
([class attr]
7776
`(.__findattr__ ~class ~(name attr)))
78-
([class attr & more]
79-
`(__ (__ ~class ~attr) ~@more)))
77+
([class attr & attrs]
78+
`(__ (__ ~class ~attr) ~@attrs)))
8079

8180
(defmacro _>
8281
"call attribute as a method
@@ -102,16 +101,16 @@
102101

103102
(defn pyobj-iterate
104103
"access 'PyObjectDerived' items as Lazy Seq"
105-
[pyobj] (lazy-seq (.__iter__ pyobj)))
104+
[pyobj] (lazy-seq (.__iter__ pyobj)))
106105

107-
(defn- java2py
106+
(defn java2py
108107
"to wrap java objects for input as jython, and unwrap Jython output as java"
109108
[args]
110109
(into-array
111110
org.python.core.PyObject
112-
(map #(.java2py org.python.core.Py %) args)))
111+
(map #(. org.python.core.Py java2py %) args)))
113112

114-
(defn- call
113+
(defn call
115114
"The first len(args)-len(keywords) members of args[]
116115
are plain arguments. The last len(keywords) arguments
117116
are the values of the keyword arguments."

0 commit comments

Comments
 (0)