|
41 | 41 | (-> *interp* |
42 | 42 | .getLocals |
43 | 43 | (.__getitem__ ~(name lib)) |
44 | | - .__dict__))) |
45 | | - (print ~lib)) |
| 44 | + .__dict__)))) |
46 | 45 | ([lib & objects] ; import object from a library |
47 | 46 | (cons 'do |
48 | | - (mapcat |
| 47 | + (map |
49 | 48 | (fn [obj] |
50 | | - `((def ~obj (.__finditem__ ~lib ~(name obj))) |
51 | | - (print ~obj))) |
| 49 | + `(def ~obj (.__finditem__ ~lib ~(name obj)))) |
52 | 50 | objects)))) |
53 | 51 |
|
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 | | - |
63 | 52 | (defmacro py-fn |
64 | 53 | "create a native clojure function applying the python |
65 | 54 | wrapper calls on a python function at the top level of the library |
66 | 55 | use this where lambda is preferred over named function" |
67 | 56 | [lib fun] |
68 | | - `(let [f# (.__finditem__ |
69 | | - ~lib |
| 57 | + `(let [f# (.__finditem__ |
| 58 | + ~lib |
70 | 59 | ~(name fun))] |
71 | 60 | (fn [& args#] |
72 | 61 | (call f# args#)))) |
73 | 62 |
|
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 __ |
75 | 74 | "access attribute of class or attribute of attribute of (and so on) class" |
76 | 75 | ([class attr] |
77 | 76 | `(.__findattr__ ~class ~(name attr))) |
78 | | - ([class attr & more] |
79 | | - `(__ (__ ~class ~attr) ~@more))) |
| 77 | + ([class attr & attrs] |
| 78 | + `(__ (__ ~class ~attr) ~@attrs))) |
80 | 79 |
|
81 | 80 | (defmacro _> |
82 | 81 | "call attribute as a method |
|
102 | 101 |
|
103 | 102 | (defn pyobj-iterate |
104 | 103 | "access 'PyObjectDerived' items as Lazy Seq" |
105 | | - [pyobj] (lazy-seq (.__iter__ pyobj))) |
| 104 | + [pyobj] (lazy-seq (.__iter__ pyobj))) |
106 | 105 |
|
107 | | -(defn- java2py |
| 106 | +(defn java2py |
108 | 107 | "to wrap java objects for input as jython, and unwrap Jython output as java" |
109 | 108 | [args] |
110 | 109 | (into-array |
111 | 110 | org.python.core.PyObject |
112 | | - (map #(.java2py org.python.core.Py %) args))) |
| 111 | + (map #(. org.python.core.Py java2py %) args))) |
113 | 112 |
|
114 | | -(defn- call |
| 113 | +(defn call |
115 | 114 | "The first len(args)-len(keywords) members of args[] |
116 | 115 | are plain arguments. The last len(keywords) arguments |
117 | 116 | are the values of the keyword arguments." |
|
0 commit comments