((41.#1=(2.#2=(3))) (14.#1#) (12.#2#) (12.#2#) (12.34)) in xyzzy does not appear in the normal list.

Asked 2 years ago, Updated 2 years ago, 90 views

I created this kind of code, but the results were not in the normal list.

 (defunins(xfs)
  (cons
   (append f(cons xs))
   (if(nulls)
       nil
     (ins x
          (reverse(cons(cars)(reverse f)))
          (cdrs)))

Results:

 (ins4nil'(123))
((4 1 . #1=(2 . #2=(3))) (1 4 . #1#) (1 2 4 . #2#) (1 2 3 4))

When I ran the same code in emacs, there was no problem.

 (ins4nil'(123))
((4 1 2 3) (1 4 2 3) (1 2 4 3) (1 2 3 4))

Can xyzzy produce the same results as emacs?

emacs common-lisp lisp xyzzy

2022-09-29 22:09

1 Answers

#1=#1# indicates that Common Lisp is referring to the same data.
xyzzy is about 60% compliant with Common Lisp, but with Common Lisp, you can disable the display of shared structures by setting *print-circle* to nil.

 (setq*print-circle*nil)

(ins4nil'(123))
→ ((4 1 2 3) (1 4 2 3) (1 2 4 3) (1 2 3 4))

However, after trying the above with xyzy, it seems that this setting does not take effect (bug?)

In this case, the contents of the data output by ins remain the same, since it only clearly states that they share the same cell data.

((41.#1=(2.#2=(3))))(14.#1#)(124.#2#)(1234))
       '((4 1 2 3) (1 4 2 3) (1 2 4 3) (1 2 3 4)))
→ t

If you change your mind and decide not to share the structure (you create new ones every time instead of reusing them), naturally the shared structure will no longer be displayed.

 (defunins(xfs)
  (cons
   (append(copy-tree f)(cons x(copy-tree)))
   (if(nulls)
       nil
       (ins x
            (reverse(cons(cars)(reverse f)))
            (cdrs)))
(ins4'(a)(b)(c))'(123(4))))
→ ((a)(b)(c) 4 1 2 3 (4))
   ((a) (b) (c) 1 4 2 3 (4))
   ((a) (b) (c) 1 2 4 3 (4))
   ((a) (b) (c) 1 2 3 4 (4)))
   ((a) (b) (c) 1 2 3 (4) 4)

In the above section, copy-tree deep copies the list f and s.


2022-09-29 22:09

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.