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

Small modification

This page is part of the web mail archives of SRFI 9 from before July 7th, 2015. The new archives for SRFI 9 contain all messages, not just those from before July 7th, 2015.



I am strongly in favor of Richard's proposal. Being syntax, it gives enough
static information to allows compilers to provide efficient implementations of
records. However, it doesn't build in particular naming conventions. It's the
right policy/mechanism split -- others can build particular record packages on
top of this low-level system, since it is completely neutral with respect to
naming conventions.

When Kent Dybvig described his record proposal at the ICFP Scheme workshop
in Baltimore, I actually wrote up a naming-neutral counterproposal to
Kent's system which is almost exactly what Richard has proposed. My proposal
had two smalldifferences, which I'll put forth for consideration.

First, put the field-spec's in their own list. That is, don't write this

    (define-record-type :ship
      (make-ship size name)	; No speed parameter.
      ship?
      (size  ship-size set-ship-size!)		; Settable
      (name  ship-name)				; Not settable
      (speed ship-speed set-ship-speed!))	; Settable

Instead, write this:

    (define-record-type :ship
      (make-ship size name)	; No speed parameter.
      ship?
      ((size  ship-size set-ship-size!)		; Settable
       (name  ship-name)			; Not settable
       (speed ship-speed set-ship-speed!)))	; Settable

This allows future SRFIs to extend this SRFI's syntax with extra items,
such as Dybvig's meta-programming hooks, or "method definitions"
for generic operations such as printing or disclosing. For example,
one might want an extension such as

    (define-record-type :ship
      (make-ship size name)			; No speed parameter.

      ship?

      ((size  ship-size set-ship-size!)		; Settable
       (name  ship-name)			; Not settable
       (speed ship-speed set-ship-speed!))	; Settable

      ;; This method is used to print ship records
      ((display self port) (display "#{ship " port)
                           (display (ship-name self) port)
			   (display "}" port)))

Second, Dybvig's old higher-level proposal had one extra field, an
identifier field, which was a value that was put into the record
type descriptor for use by the introspection facilities (e.g., the
debugger). I allowed for this in my proposal, so you wrote
    
    (define-record-type ship :ship
      (make-ship size name)
      ...)

The "ship" symbol appearing as the first form was the identifier field.
This is not ultra-important, but I thought I'd throw it out.
    -Olin