Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

One man's constant is another man's variable. -- A. J. Perlis


devel / comp.lang.lisp / Re: how to map a variable to a list?

SubjectAuthor
* how to map a variable to a list?Jinsong Zhao
+* Re: how to map a variable to a list?Spiros Bousbouras
|+- Re: how to map a variable to a list?Kaz Kylheku
|`- Re: how to map a variable to a list?steve
+- Re: how to map a variable to a list?Tom Russ
+* Re: how to map a variable to a list?Tom Russ
|`* Re: how to map a variable to a list?Jinsong Zhao
| +* Re: how to map a variable to a list?Tom Russ
| |`* Re: how to map a variable to a list?Jinsong Zhao
| | `* Re: how to map a variable to a list?Spiros Bousbouras
| |  `- Re: how to map a variable to a list?Spiros Bousbouras
| `- Re: how to map a variable to a list?jimtaylor
+- Re: how to map a variable to a list?Kaz Kylheku
+- Re: how to map a variable to a list?Ben Bacarisse
`* Re: how to map a variable to a list?Yong
 +- Re: how to map a variable to a list?Kaz Kylheku
 `- Re: how to map a variable to a list?Madhu

1
how to map a variable to a list?

<u111j3$26d7d$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: jszhao@yeah.net (Jinsong Zhao)
Newsgroups: comp.lang.lisp
Subject: how to map a variable to a list?
Date: Mon, 10 Apr 2023 21:05:23 +0800
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <u111j3$26d7d$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 10 Apr 2023 13:05:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9157715482532127d2ec0972999ec6aa";
logging-data="2307309"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ancq+MpJT2+iTRFTfbUpr"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.9.1
Cancel-Lock: sha1:42GXv9bRA8FJ5ilLx6mrpP4UQJs=
Content-Language: en-US
 by: Jinsong Zhao - Mon, 10 Apr 2023 13:05 UTC

Hi there,

In the following code example,

(defun a-test (lst)
(let ((a (elt lst 0))
(b (elt lst 1))
(c (elt lst 2)))
(+ a (- c b))))

How to map local variable a, b, and c to the elements of lst? In my
actual code, the lst have 12 elements, and I have 12 named local
variables that appeared in the body with high frequency.

Best,
Jinsong

Re: how to map a variable to a list?

<O5sf1cOqAlzNMgIN7@bongo-ra.co>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: spibou@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.lisp
Subject: Re: how to map a variable to a list?
Date: Mon, 10 Apr 2023 13:49:39 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <O5sf1cOqAlzNMgIN7@bongo-ra.co>
References: <u111j3$26d7d$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 10 Apr 2023 13:49:39 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0e2a24fbd5f2fec597d17cd44f9251bd";
logging-data="2319669"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/druFCYE4b2XT05D3sdEXF"
Cancel-Lock: sha1:M4/2X1E+waUJVXNkIpWLeJ6NERA=
X-Organisation: Weyland-Yutani
X-Server-Commands: nowebcancel
In-Reply-To: <u111j3$26d7d$1@dont-email.me>
 by: Spiros Bousbouras - Mon, 10 Apr 2023 13:49 UTC

On Mon, 10 Apr 2023 21:05:23 +0800
Jinsong Zhao <jszhao@yeah.net> wrote:
> Hi there,
>
> In the following code example,
>
> (defun a-test (lst)
> (let ((a (elt lst 0))
> (b (elt lst 1))
> (c (elt lst 2)))
> (+ a (- c b))))
>
> How to map local variable a, b, and c to the elements of lst? In my
> actual code, the lst have 12 elements, and I have 12 named local
> variables that appeared in the body with high frequency.

Why is the above code not satisfactory ?

Re: how to map a variable to a list?

<f6fbe1e3-d31f-493d-92b3-e44ee85eaccen@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:a05:620a:4047:b0:745:718a:8c58 with SMTP id i7-20020a05620a404700b00745718a8c58mr2632699qko.10.1681144734514;
Mon, 10 Apr 2023 09:38:54 -0700 (PDT)
X-Received: by 2002:a05:622a:1a8f:b0:3e2:7190:57ba with SMTP id
s15-20020a05622a1a8f00b003e2719057bamr4036304qtc.3.1681144734186; Mon, 10 Apr
2023 09:38:54 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.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, 10 Apr 2023 09:38:53 -0700 (PDT)
In-Reply-To: <u111j3$26d7d$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2603:8000:7603:1703:2815:131:e901:7d82;
posting-account=05zmAwoAAAAJZM-3jv1hCWLHGZQceqwA
NNTP-Posting-Host: 2603:8000:7603:1703:2815:131:e901:7d82
References: <u111j3$26d7d$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f6fbe1e3-d31f-493d-92b3-e44ee85eaccen@googlegroups.com>
Subject: Re: how to map a variable to a list?
From: taruss@google.com (Tom Russ)
Injection-Date: Mon, 10 Apr 2023 16:38:54 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1644
 by: Tom Russ - Mon, 10 Apr 2023 16:38 UTC

On Monday, April 10, 2023 at 6:05:45 AM UTC-7, Jinsong Zhao wrote:
> Hi there,
>
> In the following code example,
>
> (defun a-test (lst)
> (let ((a (elt lst 0))
> (b (elt lst 1))
> (c (elt lst 2)))
> (+ a (- c b))))
>
> How to map local variable a, b, and c to the elements of lst? In my
> actual code, the lst have 12 elements, and I have 12 named local
> variables that appeared in the body with high frequency.

Re: how to map a variable to a list?

<024bfbe6-8505-431f-b027-e958e37de174n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:a05:620a:28c5:b0:748:4c2f:e65c with SMTP id l5-20020a05620a28c500b007484c2fe65cmr3754855qkp.5.1681145180444;
Mon, 10 Apr 2023 09:46:20 -0700 (PDT)
X-Received: by 2002:a05:622a:1ba2:b0:3df:37d5:8d26 with SMTP id
bp34-20020a05622a1ba200b003df37d58d26mr4245920qtb.4.1681145180172; Mon, 10
Apr 2023 09:46:20 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!usenet.blueworldhosting.com!diablo1.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, 10 Apr 2023 09:46:19 -0700 (PDT)
In-Reply-To: <u111j3$26d7d$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2603:8000:7603:1703:2815:131:e901:7d82;
posting-account=05zmAwoAAAAJZM-3jv1hCWLHGZQceqwA
NNTP-Posting-Host: 2603:8000:7603:1703:2815:131:e901:7d82
References: <u111j3$26d7d$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <024bfbe6-8505-431f-b027-e958e37de174n@googlegroups.com>
Subject: Re: how to map a variable to a list?
From: taruss@google.com (Tom Russ)
Injection-Date: Mon, 10 Apr 2023 16:46:20 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2903
 by: Tom Russ - Mon, 10 Apr 2023 16:46 UTC

On Monday, April 10, 2023 at 6:05:45 AM UTC-7, Jinsong Zhao wrote:
> Hi there,
>
> In the following code example,
>
> (defun a-test (lst)
> (let ((a (elt lst 0))
> (b (elt lst 1))
> (c (elt lst 2)))
> (+ a (- c b))))
>
> How to map local variable a, b, and c to the elements of lst? In my
> actual code, the lst have 12 elements, and I have 12 named local
> variables that appeared in the body with high frequency.
>
> Best,
> Jinsong

It isn't clear to us what behavior you want to have from your mapping.
In the code you show, each of the variables is bound to a particular element
of your input list. So you can use them to reference the values of the list..
But each of the variables is a local variable inside the LET form, so any change
to the variable is just a local effect. It will not change the value in the input
list unless the change you make on the local variable is a mutation of the object
that the variable is bound to.

The code you provided should return the value of (+ A (- C B)). What do you
expect it to do?

Some other comments.
In general ELT is not a great function to use on lists, because it has to walk the
list until it gets to the Nth element. If you want to bind a number of variables to
elements of a list, then DESTRUCTURING-BIND will be more convenient and also
more efficient.

But if you have a fixed size list where the individual elements have some meaningful
names, then perhaps an even better approach would be to use a struct (via DEFSTRUCT)
to provide named accessors to the elements. It would also have the side benefit
of being both more space and time efficient.

Re: how to map a variable to a list?

<20230410113719.316@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: how to map a variable to a list?
Date: Mon, 10 Apr 2023 18:38:32 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <20230410113719.316@kylheku.com>
References: <u111j3$26d7d$1@dont-email.me>
Injection-Date: Mon, 10 Apr 2023 18:38:32 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6e25d9c0cce66d3d68bacb7296443182";
logging-data="2398897"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18mOuPW5OFw+F4/HJC9xa7P6jR7SAYHjb8="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:lu/7QU3pbL2j94JiXMvct5IBSXk=
 by: Kaz Kylheku - Mon, 10 Apr 2023 18:38 UTC

On 2023-04-10, Jinsong Zhao <jszhao@yeah.net> wrote:
> Hi there,
>
> In the following code example,
>
> (defun a-test (lst)
> (let ((a (elt lst 0))
> (b (elt lst 1))
> (c (elt lst 2)))
> (+ a (- c b))))
>
> How to map local variable a, b, and c to the elements of lst? In my
> actual code, the lst have 12 elements, and I have 12 named local
> variables that appeared in the body with high frequency.

(destructuring-bind (a b c) lst
...)

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

Re: how to map a variable to a list?

<20230410113843.471@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: how to map a variable to a list?
Date: Mon, 10 Apr 2023 18:41:11 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <20230410113843.471@kylheku.com>
References: <u111j3$26d7d$1@dont-email.me> <O5sf1cOqAlzNMgIN7@bongo-ra.co>
Injection-Date: Mon, 10 Apr 2023 18:41:11 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6e25d9c0cce66d3d68bacb7296443182";
logging-data="2398897"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8wl8BBA16IRtGCePbXSj5sqzALZIoknA="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:0bESI1YHmn/BjqzfkciYZ1rBiZU=
 by: Kaz Kylheku - Mon, 10 Apr 2023 18:41 UTC

On 2023-04-10, Spiros Bousbouras <spibou@gmail.com> wrote:
> On Mon, 10 Apr 2023 21:05:23 +0800
> Jinsong Zhao <jszhao@yeah.net> wrote:
>> Hi there,
>>
>> In the following code example,
>>
>> (defun a-test (lst)
>> (let ((a (elt lst 0))
>> (b (elt lst 1))
>> (c (elt lst 2)))
>> (+ a (- c b))))
>>
>> How to map local variable a, b, and c to the elements of lst? In my
>> actual code, the lst have 12 elements, and I have 12 named local
>> variables that appeared in the body with high frequency.
>
> Why is the above code not satisfactory ?

Other than that nobody who knows Common Lisp inside out would
write it that way, rather than doing a destructuring-bind?

This could be an X-Y problem; perhaps the function just wants
to take separate arguments, and the caller should apply the list.

(defun a-test (a b c) ...)

(apply #'a-test '(1 2 3))

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

Re: how to map a variable to a list?

<87ttxnze53.fsf@bsb.me.uk>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.lisp
Subject: Re: how to map a variable to a list?
Date: Mon, 10 Apr 2023 21:16:40 +0100
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <87ttxnze53.fsf@bsb.me.uk>
References: <u111j3$26d7d$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="b28ae3d43b73d0a1fbf20976cf7a1242";
logging-data="2430894"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ZqRtK1ZeDs7DFAfeHOF0FXDpvG32+QzA="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:JWTZai+wNOerDU2V6a+0fFL1m8I=
sha1:8RRsAoSaTb1DX6JXq3qI24L00MQ=
X-BSB-Auth: 1.6ca96c2c2a262e83e02b.20230410211640BST.87ttxnze53.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 10 Apr 2023 20:16 UTC

Jinsong Zhao <jszhao@yeah.net> writes:

> In the following code example,
>
> (defun a-test (lst)
> (let ((a (elt lst 0))
> (b (elt lst 1))
> (c (elt lst 2)))
> (+ a (- c b))))
>
> How to map local variable a, b, and c to the elements of lst? In my actual
> code, the lst have 12 elements, and I have 12 named local variables that
> appeared in the body with high frequency.

As others have said, it's not clear what the problem is. It would help
if you posted the actual code, because giving a simplified example may be
hiding what you see as the problem.

In the meantime, since 'lst' suggests a list, have you considered using
destructuring-bind?

(defun a-test (lst)
(destructuring-bind (a b c &rest _) lst
(+ a (- c b))))

(Note: elt works on any sequence so this may not suit your use.)

--
Ben.

Re: how to map a variable to a list?

<u13mcm$2l1uj$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: luo.yong.name@gmail.com (Yong)
Newsgroups: comp.lang.lisp
Subject: Re: how to map a variable to a list?
Date: Tue, 11 Apr 2023 21:12:53 +0800
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <u13mcm$2l1uj$1@dont-email.me>
References: <u111j3$26d7d$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 11 Apr 2023 13:12:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a75a14698216c28eda3a7b4657f1d75f";
logging-data="2787283"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mSOalhXZqNo0jySZOJ/mv"
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.9.1
Cancel-Lock: sha1:TvlhWl6OwPeWRQcnwHWkOHwxaR8=
In-Reply-To: <u111j3$26d7d$1@dont-email.me>
Content-Language: en-US
 by: Yong - Tue, 11 Apr 2023 13:12 UTC

On 2023/4/10 21:05, Jinsong Zhao wrote:
> Hi there,
>
> In the following code example,
>
> (defun a-test (lst)
>   (let ((a (elt lst 0))
>         (b (elt lst 1))
>         (c (elt lst 2)))
>     (+ a (- c b))))
>
> How to map local variable a, b, and c to the elements of lst? In my
> actual code, the lst have 12 elements, and I have 12 named local
> variables that appeared in the body with high frequency.
>
> Best,
> Jinsong

Emacs macro seq-let can do the similar thing:

(seq-let (v1 v2) '(val1 val2 val3)
(message "%s %s" v1 v2))

I believe that common lisp must have a similar function, currently a
known way to do this is:

;; assign 5, 6 to v1, v2
(let (v1 v2)
(mapcar (lambda (sym val) (set sym val)) '(v1 v2) '(5 6)))

Re: how to map a variable to a list?

<20230411144432.996@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: how to map a variable to a list?
Date: Tue, 11 Apr 2023 21:45:50 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <20230411144432.996@kylheku.com>
References: <u111j3$26d7d$1@dont-email.me> <u13mcm$2l1uj$1@dont-email.me>
Injection-Date: Tue, 11 Apr 2023 21:45:50 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c1d1934a92f66af7e65bcb84666caabf";
logging-data="2866948"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+WbtKXrDhpb9hdiAmpzKAfpPxNckB28Qc="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:Qvk8dmEYZOQy1VAv9PgzgebXIUk=
 by: Kaz Kylheku - Tue, 11 Apr 2023 21:45 UTC

On 2023-04-11, Yong <luo.yong.name@gmail.com> wrote:
>
> Emacs macro seq-let can do the similar thing:
>
> (seq-let (v1 v2) '(val1 val2 val3)
> (message "%s %s" v1 v2))
>
>
> I believe that common lisp must have a similar function, currently a
> known way to do this is:
>
> ;; assign 5, 6 to v1, v2
> (let (v1 v2)
> (mapcar (lambda (sym val) (set sym val)) '(v1 v2) '(5 6)))

Please refrain from posting "AI"-generated drivel.

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

Re: how to map a variable to a list?

<m3v8i2bd1z.fsf@leonis4.robolove.meer.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: enometh@meer.net (Madhu)
Newsgroups: comp.lang.lisp
Subject: Re: how to map a variable to a list?
Date: Tue, 11 Apr 2023 21:56:16 +0530
Organization: Motzarella
Lines: 39
Message-ID: <m3v8i2bd1z.fsf@leonis4.robolove.meer.net>
References: <u111j3$26d7d$1@dont-email.me> <u13mcm$2l1uj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="b639b05cdeba93317eef0c8841abf01d";
logging-data="2808332"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+mLJzC2X1Y46BSDQwa/DMYP6hxgvXdamU="
Cancel-Lock: sha1:RYuoELLlcW9koWDyPqJ3QjEumV8=
sha1:5UNNpy2EKjhtZb5RJ2jYfErn35c=
 by: Madhu - Tue, 11 Apr 2023 16:26 UTC

* Yong <u13mcm$2l1uj$1@dont-email.me> :
Wrote on Tue, 11 Apr 2023 21:12:53 +0800:

> Emacs macro seq-let can do the similar thing:
>
> (seq-let (v1 v2) '(val1 val2 val3)
> (message "%s %s" v1 v2))
>
>
> I believe that common lisp must have a similar function, currently a
> known way to do this is:
>
> ;; assign 5, 6 to v1, v2
> (let (v1 v2)
> (mapcar (lambda (sym val) (set sym val)) '(v1 v2) '(5 6)))

In general this is wrong, unless v1 and v2 are "declared" "special". SET
modifies the global binding of the variable. You should have done a
(defvar v1) (defvar v2) first before using LET.

presumably the op was asking only about lexical bindings.

For dynamic bindings there is progv, which is a strange beast

http://www.lispworks.com/documentation/lw80/CLHS/Body/s_progv.htm
"progv allows binding one or more dynamic variables whose names may be
determined at run time"

assuming v1 and v2 do not have top-level bindings and are not declared
globally special,

```
(let ((v1 1) (v2 2)) (progv '(v1 v2) '(5 6) (list v1 v2))) ;=> (1 2)

(let ((v1 1) (v2 2))
(declare (special v1 v2))
(progv '(v1 v2) '(5 6)
(list v1 v2))) ;=> (5 6)
```

Re: how to map a variable to a list?

<u16a4t$31ink$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: jszhao@yeah.net (Jinsong Zhao)
Newsgroups: comp.lang.lisp
Subject: Re: how to map a variable to a list?
Date: Wed, 12 Apr 2023 21:02:00 +0800
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <u16a4t$31ink$1@dont-email.me>
References: <u111j3$26d7d$1@dont-email.me>
<024bfbe6-8505-431f-b027-e958e37de174n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 12 Apr 2023 13:02:21 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="99bc793ed38b4c79df33b2cf8eb25a4b";
logging-data="3197684"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/RuAxuQqAAd4uDAyWPeKqI"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.9.1
Cancel-Lock: sha1:5HhJ1tZ65ullo1T4D0uP0g4+80I=
Content-Language: en-US
In-Reply-To: <024bfbe6-8505-431f-b027-e958e37de174n@googlegroups.com>
 by: Jinsong Zhao - Wed, 12 Apr 2023 13:02 UTC

Thanks a lot for all your replies. DESTRUCTURING-BIND is what I want.

Before asking this question, I actually read its CLHS pages, however, I
did not understand it well.

Best,
Jinsong

On 2023/4/11 0:46, Tom Russ wrote:
> On Monday, April 10, 2023 at 6:05:45 AM UTC-7, Jinsong Zhao wrote:
>> Hi there,
>>
>> In the following code example,
>>
>> (defun a-test (lst)
>> (let ((a (elt lst 0))
>> (b (elt lst 1))
>> (c (elt lst 2)))
>> (+ a (- c b))))
>>
>> How to map local variable a, b, and c to the elements of lst? In my
>> actual code, the lst have 12 elements, and I have 12 named local
>> variables that appeared in the body with high frequency.
>>
>> Best,
>> Jinsong
>
> It isn't clear to us what behavior you want to have from your mapping.
> In the code you show, each of the variables is bound to a particular element
> of your input list. So you can use them to reference the values of the list.
> But each of the variables is a local variable inside the LET form, so any change
> to the variable is just a local effect. It will not change the value in the input
> list unless the change you make on the local variable is a mutation of the object
> that the variable is bound to.
>
> The code you provided should return the value of (+ A (- C B)). What do you
> expect it to do?
>
> Some other comments.
> In general ELT is not a great function to use on lists, because it has to walk the
> list until it gets to the Nth element. If you want to bind a number of variables to
> elements of a list, then DESTRUCTURING-BIND will be more convenient and also
> more efficient.
>
> But if you have a fixed size list where the individual elements have some meaningful
> names, then perhaps an even better approach would be to use a struct (via DEFSTRUCT)
> to provide named accessors to the elements. It would also have the side benefit
> of being both more space and time efficient.
>

Re: how to map a variable to a list?

<182a38b4-b108-4762-97f5-535db02cf348n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:a05:620a:3cf:b0:743:d508:97ba with SMTP id r15-20020a05620a03cf00b00743d50897bamr48462qkm.1.1681347962229;
Wed, 12 Apr 2023 18:06:02 -0700 (PDT)
X-Received: by 2002:a05:6214:3016:b0:5e9:144f:f005 with SMTP id
ke22-20020a056214301600b005e9144ff005mr1158126qvb.1.1681347961877; Wed, 12
Apr 2023 18:06:01 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!3.us.feeder.erje.net!feeder.erje.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.lisp
Date: Wed, 12 Apr 2023 18:06:01 -0700 (PDT)
In-Reply-To: <u16a4t$31ink$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2603:8000:7603:1703:3c3c:8c4c:e5f9:b4fc;
posting-account=05zmAwoAAAAJZM-3jv1hCWLHGZQceqwA
NNTP-Posting-Host: 2603:8000:7603:1703:3c3c:8c4c:e5f9:b4fc
References: <u111j3$26d7d$1@dont-email.me> <024bfbe6-8505-431f-b027-e958e37de174n@googlegroups.com>
<u16a4t$31ink$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <182a38b4-b108-4762-97f5-535db02cf348n@googlegroups.com>
Subject: Re: how to map a variable to a list?
From: taruss@google.com (Tom Russ)
Injection-Date: Thu, 13 Apr 2023 01:06:02 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 8
 by: Tom Russ - Thu, 13 Apr 2023 01:06 UTC

On Wednesday, April 12, 2023 at 6:02:29 AM UTC-7, Jinsong Zhao wrote:
> Thanks a lot for all your replies. DESTRUCTURING-BIND is what I want.

Out of curiosity, what is an example of the code that you want to write?

I ask because I wonder if a struct would be a better data structure than a list.

Re: how to map a variable to a list?

<87a5zca4fc.fsf@fastmail.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: james.taylor@fastmail.com (jimtaylor)
Newsgroups: comp.lang.lisp
Subject: Re: how to map a variable to a list?
Date: Wed, 12 Apr 2023 21:42:31 -0500
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <87a5zca4fc.fsf@fastmail.com>
References: <u111j3$26d7d$1@dont-email.me>
<024bfbe6-8505-431f-b027-e958e37de174n@googlegroups.com>
<u16a4t$31ink$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="d8ca5d7af9c1cc6331605bfedcb738f3";
logging-data="268907"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19H+9Tp6ih5ITZZ7qOJrg55YzV+iQE/M8o="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:1XOBufv2f/jZnpJC3sC7B6oWgbM=
sha1:sySDKAul2e53MyBKnmUYTgltnwo=
 by: jimtaylor - Thu, 13 Apr 2023 02:42 UTC

Jinsong Zhao <jszhao@yeah.net> writes:

> Before asking this question, I actually read its CLHS pages, however,
> I did not understand it well.

It just takes time to familiarize yourself with it.

Be sure to check out the Common Lisp Cookbook as well, it's often a bit
easier to follow at least initially.

Re: how to map a variable to a list?

<u18kne$btq7$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jszhao@yeah.net (Jinsong Zhao)
Newsgroups: comp.lang.lisp
Subject: Re: how to map a variable to a list?
Date: Thu, 13 Apr 2023 18:14:39 +0800
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <u18kne$btq7$1@dont-email.me>
References: <u111j3$26d7d$1@dont-email.me>
<024bfbe6-8505-431f-b027-e958e37de174n@googlegroups.com>
<u16a4t$31ink$1@dont-email.me>
<182a38b4-b108-4762-97f5-535db02cf348n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 13 Apr 2023 10:15:10 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="93be51509379c374760dfc6c18a971bd";
logging-data="390983"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Bd4J58JsiEEdwFKOFPGLd"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.9.1
Cancel-Lock: sha1:ZtcJNXPsSCMCrEgJGZUROooUOZ4=
Content-Language: en-US
In-Reply-To: <182a38b4-b108-4762-97f5-535db02cf348n@googlegroups.com>
 by: Jinsong Zhao - Thu, 13 Apr 2023 10:14 UTC

On 2023/4/13 9:06, Tom Russ wrote:
> On Wednesday, April 12, 2023 at 6:02:29 AM UTC-7, Jinsong Zhao wrote:
>> Thanks a lot for all your replies. DESTRUCTURING-BIND is what I want.
>
> Out of curiosity, what is an example of the code that you want to write?
>
> I ask because I wonder if a struct would be a better data structure than a list.
>
The list in my sample code is the size of the different sections decoded
from the binary header. Mapping them to locally named variables makes it
easy to check the validity of the file. Because it is only used once,
structure is perhaps too heavy. Also, there are rumors that structure is
obsolete and class should be used, which I am even less familiar with.

Thanks again for the reply and helps.

Best,
Jinsong

Re: how to map a variable to a list?

<nFiJYxTO0FX2FXr4a@bongo-ra.co>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spibou@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.lisp
Subject: Re: how to map a variable to a list?
Date: Thu, 13 Apr 2023 10:55:06 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <nFiJYxTO0FX2FXr4a@bongo-ra.co>
References: <u111j3$26d7d$1@dont-email.me> <024bfbe6-8505-431f-b027-e958e37de174n@googlegroups.com> <u16a4t$31ink$1@dont-email.me>
<182a38b4-b108-4762-97f5-535db02cf348n@googlegroups.com> <u18kne$btq7$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 13 Apr 2023 10:55:06 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8fc36f9bc329dc1d3f8ef5d8a1390c54";
logging-data="444663"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/6q8x8vZ7ZE1oX+A3ctDY+"
Cancel-Lock: sha1:YPdF1aZlyR4X0WW4wvxkPw8aJSs=
In-Reply-To: <u18kne$btq7$1@dont-email.me>
X-Server-Commands: nowebcancel
X-Organisation: Weyland-Yutani
 by: Spiros Bousbouras - Thu, 13 Apr 2023 10:55 UTC

On Thu, 13 Apr 2023 18:14:39 +0800
Jinsong Zhao <jszhao@yeah.net> wrote:
> The list in my sample code is the size of the different sections decoded
> from the binary header. Mapping them to locally named variables makes it
> easy to check the validity of the file. Because it is only used once,
> structure is perhaps too heavy.

Perhaps. Without knowing how the list gets created to begin with , it is
impossible to tell.

> Also, there are rumors that structure is
> obsolete and class should be used, which I am even less familiar with.

I don't know where you heard the "rumours" but they are wrong. Main
differences between classes and structures :

Classes Structures

Support multiple
inheritance YES NO

Can be redefined YES NO ; undefined
behaviour if you attempt
to do so.

So classes offer greater flexibility at the cost of execution speed
although I don't think it would cost too much in execution speed
if structures also offered multiple inheritance.

With structures you also get automatically defined accessors , print methods
and copier functions ; you can optionally define the layout to be a vector or
a list but then the structure does not become a new type in the CL type
system but counts as a vector or list respectively.

--
If it was a Bill Clinton day, the dry cleaners could have a special on removing
stains.
Mark O'Brien
http://www.stonekettle.com/2016/02/presidents-daze.html

Re: how to map a variable to a list?

<yQh74C70zllWtISq0@bongo-ra.co>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spibou@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.lisp
Subject: Re: how to map a variable to a list?
Date: Fri, 14 Apr 2023 02:34:19 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <yQh74C70zllWtISq0@bongo-ra.co>
References: <u111j3$26d7d$1@dont-email.me> <024bfbe6-8505-431f-b027-e958e37de174n@googlegroups.com> <u16a4t$31ink$1@dont-email.me>
<182a38b4-b108-4762-97f5-535db02cf348n@googlegroups.com> <u18kne$btq7$1@dont-email.me> <nFiJYxTO0FX2FXr4a@bongo-ra.co>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 14 Apr 2023 02:34:19 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="14131ab812d4b11cc708a4f96ec22832";
logging-data="1421915"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19eLFpF9ZaErSx6dN3vvVDJ"
Cancel-Lock: sha1:dfZRTsq8AzDXMht5V4bOFdVo8w8=
X-Organisation: Weyland-Yutani
In-Reply-To: <nFiJYxTO0FX2FXr4a@bongo-ra.co>
X-Server-Commands: nowebcancel
 by: Spiros Bousbouras - Fri, 14 Apr 2023 02:34 UTC

On Thu, 13 Apr 2023 10:55:06 -0000 (UTC)
Spiros Bousbouras <spibou@gmail.com> wrote:
> On Thu, 13 Apr 2023 18:14:39 +0800
> Jinsong Zhao <jszhao@yeah.net> wrote:
> > Also, there are rumors that structure is
> > obsolete and class should be used, which I am even less familiar with.
>
> I don't know where you heard the "rumours" but they are wrong. Main
> differences between classes and structures :
>
> Classes Structures
>
> Support multiple
> inheritance YES NO
>
>
> Can be redefined YES NO ; undefined
> behaviour if you attempt
> to do so.
>
>
> So classes offer greater flexibility at the cost of execution speed
> although I don't think it would cost too much in execution speed
> if structures also offered multiple inheritance.
>
> With structures you also get automatically defined accessors , print methods
> and copier functions ; you can optionally define the layout to be a vector or
> a list but then the structure does not become a new type in the CL type
> system but counts as a vector or list respectively.

Also the accessors in structures are regular functions whereas in classes they
are generic functions. So again , you get greater flexibility with classes at
the cost of execution speed. So structures and classes offer different
tradeoffs and neither one is going away , even without taking into account
backwards compatibility.

Re: how to map a variable to a list?

<87bk6580g5.fsf@gmail.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!border-3.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: Fri, 19 Apr 2024 22:14:19 +0000
From: sgonedes1977@gmail.com (steve)
Newsgroups: comp.lang.lisp
Subject: Re: how to map a variable to a list?
References: <u111j3$26d7d$1@dont-email.me> <O5sf1cOqAlzNMgIN7@bongo-ra.co>
Date: Fri, 19 Apr 2024 18:14:18 -0400
Message-ID: <87bk6580g5.fsf@gmail.com>
Organization: 
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:XjtrKL89Hub9zVcBHOPnwsx9eI8=
MIME-Version: 1.0
Content-Type: text/plain
Lines: 45
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-sICnUAArwJ/MxVMfoyuZS7cuTSMStYwcSbWTBUCpxxPNZgVqNBuNkS61LKMcc9hWsjvaRR8T8X3iexw!Gp9D4L2r+9lBAHJ/8ZJHzKfkuXM1OozhRT1W7fbYQknR4A==
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: steve - Fri, 19 Apr 2024 22:14 UTC

Spiros Bousbouras <spibou@gmail.com> writes:

< On Mon, 10 Apr 2023 21:05:23 +0800
< Jinsong Zhao <jszhao@yeah.net> wrote:
>> Hi there,
>>
>> In the following code example,
>>
>> (defun a-test (lst)
>> (let ((a (elt lst 0))
>> (b (elt lst 1))
>> (c (elt lst 2)))
>> (+ a (- c b))))
>>
>> How to map local variable a, b, and c to the elements of lst? In my
>> actual code, the lst have 12 elements, and I have 12 named local
>> variables that appeared in the body with high frequency.

< Why is the above code not satisfactory ?

no idea, works for me.

(defun a-test (lst)
(let ((a (pop lst))
(b (pop lst))
(c (pop lst)))
(+ a (- c b))))

(a-test '(3 5 7))

(defun a-test2 (lst)
(let ((a (elt lst 0))
(b (elt lst 1))
(c (elt lst 2)))
(+ a (- c b))))

(a-test2 '(1 4 7))

show the code? might be helpful. 12 variables can be done with reduce
mapcar, depending on the operation.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor