[racket] please help to change vector to list

From: Stephen Bloch (sbloch at adelphi.edu)
Date: Thu Jun 2 10:45:25 EDT 2011

On Jun 2, 2011, at 9:11 AM, Yingjian Ma wrote:

> Here is another question.  In (lambda (ls), it seems ls took the value from v.  How does Racket know not pass x to ls as the argument?

"helper" is defined as "(lambda (ls) ...)"
The only place you call "helper", you give it "(vector->list v)"; you don't pass it x, so it doesn't take x.

>   Does it alway takes the right variable?

No, it always takes what is explicitly passed in as arguments :-)

> Also, I want code to keep all the letters that is not a.  It does not work for
> (test 'a #(b c a b a d)).  The result is '(c b).  If you know how to generalize it, please let me know.

In fact, the program you showed us has quite a number of problems: try
(test 'a #(b))
(test 'a #(a a))
(test 'a #(a b a c))
for example.

I would fix this program by starting over from scratch: the program as it stands is not only buggy but too long and complicated.  My solution, and the one I would expect my beginning students to come up with, is about 140 characters long, not including contract and test cases.

Stephen Bloch
sbloch at adelphi.edu

Posted on the users mailing list.