[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Implementing a "write" method for self-evaluating objects (by equal?)

From: divoplade
Subject: Implementing a "write" method for self-evaluating objects (by equal?)
Date: Thu, 17 Sep 2020 22:02:31 +0200
User-agent: Evolution 3.34.2

Hello guile users,

In the manual, I read:

(define-method (write (file <named-file>) port)
  (format port "#<<file> ~s ~a>" (name file) (fd file)))

So it is possible to define a write method for foreign objects (and
more generally GOOPS classes).

My question is: why use such a bizarre syntax with # and <? Would it
not be better to make it self-evaluating:

  (format port "(make <named-file> #:fd ~a #:name ~s)"
    (fd file) (name file))

This is a little more verbose, but at least the syntax explains how to
construct the value. There must be some cases where it would not be
possible (such as pointers to opaque data that do not have a
constructor...), and it would break  if for instance "make" is renamed
to something else. However, if I were to implement a write method, I
would use this, a textual representation of a constructor that would
produce the same value (according to equal?).

reply via email to

[Prev in Thread] Current Thread [Next in Thread]