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

unexpected function behavior

Visto 0 veces
Saltar al primer mensaje no leído

joa...@arti.vub.ac.be

no leída,
12 abr 2002, 9:11:2212/4/02
a

Try the following ('=>' is the lisp prompt):

=> (defun unexptected (a)
(let ((v #(128)))
(incf v 2)))
UNEXPTECTED

and call the function more then one time:

=> (unexptected)
130
=> (unexptected)
132

Is this intended??

When you replace the #(128) expression with (vector 128) the strange
behavior is gone and the function always returns 130.

Joachim.

Dr. Edmund Weitz

no leída,
12 abr 2002, 9:37:0712/4/02
a
joa...@arti.vub.ac.be writes:

You are modifying a literal. The consequences of this are undefined
according to the CLHS.

See also
<http://www-2.cs.cmu.edu/Groups/AI/html/faqs/lang/lisp/part3/faq-doc-14.html>.

Edi.

--

Dr. Edmund Weitz
Hamburg
Germany

The Common Lisp Cookbook
<http://cl-cookbook.sourceforge.net/>

Nicolas Neuss

no leída,
12 abr 2002, 9:19:5012/4/02
a
joa...@arti.vub.ac.be writes:

Modification of constant expressions leads to unspecified behavior.

Nicolas.

P.S.: This question was asked several times in the last days, by the
way. Somewhere, it is suggested that you read newsgroups some time
before you post...

Julian Stecklina

no leída,
12 abr 2002, 10:00:3012/4/02
a
joa...@arti.vub.ac.be writes:


I think the effect of changing constant objects (like your #(123)
which is created at read time) is undefined. Always use (vector bla
...) instead when you intend to change it.

--
Meine Hompage: http://julian.re6.de

Ich suche eine PCMCIA v1.x type I/II/III Netzwerkkarte.
Ich biete als Tauschobjekt eine v2 100MBit Karte in OVP.

Coby Beck

no leída,
12 abr 2002, 11:24:0012/4/02
a

<joa...@arti.vub.ac.be> wrote in message
news:l3ads92...@artipc18.vub.ac.be...

>
>
> Try the following ('=>' is the lisp prompt):
>
> => (defun unexptected (a)
> (let ((v #(128)))
> (incf v 2)))
> UNEXPTECTED
>
> and call the function more then one time:
>
> => (unexptected)
> 130
> => (unexptected)
> 132
>

Well, there are a lot of unexpected things in there for me. unexpected
expects an argument but doesn't complain when it doesn't get one. incf
isn't getting what it needs; what does it mean to add two to an array?
unexpected does not use the argument it is supposed to get.

How about this:
CL-USER 11 > (defun expected (n)
(let ((v (vector n)))
(incf (aref v 0) 2)
v))
EXPECTED

CL-USER 12 > (expected 5)
#(7)

CL-USER 13 > (expected 5)
#(7)

CL-USER 14 > (expected -374)
#(-372)

--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")


Marco Antoniotti

no leída,
12 abr 2002, 11:53:3012/4/02
a

joa...@arti.vub.ac.be writes:

What Common Lisp implementation are you using?

Cheers

--
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group tel. +1 - 212 - 998 3488
719 Broadway 12th Floor fax +1 - 212 - 995 4122
New York, NY 10003, USA http://bioinformatics.cat.nyu.edu
"Hello New York! We'll do what we can!"
Bill Murray in `Ghostbusters'.

Erik Naggum

no leída,
12 abr 2002, 12:07:1112/4/02
a
* joa...@arti.vub.ac.be

| Try the following ('=>' is the lisp prompt):
|
| => (defun unexptected (a)
| (let ((v #(128)))
| (incf v 2)))
| UNEXPTECTED

Why are you incrementing a vector?

///
--
In a fight against something, the fight has value, victory has none.
In a fight for something, the fight is a loss, victory merely relief.

Post with compassion: http://home.chello.no/~xyzzy/kitten.jpg

0 mensajes nuevos