This cannot be done using sprintf (because then you would have to propagate the arguments explicitly. However, you can use kprintf which takes a continuation as the first argument::let p format = Printf.kprintf (fun s -> "This was: " + s) format以格式化的字符串调用延续,因此您可以在返回之前对结果字符串进行任何所需的操作.The continuation is called with the formatted string and so you can do whatever you need with the resulting string before returning. 编辑:要回答您的扩展问题,诀窍是将所有其他工作放到续篇中: To answer your extended question, the trick is to put all the additional work into the continuation:let q format = let cont z = // Some work with formatted string printf "%s" z Printf.kprintf cont format 这篇关于神奇的sprintf函数-如何包装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-03 18:24