On Fri, Apr 26, 2019 at 09:11:02AM +0000, EfraimVagner wrote: > Hi, > > I've started to work on a small project for fun in scheme, and I wanted to > use a class for one thing. I saw that there is the coops extension, that does > what I want, but my problem is that when printing an object i get > #<coops-instance>. I saw I can use describe-object to get a better > description of the object. Another thing that I would like to have, is that > in sbcl, for example (I think any common lisp implementation acts the same), > when using defstruct, the printed version of the new object can be used to > create another object. For example: > > (defstruct point x y) > > (make-point :x 1 :y 2) ;; Will print #S(POINT :X 1 :Y 2) > > (setq p1 #S(POINT :X 10 :Y 0)) ;; p1 will be a point with x=10 and y=0 > > I don't like the way it works in scheme because it looses the symmetry of > lisp. My question is then, how can I restore the symmetry? (btw, I'm using > chicken scheme if it matters)
Hi Efraim, You can define a custom record printer using define-record-printer: https://wiki.call-cc.org/man/5/Module%20(chicken%20base)#define-record-printer The example here also uses define-reader-ctor to read back the record. If you prefer custom read syntax like in Common Lisp, you could also use set-[sharp-]read-syntax! from (chicken read-syntax): http://wiki.call-cc.org/man/5/Module%20(chicken%20read-syntax)#set-read-syntax I think you should also be able to define custom read syntax for coops instances as well. Hope this helps, Peter
signature.asc
Description: PGP signature
_______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users