# 2.6 循环结构对象

要在 Lisp 对象中表示共享或循环结构，您可以使用读取器结构 '# n =' 和 '# n #'。

在对象前使用#n= 可以标记这个对象，方便后续引用;这样，您可以在另一个地方引用同一个对象。这里，n是某个整数。例如，这里创建了一个列表，其中第一个元素同时作为第三个元素重复出现：&#x20;

```
(#1=(a) b #1#)
```

这不同于像这样的普通语法

```
((a) b (a))
```

这将导致列表的第一个和第三个元素看起来相似，但不是同一个 Lisp 对象。下面这串代码揭示两者的区别：

```
(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
```

您还可以使用相同的语法来创建一个循环结构，该结构看起来像个克莱因瓶。下面是一个例子：

```
#1=(#1#)
```

这将生成一个列表，其第二个元素是列表本身。您可以通过以下代码看到它确实有效：

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

如果给变量绑定`print-circle` 到非`nil`值，Lisp 打印 可以生成此语法来记录 Lisp 对象中的循环和共享结构。请参阅[输出变量](https://www.gnu.org/software/emacs/manual/html_node/elisp/Output-Variables.html)。\ <br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://emacs-lisp.ivory.cafe/lisp-shu-ju-lei-xing/xun-huan-jie-gou-dui-xiang.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
