[R6RS] revised draft of record srfi

Michael Sperber sperber
Thu Jul 28 15:21:44 EDT 2005


dyb at cs.indiana.edu writes:

> I'd be happy with keywords arguments for this procedure if and only
> if we end up adding a keyword argument mechanism to the core language
> (I'd also prefer we not add keyword arguments more generally, but that's
> another issue.)  Again, however, I don't envision humans typing calls
> to this procedure, so I don't think the interface matters overly much.

While I agree, Marc also suggested that constructor invocations might
be keyworded.  I agree that this is useful. However, it can easily be
modelled on top of the current proposal---SRFI 57 (modelled on top of
SRFI 9) has "Labeled record expressions."

Also, SRFI 68 has a `transcoder' record type whose constructor has
keywords for the fields, to allow platform-specific extensions.  The
macro (independent of the record-definition form, or even if it's on
top of records at all) to define keyworded constructors is just a
couple of lines---I've attached the code if anybody's interested.  (It
could probably use polishing; I wrote it in an airport.) That's
exactly how it should be---it allows people to get keyworded
constructors no matter what's underneath, and no matter what form they
used to define a record type.  This would also work for
MAKE-RECORD-TYPE-DESCRIPTOR.

Generally adding Common-Lisp-style keyword arguments to the language
would be a huge change (and one that, like Kent, I'd prefer not to
make), and unnecessary for the purposes of the records proposal.

In any case, this issue is orthogonal to the records, at least in the
present proposal, which makes the formals list to the constructor
explicit---whatever is allowed in the formals list in the core
language will work for the records.

-- 
Cheers =8-} Mike
Friede, V?lkerverst?ndigung und ?berhaupt blabla
-------------- next part --------------
; Helper code for managing options for Comprehensive I/O SRFI

; Copyright (C) Michael Sperber (2005). All Rights Reserved. 
; 
; Permission is hereby granted, free of charge, to any person
; obtaining a copy of this software and associated documentation files
; (the "Software"), to deal in the Software without restriction,
; including without limitation the rights to use, copy, modify, merge,
; publish, distribute, sublicense, and/or sell copies of the Software,
; and to permit persons to whom the Software is furnished to do so,
; subject to the following conditions:
; 
; The above copyright notice and this permission notice shall be
; included in all copies or substantial portions of the Software.
; 
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
; SOFTWARE.

; This gives you an alternative form for constructing records with
; keywords.  Say you have:

; (define-record-type :foo-options
;   (make-foo-options bar baz)
;   foo-options?
;   (bar foo-options-bar)
;   (baz foo-options-baz))

; You can then get a FOO-OPTIONS macro defined for you via:

; (define-options-type foo-options
;   (make-foo-options (bar foo-options-bar)
; 		      (baz foo-options-baz)))

; This allows you to do:

; (foo-options (bar 1) (baz 2))
; or:
; (foo-options (o) (baz 7))

; The latter form expects O to be a record of the same type---it gives
; you a record identical to O except for the BAR field which is 7.

(define unassigned (list 'unassigned))

(define (options-value-unassigned? x)
  (eq? x unassigned))

(define-syntax define-options-type
  (syntax-rules ()
    ((define-options-type ?keyword (?cons ?field ...))
     (define-options-type-helper (?field ...) () ?keyword ?cons))))

(define-syntax define-options-type-helper
  (syntax-rules ()
    ((define-options-type-helper ((?field0 ?accessor0) ?field-data ...) (?helper ...)
       ?keyword ?cons)
     (define-options-type-helper (?field-data ...) (?helper ... (?field0 ?accessor0 helper))
       ?keyword ?cons))
    ((define-options-type-helper () ((?field ?accessor ?helper) ...)
       ?keyword ?cons)
     (begin
       (define-syntax ?helper
	 (syntax-rules (?field)
	   ((?helper ?default (?field ?field-exp) . ?clauses)
	    ?field-exp)
	   ((?helper ?default (?other-field ?field-exp) . ?clauses)
	    (?helper ?default . ?clauses))
	   ((?helper ?default)
	    ?default)))
       ...

       (define-syntax ?keyword
	 (syntax-rules ()
	   ((?keyword (?from) . ?clauses)
	    (let ((from ?from))
	      (?cons (?helper (?accessor from) . ?clauses)
		     ...)))
	   ((?keyword . ?clauses)
	    (?cons (?helper unassigned . ?clauses)
		   ...))))))))


More information about the R6RS mailing list