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

/ StructureIntroduction / Cookbook.SRFI9

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

SRFI 9 - Defining Record Types

SRFI 9 provides a way to define new record types. For each record type a predicate, a constructor, and field accessors and modifiers are defined. The new record types are distinct from all existing types.

The builtin record types in PLT is called structures, which in some circumstances are more flexible than srfi9-records, but are less portable across implementations.

The srfi documentation is available both at http://srfi.schemers.org/srfi-9/srfi-9.html and in the HelpDesk.

Requiring srfi 9

To use srfi9 in PLT Scheme use the following:

(require (lib "9.ss" "srfi"))

Example

> (require (lib "9.ss" "srfi"))
> (define-record-type :user
      (make-user name password)
      user?
      (name user-name set-user-name!)
      (password user-password set-user-password!))
> (define guest (make-user "Anonymous" "1234"))
> (user? guest)
#t
> (user-name guest)
"Anonymous"
> (set-user-name! guest "Guest")
> (user-name guest)
"Guest"

CookbookForm
TopicType: Recipe
ParentTopic:
TopicOrder:

 
 
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