Common Lisp setting *print-circle* T causes list compression? - Stack Overflow

(setq *print-circle* T);; then create some list with a large number of items, of which a bunch;; of th

(setq *print-circle* T)

;; then create some list with a large number of items, of which a bunch
;; of them repeat

If you then try to print the list in the repl, you will see a lot of unfamiliar text. Each of your items (in the beginning) will show a #1 or #2, etc, depending on the items location in your list. Where the list repeats itself, instead of the item printing out, you will have a #1# #2#, etc, depending on which item it the list it is a repeat of. This threw me, because I wasn't expecting it. I'm not sure if there is a way to mark a list so it won't do this behaviour when you print the object in the repl.

(setq *print-circle* T)

;; then create some list with a large number of items, of which a bunch
;; of them repeat

If you then try to print the list in the repl, you will see a lot of unfamiliar text. Each of your items (in the beginning) will show a #1 or #2, etc, depending on the items location in your list. Where the list repeats itself, instead of the item printing out, you will have a #1# #2#, etc, depending on which item it the list it is a repeat of. This threw me, because I wasn't expecting it. I'm not sure if there is a way to mark a list so it won't do this behaviour when you print the object in the repl.

Share Improve this question asked Nov 20, 2024 at 1:03 JEPriceJEPrice 7131 gold badge7 silver badges10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Nothing has been modified in the list, just the way it was represented was changed.

The way I worked around it is to defun a function to concatenate the list items in a single string, this forced an expansion of the list items.

(defun join-list-items( list )
  "joins all items in a list as one big string"
  (format nil "~{~a~}" list))

This isn't really a question, more of a warning that "here there be dragons" if you're unfamiliar with how SBCL handles the repl printing of a list that has duplicate items, if print-circle is set.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742387546a4434360.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信