[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: two elementary questions
From: |
Alejandro Forero Cuervo |
Subject: |
Re: two elementary questions |
Date: |
Wed, 12 Dec 2001 09:22:25 -0500 |
User-agent: |
Mutt/1.2.5i |
2. I've been doing the exercises in a learning-scheme book, and
one is to implement the "list" function. What is wrong here?
(define (list . x)
(cond
((null? x) '())
((null? (cdr x)) x)
(else (cons (car x) (ll (cdr x))))))
(list 1 2 3 4) => (1 (2 3 4)), but I want (1 2 3 4).
I guess you mean "ll" where you said "list" in the code above.
Anyway.
You are defining your ll function to accept an unespecified number of
arguments as a list. The following table attempts to explain what
ll'll (heh) see depending on the way you call it:
Call: Value of x:
(ll 1 2 3 4) (1 2 3 4)
(ll whatever) (whatever)
(ll (2 3 4)) ((2 3 4))
(ll) ()
In your first call, (ll 1 2 3 4), ll receives the list (1 2 3 4) as
its argument. However, in your second (recursive) call, you are doing
(ll (2 3 4)) so it receives ((2 3 4)) rather than (2 3 4).
This is easy to fix but I guess telling you how to would spoil the fun
of the excersise. ;)
Good luck.
Alejo.
http://bachue.com/alejo
--
The mere formulation of a problem is far more essential than its solution.
-- Albert Einstein.
$0='!/sfldbi!yjoV0msfQ!sfiupob!utvK'x44;print map{("\e[7m \e[0m",chr ord
(chop$0)-1)[$_].("\n")[++$i%77]}split//,unpack'B*',pack'H*',($F='F'x19).
"F0F3E0607879CC1E0F0F339F3FF399C666733333CCF87F99E6133999999E67CFFCCF3".
"219CC1CCC033E7E660198CCE4E66798303873CCE60F3387$F"#Don't you love Perl?
pgpmKtYiPUHke.pgp
Description: PGP signature