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

/ WebHome / TOC / NumberChapter / Cookbook.NumberRecipesOpListInts

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

Operating on a Series of Integers

Problem

You want to perform an operation on all integers in a certain range.

Solution

Use the map, foldl, or for-each functions if you have a known list of (possibly non-contiguous) integers. Or, you may be interested in SRFI 42 (Eager List Comprehensions). Otherwise, try a do loop.

For example, to double all entries in a list:

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

Or, to print all even integers less than 71:

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

Or use a boring do loop. For example, to iterate across all integers from 0 to 4:

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

Or, to iterate across all integers from 0 to 71, step 7: 500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

Discussion

The first two methods use a more functional approach to loops.

The following code shows each technique. Here we only print the numbers we generate:

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

The program output looks like: 500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

See Also

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