s c h e m a t i c s : c o o k b o o k

/ StructureChapter / Cookbook.StructureChapterComments

This Web


WebHome 
WebChanges 
TOC (with recipes)
NewRecipe 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
Sourceforge Page
SchemeWiki.org
Original Cookbook
RSS

Scheme Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
Scheme Cross Reference
PLT Scheme SISC
Scheme48 SCM
MIT Scheme scsh
JScheme Kawa
Chicken Guile
Bigloo Tiny
Gambit LispMe
GaucheChez

Lambda the Ultimate
TWiki.org
Edit this topic to add or edit comments for the associated chapter.

Comments

I object to this egregiously gratuitous PLT-specificness, when it is explicitly stated in the CookbookFAQ page that pages should not be so gratuitously PLT-specific in contexts such as these. Here is the equivalent SRFI 9 page:

Record types represent abstract, opaque data types. A record is an instance of a particular record type. The DEFINE-RECORD-TYPE syntax defines a new record type. An example is likely the easiest way to understand the DEFINE-RECORD-TYPE macro:

(define-record-type pare
  (kons a d)
  pare?
  (a kar)
  (d kdr set-kdr!))

This defines a record type PARE with two fields, A & D. KONS is defined to be a procedure of two arguments, the two fields. PARE? is defined to be a procedure of one argument, a disjoint type predicate for PARE records. KAR extracts the A field from PARE records; KDR extracts the D field. SET-KDR! is defined to be a procedure of two arguments that assigns the D field of its first argument to its second argument. (There is no way to assign the A field of PARE records.) Here is a sample interaction:

> (define p (kons 5 3))
> (pare? p)
#t
> (pare? (cons 5 3))
#f
> (kar p)
5
> (kdr p)
3
> (set-kdr! p 'frobozz)
> (kdr p)
frobozz

-- TaylorCampbell - 30 Aug 2004

-- NoelWelsh - 01 Jul 2004

CookbookForm
TopicType: Comment
ParentTopic: StructureChapter
TopicOrder: 050

 
 
Copyright © 2004 by the contributing authors. All material on the Schematics Cookbook web site is the property of the contributing authors.
The copyright for certain compilations of material taken from this website is held by the SchematicsEditorsGroup - see ContributorAgreement & LGPL.
Other than such compilations, this material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest