[racket] please help to change vector to list

From: Yingjian Ma (yingjian.ma1955 at gmail.com)
Date: Thu Jun 2 09:11:14 EDT 2011

Hi Jos and ALL,

The code is from website


I modified it.  It is not about homework.  I am learning and evaluating

I use Language: racket; memory limit: 128 MB in DrRacket.

The error I get is

> (test 'a '(b a c a))
. . procedure application: expected procedure, given: '(b a c a) (no

I found the problem.  I should use

helper v


 helper (v)

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?  Does it
alway takes the right variable?  What happens if the first lambda has 3
parameters and the 2nd lambda has 2 parameters?

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

Thanks a lot.

On Thu, Jun 2, 2011 at 4:10 AM, Jos Koot <jos.koot at telefonica.net> wrote:

>  Whast you describe seems correct.
> How about showing me yoyur code after deleting vector->list?
> If this is HOMEWORK, send it OFF LIST.
> What language did you use?
> Jos
>  ------------------------------
> *From:* users-bounces at racket-lang.org [mailto:
> users-bounces at racket-lang.org] *On Behalf Of *Yingjian Ma
> *Sent:* 02 June 2011 08:45
> *To:* users at racket-lang.org
> *Subject:* [racket] please help to change vector to list
>   Hi ALL,
> I have this code
> (define test
>   (lambda (x v)
>     (define helper
>       (lambda (ls)
>         (cond
>           ((empty? ls) '())
>           ((empty? (rest ls)) '())
>           ((equal? (second ls) x) (cons (first ls) (helper (rest
> ls))))
>           (else (helper (rest ls))))))
>    (helper (vector->list v))))
> When I run it with
> > (test 'a #(b a c a))
> it returns
> '(b c)
> Is there a way to use the list such as (test 'a '(b a c a))?  I tried to
> delete vector->list from the last line of the code, but it did not work.
> Why?
> Thanks a lot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110602/ceb36e83/attachment.html>

Posted on the users mailing list.