如何将填充长度指定为 Guile 格式的参数?

How to specify the padding length as an argument in Guile's format?

Guile 的格式可以填充参数:

(format #f "~5d" 123)  ;; => "  123"

但是如何从参数中读取填充长度?

(format #f "~?d" 5 123)  ;; => "  123"

因为它是由 Bash 的 printf 完成的:

printf "%*d" 5 123  ## => "  123"

如 Guile Reference Manual 中所述,您可以使用 v 参数。

v - The next function argument as the parameter. v stands for “variable”, a parameter can be calculated at runtime and included in the arguments. Upper case V can be used too.

例如:

(format #f "~vd" 5 123)
=> "  123"