Saving CLOS objects

痴心易碎 提交于 2019-12-02 03:59:59

问题


Saving any Common Lisp structure object to a file (readably) seems relatively straightforward with something like

(defun save-structure-object (object filename)
  (with-open-file (stream filename :direction :output
                                   :if-exists :supersede)
    (with-standard-io-syntax (print object stream))))

For a CLOS object instance, however, the post at Make clos objects printable in lisp indicates a more complex recipe.

First, does the comment about closer-mop relate to a simpler approach to saving a clos class instance?

And second, is the code offered there presented as a general utility for printing any clos instance?


回答1:


Closer to MOP allows one to avoid the dangerous tangle of read-time conditionals in the post you refer to. Generally speaking, using an OOTB solution that many people use is safer than a random ad hoc hack - your own or someone else's.

Before closer-mop was around, I wrote my own CLOS/MOP compatibility layer and CLOS object i/o. I suggest that you use it instead of the code in the SO answer you reference.



来源:https://stackoverflow.com/questions/42334222/saving-clos-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!