From: Norman Werner
Subject: testing whether a variable was altered
Date: 
Message-ID: <87wud66d8n.fsf@wh6-307.st.uni-magdeburg.de>
Hello,
I am trying to check whether an arbitrary  function alters its
argument or not.

eg: 
 (defvar input '((1 x) (a b c) (2)))
 (defun my-sort (liste)
   (sort liste #'is-longer))

 (my-sort input)
 => ((A B C) (1 X) (2))
 input
 => ((1 X) (2))

However I found it surprisingly hard to check  whether the
argument was changed or not. 

Eg: 
 (setf input '((1 x) (a b c) (2)))
 (defvar input2 input)
 (my-sort input)
 => ((A B C) (1 X) (2))
 (eq input input2)
 => T
 input
 => ((1 X) (2))

I understand this behaviour but nevertheless I have no idea how to do
this test. I could use copy-seq in this special case but i'm looking
for a general solution (eg. clos-objects as arguments).

Any ideas?! Thanks.

Norman
-- 
One Language to rule them all, One Language to find them, One Language
to bring them all and in the darkness bind them in the Land of Mordor
where the Shadows lie.  

Norman Werner (Zi. 307)
J. G. Nathusius Ring 7 (WH6)
39106 Magdeburg
·············@student.uni-magdeburg.de

From: Pascal Bourguignon
Subject: Re: testing whether a variable was altered
Date: 
Message-ID: <87ada17vdx.fsf@thalassa.informatimago.com>
Norman Werner <·············@student.uni-magdeburg.de> writes:

> Hello,
> I am trying to check whether an arbitrary  function alters its
> argument or not.
> 
> eg: 
>  (defvar input '((1 x) (a b c) (2)))
>  (defun my-sort (liste)
>    (sort liste #'is-longer))
> 
>  (my-sort input)
>  => ((A B C) (1 X) (2))
>  input
>  => ((1 X) (2))
> 
> However I found it surprisingly hard to check  whether the
> argument was changed or not. 
> 
> Eg: 
>  (setf input '((1 x) (a b c) (2)))
>  (defvar input2 input)
>  (my-sort input)
>  => ((A B C) (1 X) (2))
>  (eq input input2)
>  => T
>  input
>  => ((1 X) (2))
> 
> I understand this behaviour but nevertheless I have no idea how to do
> this test. I could use copy-seq in this special case but i'm looking
> for a general solution (eg. clos-objects as arguments).
> 
> Any ideas?! Thanks.

Here  http://www.nhplace.com/kent/PS/EQUAL.html is nice  article about
the  difficulties  of defining  a  copy  function.   (Same problem  as
defining an  equal function). You  will have the same  difficulties in
defining a general solution for your problem.

On  the other  hand,  CLOS  objects can  know  when they're  modified:
normally only  an object can modify  itself. The other  must pass thru
sending a message to this object.  So you should not have this problem
for CLOS objects to begin with.


-- 
__Pascal_Bourguignon__                   http://www.informatimago.com/
----------------------------------------------------------------------
Do not adjust your mind, there is a fault in reality.
From: Norman Werner
Subject: Re: testing whether a variable was altered
Date: 
Message-ID: <87smnuvb8a.fsf@wh6-307.st.uni-magdeburg.de>
Pascal Bourguignon <····@thalassa.informatimago.com> skribis:

>> Any ideas?! Thanks.
>
> Here  http://www.nhplace.com/kent/PS/EQUAL.html is nice  article about
> the  difficulties  of defining  a  copy  function.   (Same problem  as
> defining an  equal function). You  will have the same  difficulties in
> defining a general solution for your problem.
>
> On  the other  hand,  CLOS  objects can  know  when they're  modified:
> normally only  an object can modify  itself. The other  must pass thru
> sending a message to this object.  So you should not have this problem
> for CLOS objects to begin with.

Thanks for the link - I took a quick glimpse - it seems
to be an interesting discussion. 

Norman
-- 
One Language to rule them all, One Language to find them, One Language
to bring them all and in the darkness bind them in the Land of Mordor
where the Shadows lie.  

Norman Werner (Zi. 307)
J. G. Nathusius Ring 7 (WH6)
39106 Magdeburg
·············@student.uni-magdeburg.de
From: Rainer Joswig
Subject: Re: testing whether a variable was altered
Date: 
Message-ID: <joswig-208C34.14222324082003@news.fu-berlin.de>
In article <··············@wh6-307.st.uni-magdeburg.de>,
 Norman Werner <·············@student.uni-magdeburg.de> wrote:

> Hello,
> I am trying to check whether an arbitrary  function alters its
> argument or not.
> 
> eg: 
>  (defvar input '((1 x) (a b c) (2)))
>  (defun my-sort (liste)
>    (sort liste #'is-longer))
> 
>  (my-sort input)
>  => ((A B C) (1 X) (2))
>  input
>  => ((1 X) (2))
> 
> However I found it surprisingly hard to check  whether the
> argument was changed or not. 
> 
> Eg: 
>  (setf input '((1 x) (a b c) (2)))
>  (defvar input2 input)
>  (my-sort input)
>  => ((A B C) (1 X) (2))
>  (eq input input2)
>  => T
>  input
>  => ((1 X) (2))
> 
> I understand this behaviour but nevertheless I have no idea how to do
> this test. I could use copy-seq in this special case but i'm looking
> for a general solution (eg. clos-objects as arguments).
> 
> Any ideas?! Thanks.
> 
> Norman

I guess according to ANSI CL above is not even allowed.

'( ... ) is a constant object.

SORT is destructively changing the sequence.

->  SORT on a constant object is not allowed.

Sigh.

Solution: copy the list first.

(I hate this topic.)
From: Marco Baringer
Subject: Re: testing whether a variable was altered
Date: 
Message-ID: <m2ad9zxm1f.fsf@bese.it>
Rainer Joswig <······@lispmachine.de> writes:

> I guess according to ANSI CL above is not even allowed.
>
> '( ... ) is a constant object.
>
> SORT is destructively changing the sequence.
>
> ->  SORT on a constant object is not allowed.
>
> Sigh.
>
> Solution: copy the list first.

or define the read macro #Q to expand to (copy-tree (quote FORM)).

-- 
-Marco
Ring the bells that still can ring.
Forget your perfect offering.
There is a crack in everything.
That's how the light gets in.
     -Leonard Cohen