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
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/>
"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
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.
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.
········@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
········@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
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