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.
·······@arti.vub.ac.be writes:
> 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.
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'.
·······@arti.vub.ac.be writes:
> 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.
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...
<·······@arti.vub.ac.be> wrote in message
···················@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")
·······@arti.vub.ac.be writes:
> 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.
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/>
·······@arti.vub.ac.be writes:
> 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.
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.
* ·······@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