Skip to content

Commit d362f65

Browse files
committed
Add (with example) . Fixes issue #156
1 parent 9353b5d commit d362f65

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/libpython_clj2/python.clj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,3 +626,24 @@ user> (py/call-attr inst \"addarg\" 10)
626626
(get-attr parent-mod (module-path-last-string item-path))
627627
(throw (Exception. (format "Failed to find module or class %s"
628628
item-path))))))))
629+
630+
631+
(defmacro def-unpack
632+
"Unpack a set of symbols into a set of defs. Useful when trying to match Python
633+
idioms - this is definitely not idiomatic Clojure.
634+
635+
Example:
636+
637+
```clojure
638+
user> (py/def-unpack [a b c] (py/->py-tuple [1 2 3]))
639+
#'user/c
640+
user> a
641+
1
642+
user> b
643+
2
644+
user> c
645+
3
646+
```"
647+
[symbols input]
648+
`(let [~symbols ~input]
649+
~@(for [s symbols] `(def ~s ~s))))

0 commit comments

Comments
 (0)