Permalink
Browse files

Allow use of deref as a value in a doseq binding

  • Loading branch information...
1 parent e0e3a5e commit bae0a3dc41392bfe39e3424832c5cdd16af9f85b @hugoduncan hugoduncan committed Nov 22, 2012
Showing with 12 additions and 3 deletions.
  1. +9 −2 src/pallet/stevedore/bash.clj
  2. +3 −1 test/pallet/stevedore/bash_test.clj
@@ -51,6 +51,10 @@
'> "\\>"
'= "=="})
+(def ^{:dynamic true :private true
+ :doc "Control output of delimiters on sequences"}
+ *delimited-sequence* true)
+
;; Helper functions for generating shFlags declarations
;; and initializations
@@ -265,7 +269,9 @@
"")
(defmethod emit [::bash clojure.lang.IPersistentVector] [expr]
- (str "(" (string/join " " (map emit expr)) ")"))
+ (str (if *delimited-sequence* "(" "")
+ (string/join " " (map emit expr))
+ (if *delimited-sequence* ")" "")))
(defmethod emit [::bash clojure.lang.IPersistentMap] [expr]
(letfn [(subscript-assign
@@ -388,7 +394,8 @@
(defmethod emit-special [::bash 'doseq]
[type [ doseq [arg values] & exprs]]
- (str "for " (emit arg) " in " (string/join " " (map emit values))
+ (str "for " (emit arg)
+ " in " (binding [*delimited-sequence* false] (emit values))
"; do\n"
(emit-do exprs)
"done"))
@@ -220,7 +220,9 @@
(deftest test-doseq
(is (= "for X in 1 2 3; do\nsomething ${X}\ndone"
- (script (doseq [X [1 2 3]] (something @X))))))
+ (script (doseq [X [1 2 3]] (something @X)))))
+ (is (= "for X in $(ls); do\nsomething ${X}\ndone"
+ (script (doseq [X @(ls)] (something @X))))))
(deftest test-map

0 comments on commit bae0a3d

Please sign in to comment.