For Programmers: Free Programming Magazines  


Home > Archive > Scheme > April 2006 > loop action with scheme









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author loop action with scheme
isaac2004

2006-04-07, 7:04 pm

hi im new to scheme and was wondering if it is possible to create a
looping action with scheme. say the prompt is entered something like
this
(make-list 7 '())
this asks the to create a list with 7 of () so something like this
(() () () () () () ())
how would you go about making a scheme function to create this action

Thomas Hafner

2006-04-07, 7:04 pm

"isaac2004" <isaac_2004@yahoo.com> wrote/schrieb <1144452780.481277.87260@i40g2000cwc.googlegroups.com>:

> how would you go about making a scheme function to create this action


(define (make-list n el)
(let loop ((n n) (a '()))
(if (< 0 n)
(loop (- n 1) (cons el a))
a)))
Jens Axel Søgaard

2006-04-07, 7:04 pm

isaac2004 wrote:
> hi im new to scheme and was wondering if it is possible to create a
> looping action with scheme. say the prompt is entered something like
> this
> (make-list 7 '())
> this asks the to create a list with 7 of () so something like this
> (() () () () () () ())
> how would you go about making a scheme function to create this action


See

<http://schemecookbook.org/view/Cook...opingConstructs>

--
Jens Axel Søgaard
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com