From: ·······@arti.vub.ac.be
Subject: unexpected function behavior
Date: 
Message-ID: <l3ads92had.fsf@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

Is this intended?? 

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

Joachim.

From: Marco Antoniotti
Subject: Re: unexpected function behavior
Date: 
Message-ID: <y6cu1qghq11.fsf@octagon.mrl.nyu.edu>
·······@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'.
From: Nicolas Neuss
Subject: Re: unexpected function behavior
Date: 
Message-ID: <87ads95a15.fsf@ortler.iwr.uni-heidelberg.de>
·······@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...
From: Coby Beck
Subject: Re: unexpected function behavior
Date: 
Message-ID: <k_Ct8.18612$de1.922685@news3.calgary.shaw.ca>
<·······@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")
From: Dr. Edmund Weitz
Subject: Re: unexpected function behavior
Date: 
Message-ID: <m37kndf37g.fsf@dyn138.dbdmedia.de>
·······@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/>
From: Julian Stecklina
Subject: Re: unexpected function behavior
Date: 
Message-ID: <87u1qhj9tt.fsf@blitz.comp.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.


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.
From: Erik Naggum
Subject: Re: unexpected function behavior
Date: 
Message-ID: <3227616430878081@naggum.net>
* ·······@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