From: Hyunchul Kim
Subject: why (reverse "aba")  not compliing?
Date: 
Message-ID: <Pine.SOL.3.96L.990301234302.14145A-100000@caesar.phil.cmu.edu>
From a book I saw

 reverse is a function for  sequences, so I believe it is for strings as
well buy when I tried (reverse "aba") in CL, it did not compile and says
"wrong type argument: consp "aba" "

Any explanation?

Thanks.
 - Jay 

From: David B. Lamkins
Subject: Re: why (reverse "aba")  not compliing?
Date: 
Message-ID: <rZKC2.5956$hC.2887486@news1.teleport.com>
In article <·········································@caesar.phil.cmu.edu> ,
Hyunchul Kim <········@andrew.cmu.edu>  wrote:

> From a book I saw
>
>  reverse is a function for  sequences, so I believe it is for strings as
> well buy when I tried (reverse "aba") in CL, it did not compile and says
> "wrong type argument: consp "aba" "
>
> Any explanation?
>
> Thanks.
>  - Jay
>

You're right.  Perhaps your CL implementation is broken.  What CL are you
running?

--
David B. Lamkins <http://www.teleport.com/~dlamkins/>
From: Marco Antoniotti
Subject: Re: why (reverse "aba")  not compliing?
Date: 
Message-ID: <lwww10gs21.fsf@copernico.parades.rm.cnr.it>
"David B. Lamkins" <········@teleport.com> writes:

> In article <·········································@caesar.phil.cmu.edu> ,
> Hyunchul Kim <········@andrew.cmu.edu>  wrote:
> 
> > From a book I saw
> >
> >  reverse is a function for  sequences, so I believe it is for strings as
> > well buy when I tried (reverse "aba") in CL, it did not compile and says
> > "wrong type argument: consp "aba" "
> >
> > Any explanation?
> >
> > Thanks.
> >  - Jay
> >
> 
> You're right.  Perhaps your CL implementation is broken.  What CL are you
> running?

His CL implementation is broken. In CMUCL

* (reverse "abc")
"cba"
* 

-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - (0)6 - 68 10 03 17, fax. +39 - (0)6 - 68 80 79 26
http://www.parades.rm.cnr.it
From: Erik Naggum
Subject: Re: why (reverse "aba")  not compliing?
Date: 
Message-ID: <3129358768479279@naggum.no>
* Hyunchul Kim <········@andrew.cmu.edu>
| From a book I saw reverse is a function for  sequences, so I believe it
| is for strings as well buy when I tried (reverse "aba") in CL, it did not
| compile and says "wrong type argument: consp "aba" "

  it seems that you are using a Lisp that is not Common Lisp at all.  your
  previous problems with MAPCAR look like Emacs Lisp problems, and the
  above error message is also provided by Emacs Lisp.  Emacs Lisp is very
  far from a Common Lisp implementation.  even with the CL package, the
  core functions are still broken, but (require 'cl) does give you MAPCAR*,
  but no REVERSE*.

#:Erik
From: Juanma Barranquero
Subject: Re: why (reverse "aba")  not compliing?
Date: 
Message-ID: <36ddd351.438490035@news.mad.ttd.net>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 02 Mar 1999 10:19:28 +0000, Erik Naggum <····@naggum.no> wrote:

>  but (require 'cl) does give you MAPCAR*,
>  but no REVERSE*.

Not a full implementation, perhaps, but that should be a start for
Hyumchul Kim:

(defun reverse-array (array)
  (let* ((len-array (length array))
         (new-array (typecase array
                        (string (make-string len-array 0))
                        (vector (make-vector len-array 0))
                        (bool-vector (make-bool-vector len-array 0))
                        (t (make-char-table
                                (char-table-subtipe array))))))
    (do ((i 0 (1+ i)))
        ((>= i len-array) new-array)
      (aset new-array i (aref array (- len-array i 1))))))

(defun reverse* (sequence)
  (if (arrayp sequence)
      (reverse-array sequence)
    (reverse sequence)))

(defun nreverse-array (array)
  (let* ((len-array (length array))
         (pivot (/ len-array 2)))
    (do ((i 0 (1+ i)))
        ((>= i pivot) array)
      (rotatef (aref array i) (aref array (- len-array i 1))))))

(defun nreverse* (sequence)
  (if (arrayp sequence)
      (nreverse-array sequence)
    (nreverse sequence)))


                                                       /L/e/k/t/u

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.0.2i

iQA/AwUBNtvINf4C0a0jUw5YEQILsgCgnzF+u1S/tri9ItFvydVPfvdtZoIAoIAw
ZP7E6uymuRwF9Se/uB/MRcWd
=HNOD
-----END PGP SIGNATURE-----
From: Pierpaolo Bernardi
Subject: Re: why (reverse "aba")  not compliing?
Date: 
Message-ID: <920388085.138047@fire-int>
Hyunchul Kim (········@andrew.cmu.edu) wrote:
: From a book I saw

:  reverse is a function for  sequences, so I believe it is for strings as
: well buy when I tried (reverse "aba") in CL, it did not compile and says
: "wrong type argument: consp "aba" "

: Any explanation?

The error message is bogus. 

But note that (reverse "aba") is trying to modify a constant string.
This is not valid common lisp (but probably this is not the problem here). 

P.
From: David B. Lamkins
Subject: Re: why (reverse "aba")  not compliing?
Date: 
Message-ID: <Z5VC2.6687$hC.3134629@news1.teleport.com>
In article <················@fire-int> , ········@cli.di.unipi.it (Pierpaolo
Bernardi) wrote:

> Hyunchul Kim (········@andrew.cmu.edu) wrote:
> : From a book I saw
>
> :  reverse is a function for  sequences, so I believe it is for strings as
> : well buy when I tried (reverse "aba") in CL, it did not compile and says
> : "wrong type argument: consp "aba" "
>
> : Any explanation?
>
> The error message is bogus.
>
> But note that (reverse "aba") is trying to modify a constant string.
> This is not valid common lisp (but probably this is not the problem here).

No.  Reverse is not destructive.  It always creates and returns a new
sequence.

--
David B. Lamkins <http://www.teleport.com/~dlamkins/>

There are many ways to abbreviate something, but only one way not to.
From: Kent M Pitman
Subject: Re: why (reverse "aba")  not compliing?
Date: 
Message-ID: <sfwg17nn766.fsf@world.std.com>
········@cli.di.unipi.it (Pierpaolo Bernardi) writes:

> But note that (reverse "aba") is trying to modify a constant string.
> This is not valid common lisp (but probably this is not the problem here). 

Btw, I can't help noting that "aba" doesn't need reversing.
From: Erik Naggum
Subject: Re: why (reverse "aba")  not compliing?
Date: 
Message-ID: <3129384541422388@naggum.no>
* ········@cli.di.unipi.it (Pierpaolo Bernardi)
| But note that (reverse "aba") is trying to modify a constant string.

  you may be thinking about NREVERSE, not REVERSE.

#:Erik
From: Thomas A. Russ
Subject: Re: why (reverse "aba")  not compliing?
Date: 
Message-ID: <ymi4so3ajsm.fsf@sevak.isi.edu>
········@cli.di.unipi.it (Pierpaolo Bernardi) writes:

> 
> Hyunchul Kim (········@andrew.cmu.edu) wrote:
> : From a book I saw
> 
> :  reverse is a function for  sequences, so I believe it is for strings as
> : well buy when I tried (reverse "aba") in CL, it did not compile and says
> : "wrong type argument: consp "aba" "
> 
> : Any explanation?
> 
> The error message is bogus. 

Yes.  It may indicate the user is not using a full Common Lisp, but
rather a simpler lisp where REVERSE applies only to lists and not to
sequences in general.

> But note that (reverse "aba") is trying to modify a constant string.
> This is not valid common lisp (but probably this is not the problem here). 

Actually, this is valid common lisp, since the constant string is not
modified.  A new sequence is produced.

If it were the destructive version NREVERSE, it would not be valid.

[Actually, a question for Kent Pitman: The hyperspec states that
 "reverse always creates and returns a new sequence".  That would
 imply that an unbelievably clever implementation could not return
 the same sequence given a palindrome: (reverse "aba")]


> 
> P.

-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu    
From: Barry Margolin
Subject: Re: why (reverse "aba")  not compliing?
Date: 
Message-ID: <AXYC2.14$Ey6.1879@burlma1-snr2>
In article <···············@sevak.isi.edu>,
Thomas A. Russ <···@sevak.isi.edu> wrote:
>[Actually, a question for Kent Pitman: The hyperspec states that
> "reverse always creates and returns a new sequence".  That would
> imply that an unbelievably clever implementation could not return
> the same sequence given a palindrome: (reverse "aba")]

That's correct.  If you do:

(setq list1 (list a b a))
(setq list2 (reverse list1))
(setf (car list2) 'c)
(eq (car list1) (car list2)) => NIL

If a "clever" implementation returned the original sequence, this would
return T, which would be incorrect.

Some non-destructive functions are give explicit leeway (or even
requirements) to share structure with the original sequence.  For instance,
APPEND is required to copy all but the last argument, which must be used as
is (the CDR of the copy of the 2nd to last argument should point to it --
this allows the last argument to be an improper list or even a non-list),
and the set functions are allowed to share structure.  However, REVERSE is
not one of these -- it must produce a fresh list, even if it's EQUAL to the
original.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Tim Bradshaw
Subject: Re: why (reverse "aba")  not compliing?
Date: 
Message-ID: <nkjvhgiet8o.fsf@tfeb.org>
···@sevak.isi.edu (Thomas A. Russ) writes:

> [Actually, a question for Kent Pitman: The hyperspec states that
>  "reverse always creates and returns a new sequence".  That would
>  imply that an unbelievably clever implementation could not return
>  the same sequence given a palindrome: (reverse "aba")]

That's right, and that's always what you want.  Otherwise this might not work (or even be legal since it's modifying a constant):

	(setf (aref (reverse "aba") 0) #\d)

--tim