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

/ Cookbook.PatternMatchingIntroduction

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

Introduction

Scheme provides powerful pattern matching facilities, through libraries such match.ss and plt-match.ss.

Pattern matching in Scheme is based around a paper by Duba and Wright entitled "Pattern Matching for Scheme". The essence of pattern matching is to establish a set of rules in the form

(pattern expression)

Where pattern is a pattern that you're attempting to match and expression is the code that should be executed on a successful match. In general, you can view pattern matching as being similar to regular expressions, but acting on S-expressions instead of text strings. As in Regular Expressions, patterns allow you to bind parts of the pattern to variables that can be used in the expression part. Unlike (most) regular expression systems, patterns can be used to do things like

1. Match against the fields of a struct. 1. Match based on the result of evaluating an expression. 1. Use quasiquoting to make pattern templates.

Pattern matching is useful in handling markup (HTML or XML translated to S-Expressions), dispatching functions, and analyzing Scheme code, among other tasks.

CookbookForm
TopicType: Section
ParentTopic: PatternMatchingChapter
TopicOrder: 010

 
 
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