如何通过调用格式替换?

时间:2017-02-02 19:49:09

标签: clojure

我有一个功能

(defn f-test [c-width] (format "%-(c-width)s" "boogey"))

当我尝试评估它时会发生这种情况

(f-test 10)

FormatFlagsConversionMismatchException Conversion = c, Flags = (  java.util.Formatter$FormatSpecifier.failMismatch (Formatter.java:4041)

但这就是我要做的事情

(format "%-10s" "boogey")

"boogey    "

如何在格式调用中替换c-width?

1 个答案:

答案 0 :(得分:2)

试试这个:

(defn f-test 
  [c-width] 
  (format (str "%-" c-width "s") "boogey"))