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

/ Cookbook.ListChapter

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

List Recipes

Introduction

Being a flavor of Lisp (LISt Processing), Scheme contains lists as a low-level feature of the language. Unfortunately, the standard set of tools for handling lists is relatively minimal. Consequently, scheme programmers are well advised to become familiar with SRFI 1.

Lists are ordered collections of values. They may contain any data type, and are extremely cheap to extend by adding new elements. However, their very nature makes traversing the list have a cost proportional to the number of elements in the list. As the list grows, the cost to access an element takes more time.

Lists are created using either the constructor list, or the list syntax:

> '(a b c)
(a b c)
> (list 'a 'b 'c)
(a b c)

Lists can also be constructed using the ancient Lisp primitive cons, and can be broken apart using the car and cdr functions.

> (define a (list 1 2 3 4 5))
> (define b (cons 5 4))
> (define c (cons 5 '()))
> a
(1 2 3 4 5)
> b
(5 . 4)
> c
(5)
> (car a)
1
> (cdr a)
(2 3 4 5)

This section provide a variety of recipes for efficient list handling.

Recipes

References

ToDo: Links to R5RS, SRFI1, list.ss in mzlib. HTDP on list recipes



CookbookForm
TopicType: Chapter
ParentTopic: TOC
TopicOrder: 07

 
 
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