unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: divoplade <d@divoplade.fr>
To: guile-user@gnu.org
Subject: Implementing a "write" method for self-evaluating objects (by equal?)
Date: Thu, 17 Sep 2020 22:02:31 +0200	[thread overview]
Message-ID: <fd973471cc3bd6213552dc6bba725982eb1c54d5.camel@divoplade.fr> (raw)

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	other threads:[~2020-09-17 20:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-17 20:02 divoplade [this message]
2020-09-17 20:17 ` Implementing a "write" method for self-evaluating objects (by equal?) John Cowan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fd973471cc3bd6213552dc6bba725982eb1c54d5.camel@divoplade.fr \
    --to=d@divoplade.fr \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).