>From 72affff0142374f8be0bf5fcfdab14dae921bc33 Mon Sep 17 00:00:00 2001 From: Alaric Snell-Pym Date: Sun, 20 Nov 2011 20:15:58 +0000 Subject: [PATCH] Clarified the define-record documentation I hope it's a clarification, at least. I found the original definition a bit terse for my tastes. --- manual/Non-standard macros and special forms | 32 +++++++++++++++++++++----- 1 files changed, 26 insertions(+), 6 deletions(-) diff --git a/manual/Non-standard macros and special forms b/manual/Non-standard macros and special forms index 8a94264..c686554 100644 --- a/manual/Non-standard macros and special forms +++ b/manual/Non-standard macros and special forms @@ -385,10 +385,17 @@ Equivalent to: (define-record NAME SLOTNAME ...) -Defines a record type. Call {{make-NAME}} to create an instance -of the structure (with one initialization-argument for each slot). +Defines a record type. This defines a number of procedures for +creating, accessing, and modifying record members. + +Call {{make-NAME}} to create an instance +of the structure (with one initialization-argument for each slot, in +the listed order). + {{(NAME? STRUCT)}} tests any object for being an instance of this -structure. Slots are accessed via {{(NAME-SLOTNAME STRUCT)}} +structure. + +Slots are accessed via {{(NAME-SLOTNAME STRUCT)}} and updated using {{(NAME-SLOTNAME-set!}} {{STRUCT}} {{VALUE)}}. @@ -400,13 +407,26 @@ and updated using {{(NAME-SLOTNAME-set!}} {{STRUCT}} {{VALUE)}}. (point-y p1) ==> 99 +===== SRFI-17 setters + {{SLOTNAME}} may alternatively also be of the form (setter SLOTNAME) -In this case the slot can be read with {{(NAME-SLOTNAME STRUCT)}} -and written with {{(set! (NAME-SLOTNAME STRUCT) VALUE)}} (the slot-accessor -has an associated SRFI-17 "setter" procedure). +In this case the slot can be read with {{(NAME-SLOTNAME STRUCT)}} as usual, +and modified with {{(set! (NAME-SLOTNAME STRUCT) VALUE)}} (the slot-accessor +has an associated SRFI-17 "setter" procedure) instead of +the usual {{(NAME-SLOTNAME-set!}} {{STRUCT}} {{VALUE)}}. + + + +(define-record point (setter x) (setter y)) +(define p1 (make-point 123 456)) +(point? p1) ==> #t +(point-x p1) ==> 123 +(set! (point-y p1) 99) +(point-y p1) ==> 99 + ==== define-record-type -- 1.7.4.1