unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: ludo@gnu.org (Ludovic Courtès)
Cc: guile-devel@gnu.org
Subject: Re: Functional record “setters”
Date: Mon, 09 Apr 2012 11:55:47 -0700	[thread overview]
Message-ID: <87ty0s91l8.fsf@pobox.com> (raw)
In-Reply-To: <871unxhi74.fsf@gnu.org> ("Ludovic Courtès"'s message of "Mon, 09 Apr 2012 02:17:35 +0200")

On Sun 08 Apr 2012 17:17, ludo@gnu.org (Ludovic Courtès) writes:

> I’d like to apply these patches and associated documentation in
> stable-2.0.  Thoughts?

Looks great to me.  A couple of thoughts:

> +                  (define-inlinable (modifier s val)
> +                    (if (eq? (struct-vtable s) #,type-name)
> +                        (struct-set! s index val)
> +                        (throw 'wrong-type-arg 'modifier
> +                               "Wrong type argument: ~S" (list s)
> +                               (list s)))))))))

Any better abstraction here?  It can be a big win to just pass the
vtable to some function, because you avoid emitting code and constants.
(It will be nice to start to elide some of these checks in the
optimizer...)

E.g. (throw-bad-struct s 'modifier).  Same for the getter.  ("Getter"
and "setter" are better names IMO, because of other uses of the name
"accessor" in Guile.)

Perhaps not germane to your patch, but hey :)

>      (syntax-case x ()
> -      ((_ type-name constructor-spec predicate-name field-spec ...)
> +      ((_ immutable? type-name constructor-spec predicate-name
> +          field-spec ...)

I realize this is an internal macro, but it would be nice to support
keywords (#:immutable), possibly without arguments...

> +;; Import (srfi srfi-9)'s private module, so we can use the private
> +;; `%define-record-type' macro.
> +(eval-when (compile eval load)
> +  (module-use! (current-module) (resolve-module '(srfi srfi-9))))

Why not just use (@@ (srfi srfi-9) %define-record-type) ?

>   (%define-record-type)[functional-accessors]: Mimic `define-inlinable',
>   but add support for (ACCESSOR obj val), when `%reveal-setter' allows
>   it.

This is confusing naming.  Functional setters?  Surely getters are
already functional.

I find the set-fields interface a bit strange, FWIW.  Are you happy with
it, or do you think it could be better?  If you think it's really the
thing to do, OK.

OK those were more comments than I intended!

Peace,

Andy
-- 
http://wingolog.org/



  reply	other threads:[~2012-04-09 18:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-09  0:17 Functional record “setters” Ludovic Courtès
2012-04-09 18:55 ` Andy Wingo [this message]
2012-04-09 21:00   ` Ludovic Courtès
2012-04-10  1:19     ` Noah Lavine
2012-04-10  9:55       ` Ludovic Courtès
2012-04-10 14:18         ` Mark H Weaver
2012-04-10 14:27           ` Ludovic Courtès
2012-04-10 14:37             ` Noah Lavine
2012-04-10 15:15             ` Mark H Weaver

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=87ty0s91l8.fsf@pobox.com \
    --to=wingo@pobox.com \
    --cc=guile-devel@gnu.org \
    --cc=ludo@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).