Skip to content
This repository
Browse code

Allow use of deref as a value in a doseq binding

  • Loading branch information...
commit bae0a3dc41392bfe39e3424832c5cdd16af9f85b 1 parent e0e3a5e
Hugo Duncan authored November 22, 2012
11  src/pallet/stevedore/bash.clj
@@ -51,6 +51,10 @@
51 51
       '> "\\>"
52 52
       '= "=="})
53 53
 
  54
+(def ^{:dynamic true :private true
  55
+       :doc "Control output of delimiters on sequences"}
  56
+  *delimited-sequence* true)
  57
+
54 58
 ;; Helper functions for generating shFlags declarations
55 59
 ;; and initializations
56 60
 
@@ -265,7 +269,9 @@
265 269
   "")
266 270
 
267 271
 (defmethod emit [::bash clojure.lang.IPersistentVector] [expr]
268  
-  (str "(" (string/join " " (map emit expr)) ")"))
  272
+  (str (if *delimited-sequence* "(" "")
  273
+       (string/join " " (map emit expr))
  274
+       (if *delimited-sequence* ")" "")))
269 275
 
270 276
 (defmethod emit [::bash clojure.lang.IPersistentMap] [expr]
271 277
   (letfn [(subscript-assign
@@ -388,7 +394,8 @@
388 394
 
389 395
 (defmethod emit-special [::bash 'doseq]
390 396
   [type [ doseq [arg values] & exprs]]
391  
-  (str "for " (emit arg) " in " (string/join " " (map emit values))
  397
+  (str "for " (emit arg)
  398
+       " in " (binding [*delimited-sequence* false] (emit values))
392 399
        "; do\n"
393 400
        (emit-do exprs)
394 401
        "done"))
4  test/pallet/stevedore/bash_test.clj
@@ -220,7 +220,9 @@
220 220
 
221 221
 (deftest test-doseq
222 222
   (is (= "for X in 1 2 3; do\nsomething ${X}\ndone"
223  
-         (script (doseq [X [1 2 3]] (something @X))))))
  223
+         (script (doseq [X [1 2 3]] (something @X)))))
  224
+  (is (= "for X in $(ls); do\nsomething ${X}\ndone"
  225
+         (script (doseq [X @(ls)] (something @X))))))
224 226
 
225 227
 
226 228
 (deftest test-map

0 notes on commit bae0a3d

Please sign in to comment.
Something went wrong with that request. Please try again.