Take the 2-minute tour ×

Let's say that I have a list of lists in Scheme, like so:

 (define a-list  (list (list a b) (list c d) (list e f) (list g h) (list i j)))

How would I go about defining a function that would consume this list such that I could use another function to consume each letter in the list?

For instance, I had another function

(define (smorg a)

So, how do I go about doing smorg a, smorg b, smorg c... ?

share|improve this question
what have you tried? –  cam Sep 15 '11 at 7:13
I'm very new to Scheme (and recursion at that). So far, I've tried bruteforce methods, i.e. smorg(first(first a-list)), smorg(second(first a-list)), etc. I'd just like to automate this process somehow –  arkate Sep 15 '11 at 7:17
add comment

2 Answers

up vote 2 down vote accepted

Be sure you understand what list?, map, car and cdr do. They might be of use.

share|improve this answer
now that I've covered it in class, map actually does seem like the more elegant solution. –  arkate Oct 25 '11 at 8:51
add comment

What textbook are you using?

If the answer is How to Design Programs, then follow the design recipe. In particular, you need a data definition; the data definition is used to generate a template, which tells you exactly how to get the recursion right.

If you're not using HtDP, I highly suggest you give it a read. The book is available online, here: http://www.htdp.org/. Then follow the design recipe. In particular, you need a data definition etc etc etc.

In either case, here's a hint: Never, ever use the list function before you've mastered recursion. Not in your functions, not even in your examples. It gets in your way. Build your lists with cons and empty.

share|improve this answer
add comment

Your Answer


