[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Scheme] Few basics...
From: |
Michael Käppler |
Subject: |
[Scheme] Few basics... |
Date: |
Fri, 21 Nov 2008 19:46:12 +0100 |
User-agent: |
Thunderbird 2.0.0.12 (X11/20071114) |
Scheme hackers,
following simple code extract:
(define testlist (list 0 1 2 3 4 5 6 7))
(define (addlist i nr)
(cons (list-ref testlist i) (if (= (+ i 1) nr) '() (addlist (+ i 1) nr)))
)
(display (addlist 0 3))
The procedure addlist returns all list elements up to the element
>before< that whose index is given through the second argument.
I. The source list is now defined globally. How can I pass it to the
procedure "addlist" without carrying it along through all instances of
the recursion?
II. I assume also the index number ("nr") doesn't has to be passed to
addlist every recursion stage. How to achieve this?
I'd be happy about any advice!
Cheers,
Michael
- [Scheme] Few basics...,
Michael Käppler <=