C++ fmt: GitHub - fmtlib/fmt: A modern formatting library
Rust format!: format in std - Rust
可惜功能还是差很多,尤其是最想要的数字格式化功能。
相关主题:
这个 f-string
在我边报错:
不清楚什么情况……我刚刚试了一下,我这里是可以用的。
f-string
展开后:
(macroexpand '(f-string "${username -30s}${somevar 1.2f}"))
;; =>
;; (s-format "${username -30s}${somevar 1.2f}" 'aget
;; (list
;; (cons "username -30s"
;; (format
;; (format "%%%s"
;; (if (string= "-30s" "")
;; (if s-lex-value-as-lisp "S" "s")
;; "-30s"))
;; (symbol-value
;; (intern "username")))) ;; <---
;; (cons "somevar 1.2f"
;; (format
;; (format "%%%s"
;; (if (string= "1.2f" "")
;; (if s-lex-value-as-lisp "S" "s")
;; "1.2f"))
;; (symbol-value
;; (intern "somevar"))))))
报错的就是 (symbol-value (intern "usernam"))
,抽出来放在 emacs -Q
下测试:
⋊> emacs --batch --eval "\
(let ((username \"John Kitchin\"))
(symbol-value (intern \"username\")))"
Error: void-variable (username)
mapbacktrace(#[1028 "!!!!B5@!A5!!!" [princ " " prin1 "(" " (" " " ")
"] 7 "
(fn EVALD FUNC ARGS FLAGS)"])
debug-early-backtrace()
debug-early(error (void-variable username))
symbol-value(username)
(let ((username "John Kitchin")) (symbol-value (intern "username")))
eval((let ((username "John Kitchin")) (symbol-value (intern "username"))) t)
command-line-1(("--eval" "(let ((username \"John Kitchin\"))
(symbol-value (intern \"username\")))"))
command-line()
normal-top-level()
Symbol’s value as variable is void: username
Emacs | Test result |
---|---|
25.1 | |
26.1 | |
27.1 | |
28.1 | |
29.0 |
我猜跟《 Emacs 变严格了? 》的原因类似,Emacs 27 开始对 let 变量做了某些限制。
我用的是Emacs 29。刚才用emacs -q
测试了一下,在文件里C-x C-e
的话可以正常运行,但是M-:
来evaluate这段代码的话就会报你这个错。感觉很神奇。