guile-devel
[Top][All Lists]
Advanced

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

Re: Functional record "setters", a different approach


From: Ludovic Courtès
Subject: Re: Functional record "setters", a different approach
Date: Thu, 08 Nov 2012 20:09:26 +0100
User-agent: Gnus/5.130005 (Ma Gnus v0.5) Emacs/24.2 (gnu/linux)

Hi Mark!

Mark H Weaver <address@hidden> skribis:

> I've attached a slightly improved functional record "setters" patch.
> The only change since yesterday's version is to the test suite, which
> now includes tests of the compile-time error checking.

Nice, thanks!

It addresses my main concern with the previous version of the patch,
which is that it lacked support for named setters, so that’s great.

At the time you were concerned about the “weight” of these macros.  Are
you just more relaxed now, or do you have a psyntax optimization in the
pipeline?  :-)

> +                          (make-address "Foo" "Paris" "France"))))
> +      (and (equal? (set-fields p
> +                     ((person-email) "address@hidden")
> +                     ((person-address address-country) "Spain")
> +                     ((person-address address-city) "Barcelona"))

The choice of towns seems inaccurate.  ;-)

> +    (pass-if "set-fields with one path as a prefix of another"
> +      (let ()
> +        (define-immutable-record-type foo (make-foo x) foo?
> +          (x foo-x)
> +          (y foo-y set-foo-y)
> +          (z foo-z set-foo-z))
> +
> +        (define-immutable-record-type :bar (make-bar i j) bar?
> +          (i bar-i)
> +          (j bar-j set-bar-j))
> +
> +        (catch 'syntax-error
> +         (lambda ()
> +           (compile '(let ((s (make-bar (make-foo 5) 2)))
> +                       (set-fields s
> +                         ((bar-i foo-x) 1)
> +                         ((bar-i foo-z) 2)
> +                         ((bar-i) 3)))
> +                    #:env (current-module))
> +           #f)
> +         (lambda (key whom what src form subform)
> +           (equal? (list key whom what form subform)
> +                   '(syntax-error set-fields
> +                                  "one field path is a prefix of another"
> +                                  (set-fields s
> +                                    ((bar-i foo-x) 1)
> +                                    ((bar-i foo-z) 2)
> +                                    ((bar-i) 3))
> +                                  (bar-i)))))))))

You might want to use ‘pass-if-equal’ here, for better reporting.

Please commit, I’ll take care of the doc.

Thanks!

Ludo’.




reply via email to

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