Grupos de Google ya no admite nuevas publicaciones ni suscripciones de Usenet. El contenido anterior sigue siendo visible.

why (reverse "aba") not compliing?

Visto 10 veces
Saltar al primer mensaje no leído

Hyunchul Kim

no leída,
1 mar 1999, 3:00:001/3/99
a
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


David B. Lamkins

no leída,
1 mar 1999, 3:00:001/3/99
a
In article <Pine.SOL.3.96L.99030...@caesar.phil.cmu.edu> ,
Hyunchul Kim <hyun...@andrew.cmu.edu> wrote:

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

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

Marco Antoniotti

no leída,
2 mar 1999, 3:00:002/3/99
a

"David B. Lamkins" <dlam...@teleport.com> writes:

> In article <Pine.SOL.3.96L.99030...@caesar.phil.cmu.edu> ,
> Hyunchul Kim <hyun...@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

Erik Naggum

no leída,
2 mar 1999, 3:00:002/3/99
a
* Hyunchul Kim <hyun...@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

Juanma Barranquero

no leída,
2 mar 1999, 3:00:002/3/99
a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 02 Mar 1999 10:19:28 +0000, Erik Naggum <er...@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-----


Pierpaolo Bernardi

no leída,
2 mar 1999, 3:00:002/3/99
a
Hyunchul Kim (hyun...@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.

David B. Lamkins

no leída,
2 mar 1999, 3:00:002/3/99
a
In article <920388085.138047@fire-int> , bern...@cli.di.unipi.it (Pierpaolo
Bernardi) wrote:

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

There are many ways to abbreviate something, but only one way not to.

Kent M Pitman

no leída,
2 mar 1999, 3:00:002/3/99
a
bern...@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.

Erik Naggum

no leída,
2 mar 1999, 3:00:002/3/99
a
* bern...@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

Pierpaolo Bernardi

no leída,
2 mar 1999, 3:00:002/3/99
a Paul Dietz

On Tue, 2 Mar 1999, Paul Dietz wrote:

> REVERSE doesn't modify anything -- NREVERSE does.

OOPS.

Thank you.

P.


Thomas A. Russ

no leída,
2 mar 1999, 3:00:002/3/99
a
bern...@cli.di.unipi.it (Pierpaolo Bernardi) writes:

>
> Hyunchul Kim (hyun...@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 t...@isi.edu

Barry Margolin

no leída,
2 mar 1999, 3:00:002/3/99
a
In article <ymi4so3...@sevak.isi.edu>,

Thomas A. Russ <t...@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, bar...@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.

Tim Bradshaw

no leída,
3 mar 1999, 3:00:003/3/99
a
t...@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


0 mensajes nuevos