PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, September 18, 2022

[FIXED] How to print showing shared structure?

 September 18, 2022     common-lisp, printing, sbcl, slime     No comments   

Issue

As an example, the two expressions evaluated below have the same "printed" representation, namely ((A) (A)), but they have very different internal structure. Here the structure is shared:

* (let ((item '(a))) (list item item))
((A) (A))

Here each (a) is a distinct entity:

* '((a) (a))
((A) (A))

Specifically, the value of the first expression is a two-element list were the two elements are identical; the value of the second expression is also a two-element list, but its two elements are distinct (i.e. not identical).

How can I represent these two values in a way that makes this difference in their internal structures more apparent?


Solution

What you are looking for is *print-circle*:

* (setq *print-circle* t)
T
* '((a) (a))
((A) (A))
* (let ((item '(a))) (list item item))
(#1=(A) #1#)

If you want "print - read consistency", you should investigate *print-readably* and with-standard-io-syntax:

(equal (read-from-string (with-standard-io-syntax (write-to-string x)))
       x)

should either return T or signal an error of type print-not-readable.



Answered By - sds
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing