Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

I bet the human brain is a kludge. -- Marvin Minsky


devel / comp.lang.lisp / strange behaviour of (delete .. in Allegro

SubjectAuthor
* strange behaviour of (delete .. in Allegroslowman01
+- Re: strange behaviour of (delete .. in AllegroLieven Marchand
+* Re: strange behaviour of (delete .. in AllegroSpiros Bousbouras
|`- Re: strange behaviour of (delete .. in Allegroslowman01
`* Re: strange behaviour of (delete .. in AllegroKaz Kylheku
 `* Re: strange behaviour of (delete .. in Allegrosmh
  `- Re: strange behaviour of (delete .. in Allegroslowman01

1
strange behaviour of (delete .. in Allegro

<6c46418e-b0a4-446b-b0a0-36cb415520a0n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17286&group=comp.lang.lisp#17286

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:a05:6214:209:b0:4bb:6bbd:8c1b with SMTP id i9-20020a056214020900b004bb6bbd8c1bmr70210418qvt.111.1671295133172;
Sat, 17 Dec 2022 08:38:53 -0800 (PST)
X-Received: by 2002:a9d:3e7:0:b0:670:5bc6:a758 with SMTP id
f94-20020a9d03e7000000b006705bc6a758mr6860114otf.100.1671295132842; Sat, 17
Dec 2022 08:38:52 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.lisp
Date: Sat, 17 Dec 2022 08:38:52 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f9:f723:a516:a505:41fe:55c5:962c;
posting-account=lwvs8AoAAAAR1AeHcx419_BrE_n4VzsN
NNTP-Posting-Host: 2003:f9:f723:a516:a505:41fe:55c5:962c
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6c46418e-b0a4-446b-b0a0-36cb415520a0n@googlegroups.com>
Subject: strange behaviour of (delete .. in Allegro
From: tomue.pallas@gmail.com (slowman01)
Injection-Date: Sat, 17 Dec 2022 16:38:53 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1612
 by: slowman01 - Sat, 17 Dec 2022 16:38 UTC

Hello!

I try to remove random elements from a list until the list is empty. My environment is Allegro Lisp , free edition.

(setq set1 '(Nr1 Nr2 Nr3))
(delete (nth (random (length set1)) set1) set1)

after some repetitions , the output of sequential calls to delete (and the content of set1) start to look like this

(NR1 NR2 NR3)
(NR2 NR3)
(NR1 NR2)
(NR1)
NIL
that is, sometimes items are not deleted, sometimes deleted items reappear. If I use remove there is no such problem.

Is this a bug or do I miss something about delete ?

thank you
Thomas

Re: strange behaviour of (delete .. in Allegro

<87a63m2c81.fsf@wyrd.be>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17288&group=comp.lang.lisp#17288

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sat, 17 Dec 2022 17:00:29 +0000
From: mal@wyrd.be (Lieven Marchand)
Newsgroups: comp.lang.lisp
Subject: Re: strange behaviour of (delete .. in Allegro
References: <6c46418e-b0a4-446b-b0a0-36cb415520a0n@googlegroups.com>
Date: Sat, 17 Dec 2022 18:04:30 +0100
Message-ID: <87a63m2c81.fsf@wyrd.be>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:DjVHuZax3Oqp8FBXhB2IKz9NnEc=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Lines: 24
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-P0PuYVfDDa2N/ER8/NN2vRC3S5a/b5nGeblLfhpm/iihMMiiTdZf/bIVaqkbodyAenvRcU/EzQMAGOi!M6EQmHsRhDSxzUlBtoidfH13n2TzhT2bZsjUI58+PA==
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
 by: Lieven Marchand - Sat, 17 Dec 2022 17:04 UTC

slowman01 <tomue.pallas@gmail.com> writes:

> Hello!
>
> I try to remove random elements from a list until the list is
> empty. My environment is Allegro Lisp , free edition.

> after some repetitions , the output of sequential calls to delete (and
> the content of set1) start to look like this

> that is, sometimes items are not deleted, sometimes deleted items
> reappear. If I use remove there is no such problem.
>
> Is this a bug or do I miss something about delete ?

REMOVE is non destructive and will if needed create fresh lists. DELETE
is potentially destructive and will modify the existing list. So you
need to reassign the result of DELETE.

(setf list (delete item list)) will fix your problem.

--
Laat hulle almal sterf. Ek is tevrede om die wêreld te sien brand en die vallende
konings te spot. Ek en my aasdier sal loop op die as van die verwoeste aarde.

Re: strange behaviour of (delete .. in Allegro

<kZy5uu9xO9MFqAUWY@bongo-ra.co>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17289&group=comp.lang.lisp#17289

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: spibou@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.lisp
Subject: Re: strange behaviour of (delete .. in Allegro
Date: Sat, 17 Dec 2022 19:03:02 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <kZy5uu9xO9MFqAUWY@bongo-ra.co>
References: <6c46418e-b0a4-446b-b0a0-36cb415520a0n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 17 Dec 2022 19:03:02 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="77df1860c24f123305fb8450030de443";
logging-data="3912096"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19RZexatfer5TDBq23lw9ku"
Cancel-Lock: sha1:RAmGoEQueXjEVe7l52sD/eOgrvc=
X-Organisation: Weyland-Yutani
In-Reply-To: <6c46418e-b0a4-446b-b0a0-36cb415520a0n@googlegroups.com>
X-Server-Commands: nowebcancel
 by: Spiros Bousbouras - Sat, 17 Dec 2022 19:03 UTC

On Sat, 17 Dec 2022 08:38:52 -0800 (PST)
slowman01 <tomue.pallas@gmail.com> wrote:
> Hello!
>
> I try to remove random elements from a list until the list is empty.
> My environment is Allegro Lisp , free edition.
>
> (setq set1 '(Nr1 Nr2 Nr3))
> (delete (nth (random (length set1)) set1) set1)
>
> after some repetitions , the output of sequential calls to delete (and
> the content of set1) start to look like this
>
> (NR1 NR2 NR3)
> (NR2 NR3)
> (NR1 NR2)
> (NR1)
> NIL
> that is, sometimes items are not deleted, sometimes deleted items reappear.
> If I use remove there is no such problem.

Use REMOVE how ?

> Is this a bug or do I miss something about delete ?

You are missing 2 things : first , modifying a quoted object is undefined
behaviour. So if you want to use DELETE you have to do
(setq set1 (list 'Nr1 'Nr2 'Nr3))

Second , the new list created by DELETE won't necessarily be what set1
points to. So you must do [as <87a63m2c81.fsf@wyrd.be> has said]
(setq set1 (delete ...))

Don't you do it like this when you use REMOVE ?

--
man telnet
BUGS
The source code is not comprehensible.

Re: strange behaviour of (delete .. in Allegro

<20221218142306.215@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17294&group=comp.lang.lisp#17294

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: strange behaviour of (delete .. in Allegro
Date: Sun, 18 Dec 2022 22:26:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <20221218142306.215@kylheku.com>
References: <6c46418e-b0a4-446b-b0a0-36cb415520a0n@googlegroups.com>
Injection-Date: Sun, 18 Dec 2022 22:26:54 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="16b953b12cde008ec5828c6d2e0f5a1a";
logging-data="72036"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+kRT0yGqtNIkxkh21u+m2A8yhO8D7Bdyc="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:t9IZsJltk9Jb745IwRg8lWIbVN4=
 by: Kaz Kylheku - Sun, 18 Dec 2022 22:26 UTC

On 2022-12-17, slowman01 <tomue.pallas@gmail.com> wrote:
> Hello!
>
> I try to remove random elements from a list until the list is empty. My environment is Allegro Lisp , free edition.
>
> (setq set1 '(Nr1 Nr2 Nr3))
> (delete (nth (random (length set1)) set1) set1)

1. You must capture the result of remove or delete!
Even though delete is destructive, what that means is that
there is a new list which is destructively made out of the pieces of
the old list. //That new list appears as the return value of
delete.///

The original input object stored in setl is possibly just one of the
fragments of the original list. Think about it: what if the first
item is deleted? Setl still points to the cons cell which held that
item; delete cannot update the setl variable.

2. Because delete is destructive, you must generally take special
care about correctness. Get the code working with remove, and then
carefully change remove calls to delete, if you're able to justify
that the program doesn't break.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: strange behaviour of (delete .. in Allegro

<52b9e52f-064d-4973-9bd2-d6d6d7054952n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17295&group=comp.lang.lisp#17295

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:ac8:687:0:b0:3a5:41fd:2216 with SMTP id f7-20020ac80687000000b003a541fd2216mr90149978qth.338.1671426463257;
Sun, 18 Dec 2022 21:07:43 -0800 (PST)
X-Received: by 2002:a9d:7ad2:0:b0:672:434d:b7f5 with SMTP id
m18-20020a9d7ad2000000b00672434db7f5mr1243926otn.73.1671426462945; Sun, 18
Dec 2022 21:07:42 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.lisp
Date: Sun, 18 Dec 2022 21:07:42 -0800 (PST)
In-Reply-To: <20221218142306.215@kylheku.com>
Injection-Info: google-groups.googlegroups.com; posting-host=23.93.180.39; posting-account=GBVz1QoAAABLyMbxU_fsoKKC5clEj6fn
NNTP-Posting-Host: 23.93.180.39
References: <6c46418e-b0a4-446b-b0a0-36cb415520a0n@googlegroups.com> <20221218142306.215@kylheku.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <52b9e52f-064d-4973-9bd2-d6d6d7054952n@googlegroups.com>
Subject: Re: strange behaviour of (delete .. in Allegro
From: shaflich@gmail.com (smh)
Injection-Date: Mon, 19 Dec 2022 05:07:43 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3436
 by: smh - Mon, 19 Dec 2022 05:07 UTC

The two previous answers so far are (almost) correct, but will not make the real issue clear to a beginner.

But first, the reason these two answers are not quite correct is that they miss that the desired behavior is incompatible with Common Lisp! Specifically, the original question created the list as a quoted literal, i.e. '(Nr1 Nr2 Nr3), and Common Lisp prohibits modifying any literal datum (ANS 3.7.1). This allows an implementation to place some or all constants in pure space where an attempt to modify the constant would result in an exception. Now, most actual implementations don't exploit this so modifying a constant will generally work (despite being considered poor practice in most languages) so constant modification is not the issue here.

The following interaction might better illustrate what delete does and does not do, and what OP probably experienced

cl-user(8): (defparameter *foo* (list 'a 'b 'c 'd)) ; A conforming way to create a mutable list.
*FOO*
cl-user(9): (delete 'd *foo*)
(A B C)
cl-user(10): *foo*
(A B C)
cl-user(11): (delete 'a *foo*)
(B C) ; The original list is not modified
cl-user(12): *foo*
(A B C) ; The value of *foo* is also not modified.

Now, the delete in (9) steps down the list and when it finds a cons whose car is d, it sets the cdr of the _previous_ cons to the cdr of the cons cell holding d (which in this example is nil because that cons is the last element of the list). Thus, the list has been destructively modified deletining d, and the value of *foo* is still the first cons of the original list, the one containing a.
The delete in (11) encounters the a in the very first cons cell of the list.. There is no previous cons whose cdr can be changed, so delete simply returns the cdr of the "deleted" cons, which is the correct result. The symbol (better called the variable) *foo* is not passed to delete, only its value (the list) so delete can not and should not destructively modify it. So *foo* still points to the first cons of the original list, and the cdr of that cons still points to the second element of the original list. delkete does not and can not modify the value stored in *foo*.

Re: strange behaviour of (delete .. in Allegro

<6a527b89-25b0-4d92-95d9-5d06c0a2f7a4n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17296&group=comp.lang.lisp#17296

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:ac8:687:0:b0:3a5:41fd:2216 with SMTP id f7-20020ac80687000000b003a541fd2216mr90233125qth.338.1671471336389;
Mon, 19 Dec 2022 09:35:36 -0800 (PST)
X-Received: by 2002:a05:6871:a68e:b0:144:1b93:3f9a with SMTP id
wh14-20020a056871a68e00b001441b933f9amr1806776oab.200.1671471335982; Mon, 19
Dec 2022 09:35:35 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.lisp
Date: Mon, 19 Dec 2022 09:35:35 -0800 (PST)
In-Reply-To: <52b9e52f-064d-4973-9bd2-d6d6d7054952n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f9:f723:a5c7:4449:cb9:b802:ee50;
posting-account=lwvs8AoAAAAR1AeHcx419_BrE_n4VzsN
NNTP-Posting-Host: 2003:f9:f723:a5c7:4449:cb9:b802:ee50
References: <6c46418e-b0a4-446b-b0a0-36cb415520a0n@googlegroups.com>
<20221218142306.215@kylheku.com> <52b9e52f-064d-4973-9bd2-d6d6d7054952n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6a527b89-25b0-4d92-95d9-5d06c0a2f7a4n@googlegroups.com>
Subject: Re: strange behaviour of (delete .. in Allegro
From: tomue.pallas@gmail.com (slowman01)
Injection-Date: Mon, 19 Dec 2022 17:35:36 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1784
 by: slowman01 - Mon, 19 Dec 2022 17:35 UTC

smh schrieb am Montag, 19. Dezember 2022 um 06:07:45 UTC+1:
> The two previous answers so far are (almost) correct, but will not make the real issue clear to a beginner.
...
Thank you, this is exactly what I didn't understand . I treated *foo* as if it is a structure holding a list which can be updated. I missed the point that it is just the car of the original list. I also didn't know the difference between '(a b c) and (list 'a 'b 'c).

Re: strange behaviour of (delete .. in Allegro

<f34e9727-18be-4f67-aa1b-baee016dbd3an@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17297&group=comp.lang.lisp#17297

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:ad4:4f91:0:b0:514:6d9a:37e9 with SMTP id em17-20020ad44f91000000b005146d9a37e9mr249107qvb.43.1671472218333;
Mon, 19 Dec 2022 09:50:18 -0800 (PST)
X-Received: by 2002:a9d:7f86:0:b0:670:9177:156c with SMTP id
t6-20020a9d7f86000000b006709177156cmr2231337otp.83.1671472218084; Mon, 19 Dec
2022 09:50:18 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.lisp
Date: Mon, 19 Dec 2022 09:50:17 -0800 (PST)
In-Reply-To: <kZy5uu9xO9MFqAUWY@bongo-ra.co>
Injection-Info: google-groups.googlegroups.com; posting-host=2003:f9:f723:a5c7:4449:cb9:b802:ee50;
posting-account=lwvs8AoAAAAR1AeHcx419_BrE_n4VzsN
NNTP-Posting-Host: 2003:f9:f723:a5c7:4449:cb9:b802:ee50
References: <6c46418e-b0a4-446b-b0a0-36cb415520a0n@googlegroups.com> <kZy5uu9xO9MFqAUWY@bongo-ra.co>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f34e9727-18be-4f67-aa1b-baee016dbd3an@googlegroups.com>
Subject: Re: strange behaviour of (delete .. in Allegro
From: tomue.pallas@gmail.com (slowman01)
Injection-Date: Mon, 19 Dec 2022 17:50:18 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1457
 by: slowman01 - Mon, 19 Dec 2022 17:50 UTC

Spiros Bousbouras schrieb am Samstag, 17. Dezember 2022 um 20:03:07 UTC+1:
> Don't you do it like this when you use REMOVE ?
Yes, I did so when using remove but not with delete, because I misunderstood the nature of variable set1. It is clear to me now.
Thank you!

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor