gpt4 book ai didi

common-lisp - 普通口齿不清 : how to display a dot?

转载 作者:行者123 更新时间:2023-12-02 09:28:03 25 4
gpt4 key购买 nike

我想使用点 (.) 作为符号,例如 ab

我发现我可以通过引用和转义点来做到这一点。然而,当点显示在屏幕上时,它被竖线包围:

'\.
=> |.|

如何在没有竖线的情况下显示点?

更新:谢谢 jkiiski,使用 format 效果很好。这就是我这样做的原因:为了我自己的教育,我编写了一个函数来将列表表示法中的列表转换为点表示法中的等效列表。感谢您的帮助,现在它运行良好:

(defun list-notation-to-dot-notation (lst)
(cond ((atom lst) lst)
((null (cdr lst)) (list (list-notation-to-dot-notation (car lst)) '\. 'NIL))
(t (list (list-notation-to-dot-notation (car lst)) '\. (list-notation-to-dot-notation (cdr lst))))))

(defun list-2-dot (lst)
(format t "~a" (list-notation-to-dot-notation lst)))

(list-2-dot '(a))
=> (A . NIL)

(list-2-dot '(a b))
=> (A . (B . NIL))

(list-2-dot '((a) b))
=> ((A . NIL) . (B . NIL))

(list-2-dot '(a (b) c))
=> (A . ((B . NIL) . (C . NIL)))

(list-2-dot '(a b (c)))
=> (A . (B . ((C . NIL) . NIL)))

(list-2-dot '((a) (b) (c)))
=> ((A . NIL) . ((B . NIL) . ((C . NIL) . NIL)))

最佳答案

这将是获得相同结果的更简洁的方法:

(defun print-dot-notation (list &optional (stream *standard-output*))
(if (atom list)
(format stream "~s" list)
(format stream "(~a . ~a)"
(print-dot-notation (car list) nil)
(print-dot-notation (cdr list) nil))))

(print-dot-notation '(a (b) c))
; (A . ((B . NIL) . (C . NIL)))

无需创建额外的列表或为点使用符号。

关于common-lisp - 普通口齿不清 : how to display a dot?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35959849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com