Skip to content

Share uninterned symbols in *print-circle*#271

Merged
k-okada merged 4 commits intoeuslisp:masterfrom
Affonso-Gui:master
May 24, 2018
Merged

Share uninterned symbols in *print-circle*#271
k-okada merged 4 commits intoeuslisp:masterfrom
Affonso-Gui:master

Conversation

@Affonso-Gui
Copy link
Member

Makes (let ((g (gensym))) (list g g)) print as (#1=#:G824 #1#), when *print-circle* is non-nil. Since this is a dumpable and loadable form, #266 gets solved. (It is also default behavior in clisp and sbcl.)

Can be tested with below code:

(let ((lst (let ((g (gensym))) (list g g)))
      (*print-circle* t))
  (assert
   (reduce #'eq (read-from-string (format nil "~S" lst)))
   "Unable to read uninterned symbol"))

@Affonso-Gui Affonso-Gui closed this Apr 3, 2018
@Affonso-Gui Affonso-Gui reopened this Apr 3, 2018
@k-okada
Copy link
Member

k-okada commented Apr 3, 2018 via email

@k-okada
Copy link
Member

k-okada commented Apr 3, 2018

need to merge #273

@Affonso-Gui
Copy link
Member Author

@inabajsk Please review

@Affonso-Gui
Copy link
Member Author

To give a better explanation of the problem:

Symbols generated by (gensym) cannot be correctly readen from files, creating different objects for the same symbol representation.

(apply #'eq (read-from-string "(#:test #:test)"))
  ;; -> nil

This causes problems e.g. when trying to load hash tables from dumped files, as reported on #266.

In common lisp, this problem is solved by writing files using labeled notation, when *print-circle* is non-nil.

(let* ((g (gensym))
       (lst (list g g))
       (*print-circle* t))
  (format t "~s" lst))
;; -> (#1=#:G966 #1#)

(apply #'eq (read-from-string "(#1=#:G966 #1#)"))
  ;; -> t

This PR takes the same approach as common lisp implementation. It can be tested with the following:

(let ((lst (let ((g (gensym))) (list g g)))
      (*print-circle* t))
  (assert
   (apply #'eq (read-from-string (format nil "~S" lst)))
   "Unable to read uninterned symbol"))

@k-okada
Copy link
Member

k-okada commented Apr 10, 2018

can you put test code into jskeus/irteus/test ?

@Affonso-Gui
Copy link
Member Author

@k-okada added in euslisp/jskeus#501

@Affonso-Gui
Copy link
Member Author

@k-okada ping

@k-okada k-okada merged commit fab69d9 into euslisp:master May 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants