Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Trying to make my own reverse function
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Nils M Holm  
View profile  
 More options Sep 25 2012, 1:08 pm
Newsgroups: comp.lang.lisp
From: Nils M Holm <news2...@t3x.org>
Date: 25 Sep 2012 17:08:47 GMT
Local: Tues, Sep 25 2012 1:08 pm
Subject: Re: Trying to make my own reverse function
Yves S. Garret <yoursurrogate...@gmail.com> wrote:

> ================================================
> (defun custom-reverse(list-to-reverse)
>   (if (equal (cdr list-to-reverse) nil)
>       (car list-to-reverse)
>       (cons (custom-reverse (cdr list-to-reverse))
>             (cons (car list-to-reverse) nil))))
> ================================================

> Now, it doesn't work.  At least not very well.  The problem is
> what should I return from the method?  Also, and I could be wrong,
> but is it possible to make a reverse method using car, cdr and cons?

Okay, here are a few hints.

- How do you reverse an empty list?

- How do you reverse a non-empty list?

- Fill in the missing parts:

  (DEFUN R (L)
    (IF (NULL L)
        reverse-empty-list
        reverse-non-empty-list))

- You will get extra points for not using APPEND.

BTW:

- (EQUAL X NIL)  equals  (NULL X)

- (CONS X NIL)   equals  (LIST X)

--
Nils M Holm  < n m h @ t 3 x . o r g >  www.t3x.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.