From: RCM
Subject: Novice learning...Help with these codes plase
Date: 
Message-ID: <m3yalj8yqx.fsf@thehack.anywhere.cc>
	Hi all, i'm as said in the subject learning this interesting programing
language, i'm still with little code, just doing procedures, still not big deal
my questions are:

	First of all i coded this procedure (our-reverse) that reverses a list 
tail-recursively:

;; aux function
(defun our-reverse-aux (l la)
  (cond ((null l) la)
	(t (our-reverse-aux (cdr l) (cons (car l) la)))))

;; take a list and reverse it
(defun our-reverse (l)
  (cond ((or (atom l) (null l)) ())
	(t (our-reverse-aux (cdr l) (car l)))))

	And it seems to work...if i give it for example '(a b c) it gives 
(C B . A)....then i tried the reverse procedure on same list and gives (C B A)
my questions here are Is there a way to make the "." dissapear from the list 
returned by our-reverse-aux??? ...Why does it appear ??


	Thanks for your answers....
-- 
-------------------------------------------------------------------------------
| Rodolfo Conde Mtz                   Universidad Nacional Autonoma de Mexico |
| ICQ      14757500                   Facultad de Ciencias                    |
| e-mails:                            Ciencias de la Computacion              |
| ······@ada.fciencias.unam.mx                                                |
| ············@usa.net                                                        |
-------------------------------------------------------------------------------

From: Johan Kullstam
Subject: Re: Novice learning...Help with these codes plase
Date: 
Message-ID: <m2sobqu5ch.fsf@sophia.axel.nom>
RCM <············@usa.net> writes:

> 	Hi all, i'm as said in the subject learning this interesting programing
> language, i'm still with little code, just doing procedures, still not big deal
> my questions are:
> 
> 	First of all i coded this procedure (our-reverse) that reverses a list 
> tail-recursively:
> 
> ;; aux function
> (defun our-reverse-aux (l la)
>   (cond ((null l) la)
> 	(t (our-reverse-aux (cdr l) (cons (car l) la)))))
> 
> ;; take a list and reverse it
> (defun our-reverse (l)
>   (cond ((or (atom l) (null l)) ())
> 	(t (our-reverse-aux (cdr l) (car l)))))
> 
> 	And it seems to work...if i give it for example '(a b c) it gives 
> (C B . A)....then i tried the reverse procedure on same list and gives (C B A)
> my questions here are Is there a way to make the "." dissapear from the list 
> returned by our-reverse-aux??? ...Why does it appear ??

i see that you may not use reasonable control structures such as
`if'.  however, you can use the full power of the debugger (who would
know?).

for debugging a recursive function, use trace.

USER(5): (trace our-reverse-aux)
(OUR-REVERSE-AUX)
USER(6): (our-reverse '(a b c))
 0: (OUR-REVERSE-AUX (B C) A)
 0: returned (C B . A)
(C B . A)

when you call our-reverse, you are passing a list and an atom -- not
two lists.  in our-reverse, either call our-reverse-aux with the full
list and nil (and get rid of the cond), or wrap the car up in list.
hope this helps.

-- 
                                           J o h a n  K u l l s t a m
                                           [········@ne.mediaone.net]
                                              Don't Fear the Penguin!
From: SLong
Subject: Re: Novice learning...Help with these codes plase
Date: 
Message-ID: <36DB3E51.44F1@isomedia.com>
RCM wrote:
> 
>         Hi all, i'm as said in the subject learning this interesting programing
> language, i'm still with little code, just doing procedures, still not big deal
> my questions are:
> 
>         First of all i coded this procedure (our-reverse) that reverses a list
> tail-recursively:
> 
> ;; aux function
> (defun our-reverse-aux (l la)
>   (cond ((null l) la)
>         (t (our-reverse-aux (cdr l) (cons (car l) la)))))
> 
> ;; take a list and reverse it
> (defun our-reverse (l)
>   (cond ((or (atom l) (null l)) ())
>         (t (our-reverse-aux (cdr l) (car l)))))
> 
>         And it seems to work...if i give it for example '(a b c) it gives
> (C B . A)....then i tried the reverse procedure on same list and gives (C B A)
> my questions here are Is there a way to make the "." dissapear from the list
> returned by our-reverse-aux??? ...Why does it appear ??
> 
>         Thanks for your answers....
> --
> -------------------------------------------------------------------------------
> | Rodolfo Conde Mtz                   Universidad Nacional Autonoma de Mexico |
> | ICQ      14757500                   Facultad de Ciencias                    |
> | e-mails:                            Ciencias de la Computacion              |
> | ······@ada.fciencias.unam.mx                                                |
> | ············@usa.net                                                        |
> -------------------------------------------------------------------------------

...Little dots... it's that business of consing cells together. A
treatment of this is usually at the front of whatever book you are
using. I assume that this was some sort of exercise since there is
already built in nreverse and reverse functions for reversing lists.

sl