1
votes

I'm using GOOPS in Guile Scheme 2.2.3. If I have code like:

(use-modules (oop goops))

(define-class <vec3> ()
  (e0 #:init-value 0.0 #:init-keyword #:e0)
  (e1 #:init-value 0.0 #:init-keyword #:e1)
  (e2 #:init-value 0.0 #:init-keyword #:e2))

(define (make-point x y z)
  (make <vec3> #:e0 x #:e1 y #:e2 z))

When I use (make-point) in the REPL and ask for the value returned it looks something like this:

scheme@(guile-user)> (define p0 (make-point 1 2 3))
scheme@(guile-user)> p0
$1 = #<<vec3> 556b26c087b0>

Is there some way I can override the object printing used by the Guile REPL so I can print the fields of p0 (say) nicely?

1

1 Answers

2
votes

It seems Guile GOOPS provides primitive generic method of display and write. So all what you need to do is specializing them.

Reference: https://www.gnu.org/software/guile/manual/html_node/GOOPS-Object-Miscellany.html#GOOPS-Object-Miscellany

Using this, you can write write something like this:

(define-method (write (o <vec3>) out) 
    (display "#<vec3 " out)
    (display (slot-ref o 'e0) out)
    (display ">" out)
    (newline out))

NOTE: Guile's REPL uses write procedure to print the evaluation result.

The same goes display.