[plt-scheme] Permutations (newbie)

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sun Sep 17 13:44:35 EDT 2006

1. Please don't post solutions to these problems on the newsgroup.

2. Follow the design recipe. You're obviously not and that explains  
your struggle.
For example, a test is not

  (f 10) ;; test


  (f 10) ;; expect

or even better

  (equal? (f 10) 20)

To become a good programmer, you must learn to develop and compute  
examples first. Contracts, purpose statements, and then make sure  
that your
template is isomorphic to the data definition.

3. HtDP does not teach you Scheme (just a bit) but it teaches you the  
of going from a blank screen and a problem statement to a program in a
systematic manner.

4. Someone who teaches you Scheme (only) may wish to show you loops  
Things like map and filter and so on. And before you know it, he's shown
you how to write permutations in 4 lines of code. And after you stare
long enough at it, you even understand it. But what do you carry
over from that process to Java, for example?

5. One last point. People who assign this problem often just ask
students to write a program that prints all permutations rather than
returning a list (collection) of all permutations. That's a slightly
"easier" problem, for some value of "easier." -- We do not teach
input and output, staying from the usual bad habits you get in a first

Hth -- Matthias

On Sep 17, 2006, at 1:04 PM, Andrew Kesery wrote:

> Hello all,
> Out of curiosity, I'm teaching myself Scheme using HTDP. Chapter 12  
> contains an
> exercise where you're supposed to take a list of symbols and return  
> a list of
> all possible permutations of those symbols.
> After a lot of messing around I've found a way to make it work, but  
> it left me
> feeling it can't be the best solution. It's quite verbose compared  
> to a
> reference implementation I did in Python at a point when I was  
> beginning to
> doubt my intellectual prowess :).
> I'd appreciate feedback regarding possible improvements.

Posted on the users mailing list.