From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/elisp/circular-objects.html | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 devdocs/elisp/circular-objects.html (limited to 'devdocs/elisp/circular-objects.html') diff --git a/devdocs/elisp/circular-objects.html b/devdocs/elisp/circular-objects.html new file mode 100644 index 00000000..797d97b1 --- /dev/null +++ b/devdocs/elisp/circular-objects.html @@ -0,0 +1,25 @@ +

Read Syntax for Circular Objects

To represent shared or circular structures within a complex of Lisp objects, you can use the reader constructs ‘#n=’ and ‘#n#’.

Use #n= before an object to label it for later reference; subsequently, you can use #n# to refer the same object in another place. Here, n is some integer. For example, here is how to make a list in which the first element recurs as the third element:

(#1=(a) b #1#)
+
+

This differs from ordinary syntax such as this

((a) b (a))
+
+

which would result in a list whose first and third elements look alike but are not the same Lisp object. This shows the difference:

(prog1 nil
+  (setq x '(#1=(a) b #1#)))
+(eq (nth 0 x) (nth 2 x))
+     ⇒ t
+(setq x '((a) b (a)))
+(eq (nth 0 x) (nth 2 x))
+     ⇒ nil
+
+

You can also use the same syntax to make a circular structure, which appears as an element within itself. Here is an example:

#1=(a #1#)
+
+

This makes a list whose second element is the list itself. Here’s how you can see that it really works:

(prog1 nil
+  (setq x '#1=(a #1#)))
+(eq x (cadr x))
+     ⇒ t
+
+

The Lisp printer can produce this syntax to record circular and shared structure in a Lisp object, if you bind the variable print-circle to a non-nil value. See Output Variables.

+

+ Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc.
Licensed under the GNU GPL license.
+ https://www.gnu.org/software/emacs/manual/html_node/elisp/Circular-Objects.html +

+
-- cgit v1.2.3