通用Lisp库用于漂亮印刷?例如漂亮打印嵌套哈希表 [英] Common Lisp Library for Pretty Printing? e.g. pretty print a nested hash table
本文介绍了通用Lisp库用于漂亮印刷?例如漂亮打印嵌套哈希表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是普通的Lisp新手。是否有一个CL库可用于漂亮的打印集合(在我的情况下是嵌套哈希表)?
I am new to common lisp. Is there a CL library to pretty print collections, in my case, nested hash tables?
推荐答案
如果您考虑自己编写,则可以使用打印对象。它不是实现独立的对象,但至少在LispWorks和SBCL中有效。
If you consider writing it yourself here is a starting point using print-object. It is not implementation independend, but this works at least in LispWorks and SBCL.
(defmethod print-object ((object hash-table) stream)
(format stream "#HASH{~{~{(~a : ~a)~}~^ ~}}"
(loop for key being the hash-keys of object
using (hash-value value)
collect (list key value))))
这篇关于通用Lisp库用于漂亮印刷?例如漂亮打印嵌套哈希表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文