[plt-scheme] Multiple loops

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Mar 31 14:04:30 EDT 2009

HtDP shows you how to design programs from scratch for three  
chapters. When a data definition is recursive, so are the functions  
that process its instances.

In chapter 4, HtDP introduces abstractions over this process. For  
linear forms of recursive data, we call them loops. A loop is a  
traversal over some form of data, parameterized over the actions you  
take at each node. While poor languages (Java, Python) support 3 or 4  
loops, Scheme allows you to define your own loops.

So the problem that you were facing in Python would be this in  
chapter HtDP/4:

  #lang scheme
  ;; (Listof Number) (Listof Number) -> (Listof Number)
  (define (*list onel twol) (map * onel twol))

If I misunderstood and you're also summing up the results of the  
multiplications, it would look like this:

  #lang scheme
  ;; (Listof Number) (Listof Number) -> (Listof Number)
  (define (*list onel twol) (apply + (map * onel twol)))

Helps? -- Matthias






On Mar 31, 2009, at 1:29 PM, aditya shukla wrote:

> I am not sure if this is the right question for this forum.but  
> since htdp is helping me to learn program design approach i think i  
> should i ask it.In  chapter 12 HTDP , recursion is used to  
> implement insertion sort this marks the beginning of designing  
> comlex programs.Yesterday i was coding in python and the data  
> structure was a list of lists of numbers where i had to multiple  
> each element of the list with the other elements of the other  
> lists .I tried it using for loops and after a hard time i finally  
> got the solution.My question here is are there loops in scheme or  
> recursion is used in all the cases and is there is a design rule  
> for multiple loops?Any help is appreciated.
>
>
> Aditya
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.