[racket] please help to change vector to list
Hi Jos and ALL,
The code is from website
http://stackoverflow.com/questions/4175626/scheme-recursion-error
I modified it. It is not about homework. I am learning and evaluating
Racket.
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
arguments)
I found the problem. I should use
helper v
not
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
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.
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>