unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: Mark H Weaver <mhw@netris.org>
Cc: guile-devel@gnu.org
Subject: Re: Functional record "setters", a different approach
Date: Fri, 13 Apr 2012 17:41:02 +0200	[thread overview]
Message-ID: <874nsn1vxt.fsf@gnu.org> (raw)
In-Reply-To: <87vcl475qs.fsf@netris.org> (Mark H. Weaver's message of "Thu, 12 Apr 2012 21:58:03 -0400")

Hi Mark!

And Happy Friday, as our friend would say.  :-)

Mark H Weaver <mhw@netris.org> skribis:

> ludo@gnu.org (Ludovic Courtès) writes:
>> Mark H Weaver <mhw@netris.org> skribis:
>>> ludo@gnu.org (Ludovic Courtès) writes:
>>>> I’d still want named single-field setters, for convenience.  For that,
>>>> we probably still need a separate ‘define-immutable-record-type’.
>>>
>>> Agreed.
>>
>> Cool!  Could you integrate it somehow, along with the tests I provided?
>
> Will do.

Thanks!

>>> However, I find the term 'set' misleading, since no mutation is taking
>>> place.  Maybe 'update'?  I dunno, I don't have strong feelings on this.
>>
>> I don’t find ‘set’ misleading because there’s no exclamation mark, and
>> because it’s conceptually about setting a field’s value.  WDYT?
>
> Okay, on second thought I'm inclined to agree.  'set' is a good choice.

[...]

> What do you think?

I’d say ‘set-fields’, no?

(There are actually two common conventions: one is TYPE-METHOD, as in
‘vector-ref’, and another is VERB-NAME, as is ‘make-list’, ‘let-values’.
I tend to prefer the latter, but sometimes the former is more convenient
or clearer.)

[...]

>> Would these checks be alleviated by Andy’s work on peval “predicates”?
>
> Unfortunately, no.  The 'vtable' field of a struct is a mutable field,
> and in fact when a GOOPS class is redefined, the 'vtable' field of
> instances are modified.  This means that it is not safe for the compiler
> to eliminate redundant calls to 'struct-vtable'.

Oh, OK.  That is eviiiil.

>>> For example, for (modified-copy s ((foo-x) 'new)) where 's' contains 10
>>> fields, the expanded code would include 9 separate checks that 's' is
>>> the right type.
>>
>> Couldn’t ‘modified-copy’ be implemented differently so that there’s only
>> one check?  That seems like the most obvious (not necessarily the
>> easiest) way to address the problem.
>
> Yes, and that's exactly what I did.  However, I was only able to
> accomplish this by essentially hacking up my own '<getter>-nocheck'.
>
> If I had used the normal getters in the expansion of 'modified-copy',
> then (modified-copy s ((foo-x) 'new)) would expand to:
>
>   (make-struct <foo> 0
>     (foo-q s) (foo-r s) (foo-s s) (foo-t s) (foo-u s)
>     (foo-v s) (foo-w s) 'new      (foo-y s) (foo-z s))
>
> and each of those getter uses would include a type-check in their
> expansions.  As you suggested, I instead wrap a single check around the
> whole thing and then effectively use (foo-*-nocheck s) instead, by using
> 'struct-ref' directly.
>
> This example is intended to convince you that 'nocheck' variants of
> struct accessors are important as a base upon which to build efficient
> higher-level constructs, at least for our own internal use.

I view it as an important “implementation detail”, but not as an API to
be exposed publicly.

What about keeping it private until we find an actual use case where it
is required outside of (srfi srfi-9)?

Thanks!

Ludo’.



  reply	other threads:[~2012-04-13 15:41 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-11  6:59 Functional record "setters", a different approach Mark H Weaver
2012-04-11  7:57 ` Mark H Weaver
2012-04-11  8:20   ` Mark H Weaver
2012-04-11 22:27     ` Ludovic Courtès
2012-04-11 22:22 ` Ludovic Courtès
2012-04-12 15:04   ` Mark H Weaver
2012-04-12 16:45     ` Thien-Thi Nguyen
2012-04-12 19:58     ` Ludovic Courtès
2012-04-13  1:58       ` Mark H Weaver
2012-04-13 15:41         ` Ludovic Courtès [this message]
2012-04-13 17:26           ` Mark H Weaver
2012-05-07 16:34         ` Ludovic Courtès
2012-05-14 22:25           ` Mark H Weaver
2012-05-15 21:23             ` Ludovic Courtès
2012-11-07 20:04 ` Mark H Weaver
2012-11-08  5:15   ` Mark H Weaver
2012-11-08 19:09     ` Ludovic Courtès
2012-11-09  3:54       ` Mark H Weaver
2012-11-10 16:28         ` Ludovic Courtès
2012-11-10 19:03           ` Mark H Weaver
2012-11-10 21:40             ` Ludovic Courtès
2012-11-10  4:13       ` 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=874nsn1vxt.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guile-devel@gnu.org \
    --cc=mhw@netris.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).