guile-srfi-123

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit fb75134f55749f52d57cc691db6a2618b2eb4eaf
parent a6f77aabdfd2d03685b4c5601fc87f41a398d937
Author: Taylan Ulrich Bayırlı/Kammer <taylanbayirli@gmail.com>
Date:   Tue, 18 Aug 2015 10:00:14 +0200

Elaborate register-getter-with-setter! spec.

Diffstat:
Msrfi-123.html | 4++++
Msrfi-123.md | 27+++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/srfi-123.html b/srfi-123.html @@ -105,6 +105,9 @@ struct ;=&gt; #(a (x y #u8(4 2 3)) c)</code></pre> <li><code>(register-getter-with-setter! type getter sparse?)</code> (procedure)</li> </ul> <p>Registers a new type/getter/setter triple for the dynamic dispatch. <code>Type</code> is a type predicate, <code>getter</code> is a procedure that has a setter associated with it, and <code>sparse?</code> is a Boolean indicating whether the type is a sparse type (see <code>ref</code> specification).</p> +<p>The getter will be called with two arguments: the object whose field should be accessed, and an object identifying the field to be accessed. The setter will be called with one additional argument which is the value to be assigned to the given field of the given object.</p> +<p><strong>Warning:</strong> This procedure is strictly meant for when defining a new disjoint type, which isn't already handled by <code>ref</code>. In practice, this means it should only be used with newly defined opaque record types, or types defined with some implementation-specific method which, unlike <code>define-record-type</code>, doesn't automatically register a getter and setter for the type. If any two type predicates registered with the system both return true for any Scheme object, the behavior is undefined. (A custom getter or setter may, however, dispatch to different actions based on some property of the given object, based on the <code>field</code> argument, or based on anything else.)</p> +<p>It is conceivable that this method will become deprecated after a system has been invented which ties together the definition of a new opaque record type with the definitions of its getter and setter. This is considered outside the scope of this SRFI.</p> <h2 id="considerations-when-using-as-a-library">Considerations when using as a library</h2> <p>The intent of this SRFI is to encourage Scheme systems to extend their standard library in accordance with the above specification. On the meanwhile, the reference implementation can be used as a separate library, but certain considerations apply.</p> <p>The <code>define-record-type</code> export of the library conflicts with the one in <code>(scheme base)</code>, so either has to be renamed, or more typically, the one from <code>(scheme base)</code> excluded.</p> @@ -116,6 +119,7 @@ struct ;=&gt; #(a (x y #u8(4 2 3)) c)</code></pre> <p>Thanks to Jorgen Schäfer for inspiring me to write this SRFI and making the initial suggestion for the <code>ref</code> procedure and ternary <code>set!</code> syntax, as well as providing continuous input.</p> <p>The <code>ref*</code> procedure with its <code>~</code> synonym and SRFI-17 setter (which replaced the initially considered ternary <code>set!</code> syntax) seems to have first appeared in Gauche. Thanks to Shiro Kawai: <a href="http://blog.practical-scheme.net/gauche/20100428-shorter-names" class="uri">http://blog.practical-scheme.net/gauche/20100428-shorter-names</a></p> <p>Thanks to Evan Hanson for the idea of using a throw-away <code>define</code> in the expansion of <code>define-record-type</code> so as not to disturb a sequence of internal definitions.</p> +<p>Thanks to Vincent St-Amour, Eli Barzilay, and others in the Racket IRC channel for raising my awareness against action-at-a-distance bugs that might result from abuse of the imperative <code>register-getter-with-setter!</code>.</p> <p>Thanks also to everyone else on the discussion mailing list for their input.</p> <h2 id="copyright-and-license">Copyright and license</h2> <p>Copyright (C) Taylan Ulrich Bayırlı/Kammer (2015). All Rights Reserved.</p> diff --git a/srfi-123.md b/srfi-123.md @@ -225,6 +225,28 @@ Registers a new type/getter/setter triple for the dynamic dispatch. associated with it, and `sparse?` is a Boolean indicating whether the type is a sparse type (see `ref` specification). +The getter will be called with two arguments: the object whose field +should be accessed, and an object identifying the field to be +accessed. The setter will be called with one additional argument +which is the value to be assigned to the given field of the given +object. + +**Warning:** This procedure is strictly meant for when defining a new +disjoint type, which isn't already handled by `ref`. In practice, +this means it should only be used with newly defined opaque record +types, or types defined with some implementation-specific method +which, unlike `define-record-type`, doesn't automatically register a +getter and setter for the type. If any two type predicates registered +with the system both return true for any Scheme object, the behavior +is undefined. (A custom getter or setter may, however, dispatch to +different actions based on some property of the given object, based on +the `field` argument, or based on anything else.) + +It is conceivable that this method will become deprecated after a +system has been invented which ties together the definition of a new +opaque record type with the definitions of its getter and setter. +This is considered outside the scope of this SRFI. + Considerations when using as a library -------------------------------------- @@ -271,6 +293,11 @@ Thanks to Evan Hanson for the idea of using a throw-away `define` in the expansion of `define-record-type` so as not to disturb a sequence of internal definitions. +Thanks to Vincent St-Amour, Eli Barzilay, and others in the Racket IRC +channel for raising my awareness against action-at-a-distance bugs +that might result from abuse of the imperative +`register-getter-with-setter!`. + Thanks also to everyone else on the discussion mailing list for their input.