【问题标题】:How to specify the padding length as an argument in Guile's format?如何将填充长度指定为 Guile 格式的参数?
【发布时间】:2018-03-04 13:13:04
【问题描述】:

Guile 的格式可以填充参数:

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

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

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

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

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

【问题讨论】:

    标签: scheme guile


    【解决方案1】:

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

    v - 下一个函数参数作为参数。 v 代表“变量”,参数可以在运行时计算并包含在参数中。也可以使用大写V。

    例如:

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

    【讨论】:

    • 只见树木不见森林。
    猜你喜欢
    • 2010-09-16
    • 1970-01-01
    • 2021-11-30
    • 2020-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-13
    相关资源
    最近更新 更多