Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

unexpected function behavior

0 views
Skip to first unread message

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

unread,
Apr 12, 2002, 9:11:22 AM4/12/02
to

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

unread,
Apr 12, 2002, 9:37:07 AM4/12/02
to
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

unread,
Apr 12, 2002, 9:19:50 AM4/12/02
to
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

unread,
Apr 12, 2002, 10:00:30 AM4/12/02
to
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

unread,
Apr 12, 2002, 11:24:00 AM4/12/02
to

<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

unread,
Apr 12, 2002, 11:53:30 AM4/12/02
to

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

unread,
Apr 12, 2002, 12:07:11 PM4/12/02
to
* 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 new messages