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

/ Cookbook.ListRecipeExtractingSublist

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

Extracting a sublist

Problem

Given a list, extract a segment specified by a start and an end index (exclusive).

Solution

500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

This uses the take and drop functions from SRFI 1. The function take takes the first n elements from a list, while drop takes everything after the first n elements. So you can see that we're dropping start elements from the front of the list and taking {- end start) elements from that result.

Example usage: 500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

Discussion

A call to sublist will a return a newly allocated list holding the elements of the given segment.

The function sublist! will alter the given list, and will therefore not allocate a new list.

Note: The sublist function corrresponds to using the slice operator in Python.

-- GordonWeakliem - 29 Apr 2004, JensAxelSoegaard - 12 May 2004

Comments

I rewrote the text to use the language of SRFI1?, i.e. using "sublist" instead of "slice".

-- JensAxelSoegaard - 13 May 2004

CookbookForm
TopicType: Recipe
ParentTopic: ListRecipeSection?
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