Fwd: [plt-scheme] Re: Permutation correct way to do it ?

From: richard gere (diggerrrrr at gmail.com)
Date: Mon Apr 7 08:38:55 EDT 2008

(missed reply-to all  sorry if you get duplicate message)

Sorry for late response , here is the new definition of both function :


 (define (insert-at-begining a-sym a-word)
  (cons a-sym a-word))


 (define (insert-at-end a-sym a-word)
  (append a-word (cons a-sym empty)))



 >  Let me recommend that you read chapter iv up to page 313 (and end of that
 > section) next.
 >  Then "edit" the above program using the "list abstractions" (map, fold,
 > etc) from
 >  chapter iv. Replace one function at a time, make sure the tests pass before
 > you move on.

 I have read up to  chapter ii . I will follow your advise and skip the
 chapter iii for the moment and  read iv and rewrite this program using
 "list abstractions" . Will come back to you when done.

 I want to thank you for guiding me  , otherwise i don't know how many
 chapters i would have read , and would have still programmed in ad-hoc
 manner ,as my first and second solution shows.

  After following sort example very carefully line by line word by word
 and applying it again to this problem absolutely clears the picture,
 it shows how automatically things follow one after another in a
 orderly sequence. It might be a hindsight but i am pretty confident on
 tackling any problem in a systematic manner .



 Thanks
 Veer









 On Sun, Apr 6, 2008 at 4:01 AM, Matthias Felleisen
<matthias at ccs.neu.edu> wrote:
 > >
 > >
 >
 >  Just a few comments left:
 >
 >
 >
 > > (define (insert-at-begining a-sym a-word)
 > >  (cond
 > >    [(empty? a-word) (cons a-sym empty)]
 > >    [else (cons a-sym a-word) ]))
 > >
 >
 >  True or false: no matter what a-word is (empty? or cons?) the answer is
 > built the same way?
 >
 >
 >
 >
 > > ;;to insert a-sym at the end of a-word
 > > ;;Example : given  'a (cons 'b (cons 'c empty)) -> (cons 'b (cons 'c (cons
 > 'a empty)))
 > > (define (insert-at-end a-sym a-word)
 > >  (cond
 > >    [(empty? a-word) (cons a-sym empty) ]
 > >    [else (append a-word (cons a-sym empty)) ]))
 > >
 >
 >  True or false: no matter what a-word is (empty? or cons?) the answer is
 > built the same way?
 >
 >  Simplify these functions.
 >
 >  ;; ---
 >
 >  Let me recommend that you read chapter iv up to page 313 (and end of that
 > section) next.
 >  Then "edit" the above program using the "list abstractions" (map, fold,
 > etc) from
 >  chapter iv. Replace one function at a time, make sure the tests pass before
 > you move on.
 >  Enjoy the test cases while you're at it and even more the powerful result.
 >
 >  -- Matthias
 >
 >


Posted on the users mailing list.