Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #257: That would be because the software doesn't work.


comp / comp.lang.lisp / Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1

SubjectAuthor
* Given string 'a.bc.' -- replace each dot(.) with 0 or 1HenHanna
+- Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1Kaz Kylheku
+* Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1Kaz Kylheku
|+- Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1steve
|`- Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1Kaz Kylheku
+* Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1Madhu
|`* Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1steve
| `* Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1Madhu
|  `- Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1steve
+- Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1steve
+* Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1Joerg Mertens
|`* Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1HenHanna
| `* Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1Madhu
|  `* Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1steve
|   `* Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1Lawrence D'Oliveiro
|    `* Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1Madhu
|     `- Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1steve
+* Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1WJ
|+- Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1HenHanna
|`- Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1Madhu
+- Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1Mark Wooding
`- Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1B. Pym

1
Subject: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: HenHanna
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sat, 18 May 2024 08:31 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: comp.lang.lisp
Subject: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
Date: Sat, 18 May 2024 01:31:32 -0700
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <v29p14$2mr5l$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 18 May 2024 10:31:33 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7c7ccf8d8ecc9b5171c5fa73857bd316";
logging-data="2845877"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+78RDE4Z5X7K1RhbvBfWwFsSoXlYT1IBo="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:xlJ7WU6mg0s1nIK2ZmI1l4mK7E0=
Content-Language: en-US
View all headers

How can i write this function simply? (in Common Lisp)

-- Given a string 'a.bc.' -- replace each dot(.) with 0 or 1.

-- So the value is a list of 4 strings:
('a0bc0' 'a0bc1' 'a1bc0' 'a1bc1')

-- The order is not important.
If the string has 3 dots, the value is a list of length 8.

If the program is going to be simpler,
pls use, e.g. (a $ b c $) rather than 'a.bc.'

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: Kaz Kylheku
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sat, 18 May 2024 20:50 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
Date: Sat, 18 May 2024 20:50:46 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <20240518081354.270@kylheku.com>
References: <v29p14$2mr5l$2@dont-email.me>
Injection-Date: Sat, 18 May 2024 22:50:46 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="e91c99aee57c8d742a6a3dcafbf58b79";
logging-data="3116169"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18nXA/HMGEpI/cPUNp632JVgsKemxg1Vls="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:TEPuTqa4nqNUAvyGV30VrdJVYpE=
View all headers

On 2024-05-18, HenHanna <HenHanna@devnull.tb> wrote:
> If the program is going to be simpler,
> pls use, e.g. (a $ b c $) rather than 'a.bc.'

Yes, the program can almost always be made simpler if you're free to
redefine the details of problem to suit your programming language.

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

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: Kaz Kylheku
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sat, 18 May 2024 21:06 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
Date: Sat, 18 May 2024 21:06:16 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <20240518140005.921@kylheku.com>
References: <v29p14$2mr5l$2@dont-email.me>
Injection-Date: Sat, 18 May 2024 23:06:17 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="e91c99aee57c8d742a6a3dcafbf58b79";
logging-data="3121327"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19KqGnOCaOwucsTppAHFNir7ThKOkxnoxU="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:Iiz6xh5YzsNzcJoB2yucTgLCww8=
View all headers

On 2024-05-18, HenHanna <HenHanna@devnull.tb> wrote:
>
> How can i write this function simply? (in Common Lisp)
>
> -- Given a string 'a.bc.' -- replace each dot(.) with 0 or 1.
>
> -- So the value is a list of 4 strings:
> ('a0bc0' 'a0bc1' 'a1bc0' 'a1bc1')
>
> -- The order is not important.
> If the string has 3 dots, the value is a list of length 8.
>
> If the program is going to be simpler,
> pls use, e.g. (a $ b c $) rather than 'a.bc.'

TXR Lisp:

(defun bindots (str)
(let* ((s (copy str))
(ixs (where (op eql #\.) s))
(n (len ixs)))
(collect-each ((digs (rperm '(#\0 #\1) n)))
(set [s ixs] digs)
(copy s))))

1> (bindots "abc")
("abc")
2> (bindots "a.bc")
("a0bc" "a1bc")
3> (bindots "a.b.c")
("a0b0c" "a0b1c" "a1b0c" "a1b1c")
4> (bindots "a.b.cd.e")
("a0b0cd0e" "a0b0cd1e" "a0b1cd0e" "a0b1cd1e" "a1b0cd0e" "a1b0cd1e"
"a1b1cd0e" "a1b1cd1e")

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

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: Madhu
Newsgroups: comp.lang.lisp
Organization: Motzarella
Date: Sun, 19 May 2024 03:28 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: enometh@meer.net (Madhu)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
Date: Sun, 19 May 2024 08:58:05 +0530
Organization: Motzarella
Lines: 29
Message-ID: <m3jzjqlbui.fsf@leonis4.robolove.meer.net>
References: <v29p14$2mr5l$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Sun, 19 May 2024 05:28:09 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="f7e0dab84c851fdda1d301d784376436";
logging-data="3369303"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19bIdnGT20A8HCncktrgEr5HI5cj0199Kw="
Cancel-Lock: sha1:o1DO7O6P7Qino2jC6MU0OzL4xMs=
sha1:/WfrbR7AdB6TcnJRDhdVewP7X+0=
View all headers

* HenHanna <v29p14$2mr5l$2@dont-email.me> :
Wrote on Sat, 18 May 2024 01:31:32 -0700:

> How can i write this function simply? (in Common Lisp)
>
> -- Given a string 'a.bc.' -- replace each dot(.) with 0 or 1.
>
> -- So the value is a list of 4 strings:
> ('a0bc0' 'a0bc1' 'a1bc0' 'a1bc1')

(defun adjusted-logbitp (pos num total-width)
(let* ((int-len (integer-length num))
(i (- pos (- total-width int-len))))
(if (< i 0)
nil
(logbitp i num))))

(defun bindots (str)
(let* ((indices (loop for c across str for i from 0
if (eql c #\.) collect i))
(width (length indices)))
(loop for i below (expt 2 width)
collect (let ((ret (copy-seq str)))
(loop for j in indices
do (setf (aref ret j)
(if (adjusted-logbitp j i width)
#\1
#\0)))
ret))))

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: steve
Newsgroups: comp.lang.lisp
Date: Sun, 19 May 2024 06:02 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-1.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: Sun, 19 May 2024 06:03:01 +0000
From: sgonedes1977@gmail.com (steve)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
References: <v29p14$2mr5l$2@dont-email.me>
Date: Sun, 19 May 2024 02:02:55 -0400
Message-ID: <87o792ibjk.fsf@gmail.com>
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:DxPeNg3t98aKd55/ydN1euNy1zE=
MIME-Version: 1.0
Content-Type: text/plain
Lines: 24
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-sy5/7EjzhUPtIQYjv14XUe3P/l3ltQHNXWhoC0nu6GpgPX/GMrYvBNKO3X4nhMKfIUdQZUmVr+5WvPl!y8o89CD9oQnfwWHuXMAeFGMMlQvR7a9Dnn7Xa85KQoH01A==
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
View all headers

HenHanna <HenHanna@devnull.tb> writes:

> How can i write this function simply? (in Common Lisp)
>
> -- Given a string 'a.bc.' -- replace each dot(.) with 0 or 1.
>
> -- So the value is a list of 4 strings:
> ('a0bc0' 'a0bc1' 'a1bc0' 'a1bc1')
>
> -- The order is not important.
> If the string has 3 dots, the value is a list of length 8.
>
> If the program is going to be simpler,
> pls use, e.g. (a $ b c $) rather than 'a.bc.'

; SLIME 2.26.1
CL-USER> (defun replace-dots (str)
(declare (string str))
(substitute #\1 #\. str))
REPLACE-DOTS
CL-USER> (replace-dots "this.a.bd.")
"this1a1bd1"
CL-USER>

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: steve
Newsgroups: comp.lang.lisp
Date: Sun, 19 May 2024 06:06 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-4.nntp.ord.giganews.com!border-1.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 19 May 2024 06:06:15 +0000
From: sgonedes1977@gmail.com (steve)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
References: <v29p14$2mr5l$2@dont-email.me>
<m3jzjqlbui.fsf@leonis4.robolove.meer.net>
Date: Sun, 19 May 2024 02:06:15 -0400
Message-ID: <87frueibe0.fsf@gmail.com>
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:fdwsoqwbdqRWEkrZ0Bl6hrSOyqU=
MIME-Version: 1.0
Content-Type: text/plain
Lines: 33
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-E3assmZ/jG3sK/We6SebW1sBXmQdfvxEgQiCOuba2HLW8rQpWP/ObKQwJoUXSFvl6/ymXACfXfX42/3!U7FK17917RbSpXOQKGZR5r0goq1SBRWl2a1XVE/4hUNs2Q==
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
View all headers

Madhu <enometh@meer.net> writes:

> * HenHanna <v29p14$2mr5l$2@dont-email.me> :
> Wrote on Sat, 18 May 2024 01:31:32 -0700:
>
< > How can i write this function simply? (in Common Lisp)
< >
< > -- Given a string 'a.bc.' -- replace each dot(.) with 0 or 1.
< >
< > -- So the value is a list of 4 strings:
< > ('a0bc0' 'a0bc1' 'a1bc0' 'a1bc1')
>
> (defun adjusted-logbitp (pos num total-width)
> (let* ((int-len (integer-length num))
> (i (- pos (- total-width int-len))))
> (if (< i 0)
> nil
> (logbitp i num))))
>
> (defun bindots (str)
> (let* ((indices (loop for c across str for i from 0
> if (eql c #\.) collect i))
> (width (length indices)))
> (loop for i below (expt 2 width)
> collect (let ((ret (copy-seq str)))
> (loop for j in indices
> do (setf (aref ret j)
> (if (adjusted-logbitp j i width)
> #\1
> #\0)))
> ret))))

what about substitute? common lisp is not scheme of the week.

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: steve
Newsgroups: comp.lang.lisp
Date: Sun, 19 May 2024 06:05 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-3.nntp.ord.giganews.com!border-1.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 19 May 2024 06:05:13 +0000
From: sgonedes1977@gmail.com (steve)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
References: <v29p14$2mr5l$2@dont-email.me> <20240518140005.921@kylheku.com>
Date: Sun, 19 May 2024 02:05:13 -0400
Message-ID: <87jzjqibfq.fsf@gmail.com>
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:4kzxCBkqJortSrAVJe9yhdn6wqc=
MIME-Version: 1.0
Content-Type: text/plain
Lines: 31
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-PenhfpygdPQ4BpMgHYE10/SC946Imatn/6qbiVi0DszLggg9zyEI8Ra8um6Lfm7Y6UUZaD9AtM+gxDi!2P+qbrAXGNpKM2EaesRXL8sJSih3gFyK5Fw/Wg9gVcJwng==
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
View all headers

Kaz Kylheku <643-408-1753@kylheku.com> writes:

> On 2024-05-18, HenHanna <HenHanna@devnull.tb> wrote:
< >
< > How can i write this function simply? (in Common Lisp)
< >
< > -- Given a string 'a.bc.' -- replace each dot(.) with 0 or 1.
< >
< > -- So the value is a list of 4 strings:
< > ('a0bc0' 'a0bc1' 'a1bc0' 'a1bc1')
< >
< > -- The order is not important.
< > If the string has 3 dots, the value is a list of length 8.
< >
< > If the program is going to be simpler,
< > pls use, e.g. (a $ b c $) rather than 'a.bc.'
>
> TXR Lisp:
>
> (defun bindots (str)
> (let* ((s (copy str))
> (ixs (where (op eql #\.) s))
> (n (len ixs)))
> (collect-each ((digs (rperm '(#\0 #\1) n)))
> (set [s ixs] digs)
> (copy s))))

where is collect-each in common lisp?
set [x] is no good! not in lisp

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: Madhu
Newsgroups: comp.lang.lisp
Organization: Motzarella
Date: Sun, 19 May 2024 12:36 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: enometh@meer.net (Madhu)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
Date: Sun, 19 May 2024 18:06:53 +0530
Organization: Motzarella
Lines: 21
Message-ID: <m3bk52kmfu.fsf@leonis4.robolove.meer.net>
References: <v29p14$2mr5l$2@dont-email.me>
<m3jzjqlbui.fsf@leonis4.robolove.meer.net> <87frueibe0.fsf@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Sun, 19 May 2024 14:36:55 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="a14a2295a5bd2f9a1d65e459281bd93e";
logging-data="3560630"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/AA1x3lDzDa0KRSewV/4AJv97x+6DQ8Ok="
Cancel-Lock: sha1:KSRxsLUw3bev+4kMiloLKPE/DfI=
sha1:M9FVZr36LwVtzZ6PaW1ONm2o+VQ=
View all headers

* steve <87frueibe0.fsf@gmail.com> :
Wrote on Sun, 19 May 2024 02:06:15 -0400:
>> (defun bindots (str)
>> (let* ((indices (loop for c across str for i from 0
>> if (eql c #\.) collect i))
>> (width (length indices)))
>> (loop for i below (expt 2 width)
>> collect (let ((ret (copy-seq str)))
>> (loop for j in indices
>> do (setf (aref ret j)
>> (if (adjusted-logbitp j i width)
>> #\1
>> #\0)))
>> ret))))
>
> what about substitute? common lisp is not scheme of the week.

Substitute doesn't help here, you want to mutate specific locations in
each string to produce a "combinatorial" result.

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: Joerg Mertens
Newsgroups: comp.lang.lisp
Organization: privat
Date: Sun, 19 May 2024 18:36 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!jmertens.eternal-september.org!.POSTED!not-for-mail
From: joerg-mertens@t-online.de (Joerg Mertens)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
Date: Sun, 19 May 2024 20:36:23 +0200
Organization: privat
Lines: 26
Message-ID: <87h6et8x94.fsf@jmertens.eternal-september.org>
References: <v29p14$2mr5l$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Sun, 19 May 2024 20:39:17 +0200 (CEST)
Injection-Info: jmertens.eternal-september.org; posting-host="997bb4aa90cad0b651257e6ee596cbe4";
logging-data="3700039"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/mGpLdaOZH968+PvvytbkkFXS4wOqK7+k="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:eyFnjsW1EmGucJ9YWkkpbzgoCGY=
sha1:L0lyt8Mp4oG7GEsJohrpogEYe/w=
View all headers

HenHanna <HenHanna@devnull.tb> writes:

> How can i write this function simply? (in Common Lisp)
>
> -- Given a string 'a.bc.' -- replace each dot(.) with 0 or 1.
>
> -- So the value is a list of 4 strings:
> ('a0bc0' 'a0bc1' 'a1bc0' 'a1bc1')
>
> -- The order is not important.
> If the string has 3 dots, the value is a list of length 8.
>
> If the program is going to be simpler,
> pls use, e.g. (a $ b c $) rather than 'a.bc.'

Another one:

(defun subst-dots (s &optional (pos 0))
(let ((p (search "." s :start2 pos)))
(if p
(append
(subst-dots (replace (copy-seq s) "0" :start1 p) (1+ p))
(subst-dots (replace (copy-seq s) "1" :start1 p) (1+ p)))
(list s))))

Regards

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: Kaz Kylheku
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sun, 19 May 2024 19:56 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
Date: Sun, 19 May 2024 19:56:35 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 161
Message-ID: <20240519121441.337@kylheku.com>
References: <v29p14$2mr5l$2@dont-email.me> <20240518140005.921@kylheku.com>
Injection-Date: Sun, 19 May 2024 21:56:36 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="51aa926811f3eee5d2771c560ded4f5e";
logging-data="3731370"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mXczEYIwKr8QuAf6jpxG6gdiFD2T1jCc="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:RCQwxwJUfv6EgdcxGhPnA2+HBAw=
View all headers

On 2024-05-18, Kaz Kylheku <643-408-1753@kylheku.com> wrote:
> On 2024-05-18, HenHanna <HenHanna@devnull.tb> wrote:
>>
>> How can i write this function simply? (in Common Lisp)
>>
>> -- Given a string 'a.bc.' -- replace each dot(.) with 0 or 1.
>>
>> -- So the value is a list of 4 strings:
>> ('a0bc0' 'a0bc1' 'a1bc0' 'a1bc1')
>>
>> -- The order is not important.
>> If the string has 3 dots, the value is a list of length 8.
>>
>> If the program is going to be simpler,
>> pls use, e.g. (a $ b c $) rather than 'a.bc.'
>
> TXR Lisp:
>
> (defun bindots (str)
> (let* ((s (copy str))
> (ixs (where (op eql #\.) s))
> (n (len ixs)))
> (collect-each ((digs (rperm '(#\0 #\1) n)))
> (set [s ixs] digs)
> (copy s))))

Using format. I.e. transform an input string like "a.b~c.d.e" into
the format string "a~ab~~c~ad~ae", and then feed it the digit
permutations as arguments, which can now be integers:

(defun bindots (str)
(let* ((n (countql #\. str))
(fs (flow str
(regsub "~" "~~")
(regsub "." "~a"))))
(collect-each ((digs (rperm '(0 1) n)))
(fmt fs . digs))))

Doh, why stick to the collect-each copy paste; it's a mapcar job:

(defun bindots (str)
(let* ((n (countql #\. str))
(fs (flow str
(regsub "~" "~~")
(regsub "." "~a"))))
(mapcar (ap fmt fs) (rperm '(0 1) n))))

Use flow syntax for the whole body:

(defun bindots (str)
(flow str
(regsub "~" "~~")
(regsub "." "~a")
(mapcar (ap fmt @@1) (rperm '(0 1) (countql #\. str)))))

Why @@1? (ap fmt @1) would refer to the ap expression's own parameter 1. @@1
escapes one level out to access the (mapcar ...) expression's implicit
parameter 1, which is the prepared format string coming out of the previous
regsub.

The op syntax, inspired the op operator in MIT Goo, has a fully
developed argument referencing system that supports nesting,
reminiscent of nested commas in backquotes.

Whenver an op expression explicitly refers to parameter material
using @1, @2, ... or @rest, this has the effect of suppressing
the insertion of the implicit rightmost parameter @1, the idea
being that the expression is taking full control over what arguments are
inserted where.

Thus because @@1 mentions an implicit parameter of the mapcar
expression, that expression no longer receives an implicit rightmost
argument. We want this, because otherwise the format string object
from the previous regsub pipeline element would appear as an extra
sequence for mapcar to traverse.

Instead of rperm, we could also count up to below (expt 2 n),
and then use digits to explode digits, like this.
Ah, right but no, because we don't get leading zeros. I will
still mention this:

1> (mapcar (lop digits 2) 0..16)
((0) (1) (1 0) (1 1) (1 0 0) (1 0 1) (1 1 0) (1 1 1) (1 0 0 0)
(1 0 0 1) (1 0 1 0) (1 0 1 1) (1 1 0 0) (1 1 0 1) (1 1 1 0) (1 1 1 1))

In TXR, I have moved toward generic iteration. Most of the library
is converted.

Actually since now ancient history, sequences other than list have been
traversable with car and cdr, and still are. But that convenience is
inefficient due to copying.

There is an iteration system which works like this:

1> (iter-begin '(a b c))
(a b c)
2> (iter-more *1)
t 3> (iter-item *1)
a 4> (iter-step *1)
(b c)
5> (iter-begin "abc")
#<seq-iter: 85d75f0>
6> (iter-more *5)
t 7> (iter-item *5)
#\a
8> (iter-step *5)
#<seq-iter: 85d75f0>
9> (iter-item *5)
#\b

Iterators can be functional or stateful, so the return value of iter-step must
be captured.

Above, (iter-begin "abc") produces a heap object, whereas (iter-begin '(a b c))
just returns (a b c).

mapcar efficiently allocates the iterator objects on the stack. In that case,
list iteration uses an iterator object also; it's not just using the list
as an iterator.

The public function iter-begin performs this optimization whereby for certain
objects, an iteration object need not be constructed, because iter-more,
iter-item and iter-step can handle the original representation.

E.g. infinitely iterate from 3:

1> (iter-begin 3) ;; identity
3 2> (iter-more *1) ;; unconditional true
t 3> (iter-item *1) ;; identity
3 4> (iter-step *1) ;; successor function
4

Since numbers are iterable, we can easily add numbering in
a mapcar, just by mentioning a number as one of the sequence
arguments.

1> (mapcar (do pic `>>:0#` @1 @2) "AA".."DD" 0)
("AA:00" "AB:01" "AC:02" "AD:03" "BA:04" "BB:05" "BC:06" "BD:07"
"CA:08" "CB:09" "CC:10" "CD:11" "DA:12" "DB:13" "DC:14" "DD:15")

do is the variant of op which handles macros rather than functions.

The pipelining opip (basis of flow macro) automatically applies do or
op to the pipeline elements based on whether they have an operator
or function binding. Thus we can do

(flow whatever (mapcar ...) (if ...) (progn ..))

The mapcar will be treated as an (op mapcar ...) the if and progn
as (do if ...) and (do progn ...).

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

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: HenHanna
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Tue, 21 May 2024 19:09 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
Date: Tue, 21 May 2024 12:09:22 -0700
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <v2irh1$ndjr$2@dont-email.me>
References: <v29p14$2mr5l$2@dont-email.me>
<87h6et8x94.fsf@jmertens.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 21 May 2024 21:09:22 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="4ee11fe942d496548c5fef5d03dc9b69";
logging-data="767611"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+QQ1SXBL5nJwXXQyk/Jf7YS1irc1yNukE="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:N8XZCcb0ifYhjVNKydnnqLB/cEs=
In-Reply-To: <87h6et8x94.fsf@jmertens.eternal-september.org>
Content-Language: en-US
View all headers

On 5/19/2024 11:36 AM, Joerg Mertens wrote:
> HenHanna <HenHanna@devnull.tb> writes:
>
>> How can i write this function simply? (in Common Lisp)
>>
>> -- Given a string 'a.bc.' -- replace each dot(.) with 0 or 1.
>>
>> -- So the value is a list of 4 strings:
>> ('a0bc0' 'a0bc1' 'a1bc0' 'a1bc1')
>>
>> -- The order is not important.
>> If the string has 3 dots, the value is a list of length 8.
>>
>> If the program is going to be simpler,
>> pls use, e.g. (a $ b c $) rather than 'a.bc.'

>
> Another one:
>
> (defun subst-dots (s &optional (pos 0))
> (let ((p (search "." s :start2 pos)))
> (if p
> (append
> (subst-dots (replace (copy-seq s) "0" :start1 p) (1+ p))
> (subst-dots (replace (copy-seq s) "1" :start1 p) (1+ p)))
> (list s))))
>
> Regards

Nice... Thanks !

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: Madhu
Newsgroups: comp.lang.lisp
Organization: Motzarella
Date: Wed, 22 May 2024 02:43 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: enometh@meer.net (Madhu)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
Date: Wed, 22 May 2024 08:13:09 +0530
Organization: Motzarella
Lines: 47
Message-ID: <m3zfsish1e.fsf@leonis4.robolove.meer.net>
References: <v29p14$2mr5l$2@dont-email.me>
<87h6et8x94.fsf@jmertens.eternal-september.org>
<v2irh1$ndjr$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Wed, 22 May 2024 04:43:11 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="8102e1f87c52442c364520b4a73a0af5";
logging-data="1053485"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19EeNqzPkVq3f5PBlVzabDzfb7OKMhuSbw="
Cancel-Lock: sha1:hBxykRUrmDI9cDRXHzYr26PLvBg=
sha1:R8sZ2w9vUtu4H2IQ//DYP7YqqNs=
View all headers

* HenHanna <v2irh1$ndjr$2@dont-email.me> :
Wrote on Tue, 21 May 2024 12:09:22 -0700:
> On 5/19/2024 11:36 AM, Joerg Mertens wrote:
>> HenHanna <HenHanna@devnull.tb> writes:
>>
>>> How can i write this function simply? (in Common Lisp)
>>>
>>> -- Given a string 'a.bc.' -- replace each dot(.) with 0 or 1.
>>>
>>> -- So the value is a list of 4 strings:
>>> ('a0bc0' 'a0bc1' 'a1bc0' 'a1bc1')
>>>
>>> -- The order is not important.
>>> If the string has 3 dots, the value is a list of length 8.
>>>
>>> If the program is going to be simpler,
>>> pls use, e.g. (a $ b c $) rather than 'a.bc.'
>
>
>> Another one:
>> (defun subst-dots (s &optional (pos 0))
>> (let ((p (search "." s :start2 pos)))
>> (if p
>> (append
>> (subst-dots (replace (copy-seq s) "0" :start1 p) (1+ p))
>> (subst-dots (replace (copy-seq s) "1" :start1 p) (1+ p)))
>> (list s))))
>> Regards
> Nice... Thanks

so my response to Steve in <m3bk52kmfu.fsf@leonis4.robolove.meer.net> :
on [Sun, 19 May 2024 18:06:53 +0530] where I said "Substitute doesn't
help here" was wrong. You can use SUBSTITUTE here like this

(defun subst-dots (s &optional (pos 0))
(let ((p (search "." s :start2 pos)))
(if p
(append
(subst-dots (substitute #\0 #\. s :start p :count 1) (1+ p))
(subst-dots (substitute #\1 #\. s :start p :count 1) (1+ p)))
(list s))))

[Apparently my machine crashed shortly after I sent that message and zfs
didn't help preserve it - I don't have a copy of it under
Mail/archive/sent ]

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: WJ
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Fri, 24 May 2024 12:54 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: w_a_x_man@yahoo.com (WJ)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
Date: Fri, 24 May 2024 12:54:41 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <v2q2mg$2b3ru$1@dont-email.me>
References: <v29p14$2mr5l$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Injection-Date: Fri, 24 May 2024 14:54:42 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="6387fa60ce5b8307389d60cf9eb6ce4f";
logging-data="2461566"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18vSfSMG/LK7DSeGo64moxr"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:30eOjLzkjhUZR39CDOf6U1OnRCQ=
View all headers

On 5/18/2024, HenHanna wrote:

>
> How can i write this function simply? (in Common Lisp)
>
> -- Given a string 'a.bc.' -- replace each dot(.) with 0 or 1.
>
> -- So the value is a list of 4 strings:
> ('a0bc0' 'a0bc1' 'a1bc0' 'a1bc1')
>
> -- The order is not important.
> If the string has 3 dots, the value is a list of length 8.
>
> If the program is going to be simpler,
> pls use, e.g. (a $ b c $) rather than 'a.bc.'

Gauche Scheme:

(define (dotty s)
(define (f r) (dotty (regexp-replace "[.]" s r)))
(if (string-scan s #\.)
(apply append (map f '("0" "1")))
(list s)))

gosh> (dotty "a.b.c")
("a0b0c" "a0b1c" "a1b0c" "a1b1c")

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: Mark Wooding
Newsgroups: comp.lang.lisp
Date: Fri, 24 May 2024 16:27 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.gegeweb.eu!gegeweb.org!nntp.terraraq.uk!nntp-feed.chiark.greenend.org.uk!ewrotcd!.POSTED.chiark.greenend.org.uk!not-for-mail
From: markw@distorted.org.uk (Mark Wooding)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
Date: Fri, 24 May 2024 17:27:28 +0100
Message-ID: <864jandvkf.fsf.markw@stratocaster.distorted.org.uk>
References: <v29p14$2mr5l$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: chiark.greenend.org.uk; posting-host="chiark.greenend.org.uk:93.93.131.173";
logging-data="13400"; mail-complaints-to="abuse@chiark.greenend.org.uk"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
Cancel-Lock: sha1:MNq6v7eZ4bLkjo/0/uwZJdvgDlY=
Originator: markw@stratocaster.unsafe.distorted.org.uk ([172.29.199.9])
View all headers

HenHanna <HenHanna@devnull.tb> writes:

> How can i write this function simply? (in Common Lisp)
>
> -- Given a string 'a.bc.' -- replace each dot(.) with 0 or 1.
>
> -- So the value is a list of 4 strings:
> ('a0bc0' 'a0bc1' 'a1bc0' 'a1bc1')
>
> -- The order is not important.
> If the string has 3 dots, the value is a list of length 8.

Oh, all right. I'll bite.

(defun replace-dots (string &key (start 0) end)
(unless end (setf end (length string)))
(let ((dots (make-array 16
:element-type 'fixnum
:adjustable t
:fill-pointer 0))
(string (copy-seq string)))

(do ((pos (position #\. string :start start :end end)
(position #\. string :start (1+ pos) :end end)))
((null pos))
(vector-push-extend pos dots))

(let* ((ndots (length dots))
(niter (ash 1 ndots))
(list nil))
(dotimes (i ndots)
(setf (char string (aref dots i)) #\0))
(push (copy-seq string) list)
(do ((i 1 (1+ i)))
((>= i niter))
(let* ((k (1- (integer-length (logand i (- i)))))
(dot (aref dots k)))
(setf (char string dot)
(code-char (logxor (char-code (char string dot))
#.(logxor (char-code #\0)
(char-code #\1)))))
(push (copy-seq string) list)))

list)))

Now that I look again, I see that you asked for `simple'. I fail at
that. But it's nonrecursive, and, perhaps, an interesting approach.

-- [mdw]

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: HenHanna
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sat, 25 May 2024 10:06 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
Date: Sat, 25 May 2024 03:06:16 -0700
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <v2sd6p$2qqmv$1@dont-email.me>
References: <v29p14$2mr5l$2@dont-email.me> <v2q2mg$2b3ru$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 25 May 2024 12:06:17 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="bbc8dc7c954839fdde821ddc918e33bb";
logging-data="2976479"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/z/uce/+lGL/FLUyavNkhnJ380mUoreHo="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:DGX+TLCEaXgQzuVsBF24w7iihCU=
Content-Language: en-US
In-Reply-To: <v2q2mg$2b3ru$1@dont-email.me>
View all headers

On 5/24/2024 5:54 AM, WJ wrote:
> On 5/18/2024, HenHanna wrote:
>
>>
>> How can i write this function simply? (in Common Lisp)
>>
>> -- Given a string 'a.bc.' -- replace each dot(.) with 0 or 1.
>>
>> -- So the value is a list of 4 strings:
>> ('a0bc0' 'a0bc1' 'a1bc0' 'a1bc1')
>>
>> -- The order is not important.
>> If the string has 3 dots, the value is a list of length 8.
>>
>> If the program is going to be simpler,
>> pls use, e.g. (a $ b c $) rather than 'a.bc.'
>
> Gauche Scheme:
>
> (define (dotty s)
> (define (f r) (dotty (regexp-replace "[.]" s r)))
> (if (string-scan s #\.)
> (apply append (map f '("0" "1")))
> (list s)))
>
>
> gosh> (dotty "a.b.c")
> ("a0b0c" "a0b1c" "a1b0c" "a1b1c")
>
>

nice... The description "a Lisp Haiku" seems appropriate
(since i don't fully get how it works)

i've not seen that style before... what else would you write in that
style? Permutation? Combination? Cartesian-Power?

here's a slight rewrite. I'd never used map! before today.

(use scheme.list)
(define (dotty x)
(if (string-scan x #\.)
(map! (lambda (d) (dotty (regexp-replace "[.]" x d)))
(list "0" "1"))
(list x)))

oh..Ok..i still need to do Apply-Append
because map! is NOT (at all like) Mapcan

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sat, 25 May 2024 22:34 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
Date: Sat, 25 May 2024 22:34:43 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <v2tp1v$32lms$1@dont-email.me>
References: <v29p14$2mr5l$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Injection-Date: Sun, 26 May 2024 00:34:44 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="939f6aa088620cd756852c9d29b2960e";
logging-data="3233500"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8A2qLqs0lKhaqPPhdmG+8"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:pMYicB6iqefUj9D4s5SbzzTjliI=
View all headers

On 5/18/2024, HenHanna wrote:

> -- Given a string 'a.bc.' -- replace each dot(.) with 0 or 1.
>
> -- So the value is a list of 4 strings:
> ('a0bc0' 'a0bc1' 'a1bc0' 'a1bc1')
>
> -- The order is not important.
> If the string has 3 dots, the value is a list of length 8.

Gauche Scheme:

(use srfi-13) ;; string-count
(use util.combinations) ;; cartesian-product

(define (dot s)
(let ((b (cartesian-product (make-list (string-count s #\.) '(0 1))))
(fs (regexp-replace-all "[.]" s "~d")))
(map (cut apply format fs <>) b)))

(dot "a.b.c")
===>
("a0b0c" "a0b1c" "a1b0c" "a1b1c")

(dot "a.b")
===>
("a0b" "a1b")

(dot "ab.")
===>
("ab0" "ab1")

(dot ".ab")
===>
("0ab" "1ab")

(dot "ab")
===>
("ab")

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: Madhu
Newsgroups: comp.lang.lisp
Organization: Motzarella
Date: Sun, 26 May 2024 01:46 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: enometh@meer.net (Madhu)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
Date: Sun, 26 May 2024 07:16:38 +0530
Organization: Motzarella
Lines: 4
Message-ID: <m31q5pjqf5.fsf@leonis4.robolove.meer.net>
References: <v29p14$2mr5l$2@dont-email.me> <v2q2mg$2b3ru$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Sun, 26 May 2024 03:46:38 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="8a97e3e2baaa7def4cb0de04314e494c";
logging-data="3283317"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19r/rqJorUBPedPlC8fJn0JOafyjN8pC2I="
Cancel-Lock: sha1:04pYn5uAipZjlk9Bg7rgVs5FGt4=
sha1:4IAdlbrOkTl1AYLZO7GnC55V3PM=
X-No-Archive: yes
View all headers

* "WJ" <v2q2mg$2b3ru$1@dont-email.me> :
Wrote on Fri, 24 May 2024 12:54:41 -0000 (UTC):

welcome back!

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: steve
Newsgroups: comp.lang.lisp
Date: Wed, 29 May 2024 00:44 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-3.nntp.ord.giganews.com!border-1.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 29 May 2024 00:44:18 +0000
From: sgonedes1977@gmail.com (steve)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
References: <v29p14$2mr5l$2@dont-email.me>
<m3jzjqlbui.fsf@leonis4.robolove.meer.net> <87frueibe0.fsf@gmail.com>
<m3bk52kmfu.fsf@leonis4.robolove.meer.net>
Date: Tue, 28 May 2024 20:44:18 -0400
Message-ID: <87o78pqwf1.fsf@gmail.com>
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:G93fipdSH+00I2m6meEY8+0rAhw=
MIME-Version: 1.0
Content-Type: text/plain
Lines: 7
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-vvyuIYKFqO2BJJcZ0O3mKtqlZM/DVBReXB3EALNBaRCYHx2e9ldJRlKIkfvxh35gKUXR/a5BYbOuL1L!m3mBz0QlLyCxbhLOpoaxM8zhm8PpLOhqkMTDiBsK6Z9ALw==
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
View all headers

Madhu <enometh@meer.net> writes:

> Substitute doesn't help here, you want to mutate specific locations in
> each string to produce a "combinatorial" result.

how about Nsubstitute?

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: steve
Newsgroups: comp.lang.lisp
Date: Wed, 29 May 2024 01:06 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-2.nntp.ord.giganews.com!border-4.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: Wed, 29 May 2024 01:06:31 +0000
From: sgonedes1977@gmail.com (steve)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
References: <v29p14$2mr5l$2@dont-email.me>
<87h6et8x94.fsf@jmertens.eternal-september.org>
<v2irh1$ndjr$2@dont-email.me> <m3zfsish1e.fsf@leonis4.robolove.meer.net>
Date: Tue, 28 May 2024 21:06:31 -0400
Message-ID: <87jzjdqve0.fsf@gmail.com>
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:CdyK13WaAJQbvRIkQgZKtMhhOMo=
MIME-Version: 1.0
Content-Type: text/plain
Lines: 94
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-BIfIhFP79sYKekxLxXVoQoquP6ZIREGhxB4GRNNvo9TPacsk0RuM9MJUxg/3pGLdYahVBHnNtU/KXyV!dAvTqdaVhaB63kTbIQxYPAEcKZX9TTpu1r9rSdzVq0/qvw==
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
View all headers

Madhu <enometh@meer.net> writes:

> so my response to Steve in <m3bk52kmfu.fsf@leonis4.robolove.meer.net> :
> on [Sun, 19 May 2024 18:06:53 +0530] where I said "Substitute doesn't
> help here" was wrong. You can use SUBSTITUTE here like this
>
> (defun subst-dots (s &optional (pos 0))
> (let ((p (search "." s :start2 pos)))
> (if p
> (append
> (subst-dots (substitute #\0 #\. s :start p :count 1) (1+ p))
> (subst-dots (substitute #\1 #\. s :start p :count 1) (1+ p)))
> (list s))))
>
>
> [Apparently my machine crashed shortly after I sent that message and zfs
> didn't help preserve it - I don't have a copy of it under
> Mail/archive/sent ]

there is also mismatch and Nsubstitute. not very scheme-like but...

Here is some emacs lisp for common lisp..

(defun mapnconcat (fn sequences seperator)
"Like MAPCONCAT but the function is desctuctive."
(let ((seperator-length 0)
(total 0) (times -1) result)
(declare (fixnum seperator-length total times))
(unless (eq fn #'identity)
(map-into sequences fn sequences))
(setq seperator-length (the fixnum (length seperator)))
(dolist (seq sequences)
(incf times) (incf total (+ (length seq) seperator-length)))
(setq result (make-string (- total seperator-length)))
(let ((pos -1)) (declare (fixnum pos))
(loop repeat times do
(let ((seq (pop sequences)))
(loop for i across seq do
(setf (schar result (incf pos)) i))
(loop for i across seperator do
(setf (aref result (incf pos)) i))))
(loop for i across (car sequences) do
(setf (schar result (incf pos)) i)))
result))

(defun mapconcat (fn sequences seperator)
"Applies <FN> to each element of <SEQUENCES>; the results, which
must be sequences of characters (strings, vectors, or lists), are
concatenated into a single string return value. Between each pair of
result sequences, <mapconcat> inserts the characters from <SEPARATOR>,
which also must be a string, or a vector or list of characters."
(if (eq fn #'identity)
(mapnconcat fn sequences seperator)
(let ((result ""))
(dolist (seq (cdr sequences))
(setq result
(concatenate 'string
result seperator (funcall fn seq))))
(concatenate 'string (funcall fn (car sequences)) result))))

CL-USER>
; No value
CL-USER>
; No value
CL-USER> (mapconcat #'identity '("1234" "ff.ff" "255255") ".!")
"1234.!ff.ff.!255255"
CL-USER> (defun dot-to-ex (ch)
(if (eql ch #\.) #\_ ch))

DOT-TO-EX
;; this is no good for you

CL-USER> (mapconcat #'dot-to-ex '("1234" "ff.ff" "255255") ".!")
"1234.!ff.ff.!255255"
CL-USER> (mapconcat #'dot-to-ex '("1234" "ff.ff" "255255") ".")
"1234.ff.ff.255255"
CL-USER> (mapconcat #'dot-to-ex '("1234" "ff.ff" "255.255") ".")
"1234.ff.ff.255.255"

CL-USER> (defun dot-to-ex (ch)
(substitute #\_ #\. ch))

DOT-TO-EX
CL-USER> (mapconcat #'dot-to-ex '("1234" "ff.ff" "255.255") ".")
"1234.ff_ff.255_255"
CL-USER>

Have fun

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: Lawrence D'Oliv
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Wed, 29 May 2024 02:01 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
Date: Wed, 29 May 2024 02:01:50 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <v362ae$v652$2@dont-email.me>
References: <v29p14$2mr5l$2@dont-email.me>
<87h6et8x94.fsf@jmertens.eternal-september.org>
<v2irh1$ndjr$2@dont-email.me> <m3zfsish1e.fsf@leonis4.robolove.meer.net>
<87jzjdqve0.fsf@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 29 May 2024 04:01:51 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="3ef20057ca595167e2155ab2d3a746a0";
logging-data="1022114"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX186ksUjQmV57aujlm5uLgfe"
User-Agent: Pan/0.158 (Avdiivka; )
Cancel-Lock: sha1:I/wTBpD7DZaoLT+Mu9JZZHrec78=
View all headers

On Tue, 28 May 2024 21:06:31 -0400, steve wrote:

> (defun mapnconcat (fn sequences seperator)
> "Like MAPCONCAT but the function is desctuctive."
> (let ((seperator-length 0)
> (total 0) (times -1) result)
> (declare (fixnum seperator-length total times))
> (unless (eq fn #'identity)
> (map-into sequences fn sequences))
> (setq seperator-length (the fixnum (length seperator)))
> (dolist (seq sequences)
> (incf times) (incf total (+ (length seq) seperator-length)))
> (setq result (make-string (- total seperator-length)))
> (let ((pos -1)) (declare (fixnum pos))
> (loop repeat times do
> (let ((seq (pop sequences)))
> (loop for i across seq do
> (setf (schar result (incf pos)) i))
> (loop for i across seperator do
> (setf (aref result (incf pos)) i))))
> (loop for i across (car sequences) do
> (setf (schar result (incf pos)) i)))
> result))

How about:

(defun mapnconcat (fn sequences separator)
"Like MAPCONCAT but the function is destructive."
(let
(
(separator-length 0)
(total 0)
(times -1)
result
)
(declare (fixnum separator-length total times))
(unless (eq fn #'identity)
(map-into sequences fn sequences)
) ; unless
(setq separator-length (the fixnum (length separator)))
(dolist (seq sequences)
(incf times)
(incf total (+ (length seq) separator-length))
) ; dolist
(setq result (make-string (- total separator-length)))
(let ((pos -1))
(declare (fixnum pos))
(loop repeat times do
(let ((seq (pop sequences)))
(loop for i across seq do
(setf (schar result (incf pos)) i)
) ; loop
(loop for i across separator do
(setf (aref result (incf pos)) i)
) ; loop
) ; let
) ; loop
(loop for i across (car sequences) do
(setf (schar result (incf pos)) i)
) ; loop
) ; let
result
) ; let
) ; mapconcat

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: Madhu
Newsgroups: comp.lang.lisp
Organization: Motzarella
Date: Wed, 29 May 2024 09:00 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: enometh@meer.net (Madhu)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
Date: Wed, 29 May 2024 14:30:15 +0530
Organization: Motzarella
Lines: 76
Message-ID: <m3sey1vvq8.fsf@leonis4.robolove.meer.net>
References: <v29p14$2mr5l$2@dont-email.me>
<87h6et8x94.fsf@jmertens.eternal-september.org>
<v2irh1$ndjr$2@dont-email.me>
<m3zfsish1e.fsf@leonis4.robolove.meer.net> <87jzjdqve0.fsf@gmail.com>
<v362ae$v652$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Wed, 29 May 2024 11:00:12 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2fb1949d2d62dbbfe6ac7e0525851912";
logging-data="1141738"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18M7wBZa85RvV5hNQYnLIS2ThM+gkTY8qA="
Cancel-Lock: sha1:8gxURQ+HMFWcBW1QEDluUKlKZeo=
sha1:ED5Fq+DujrIfnPswOX1Ee9LdH1c=
View all headers

* Lawrence D'Oliveiro <v362ae$v652$2@dont-email.me> :
Wrote on Wed, 29 May 2024 02:01:50 -0000 (UTC):
> On Tue, 28 May 2024 21:06:31 -0400, steve wrote:
>
>> (defun mapnconcat (fn sequences seperator)
>> "Like MAPCONCAT but the function is desctuctive."
>> (let ((seperator-length 0)
>> (total 0) (times -1) result)
>> (declare (fixnum seperator-length total times))
>> (unless (eq fn #'identity)
>> (map-into sequences fn sequences))
>> (setq seperator-length (the fixnum (length seperator)))
>> (dolist (seq sequences)
>> (incf times) (incf total (+ (length seq) seperator-length)))
>> (setq result (make-string (- total seperator-length)))
>> (let ((pos -1)) (declare (fixnum pos))
>> (loop repeat times do
>> (let ((seq (pop sequences)))
>> (loop for i across seq do
>> (setf (schar result (incf pos)) i))
>> (loop for i across seperator do
>> (setf (aref result (incf pos)) i))))
>> (loop for i across (car sequences) do
>> (setf (schar result (incf pos)) i)))
>> result))
>
> How about:
> (defun mapnconcat (fn sequences separator)
> "Like MAPCONCAT but the function is destructive."
> (let
> (
> (separator-length 0)
> (total 0)
> (times -1)
> result
> )
> (declare (fixnum separator-length total times))
> (unless (eq fn #'identity)
> (map-into sequences fn sequences)
> ) ; unless
> (setq separator-length (the fixnum (length separator)))
> (dolist (seq sequences)
> (incf times)
> (incf total (+ (length seq) separator-length))
> ) ; dolist
> (setq result (make-string (- total separator-length)))
> (let ((pos -1))
> (declare (fixnum pos))
> (loop repeat times do
> (let ((seq (pop sequences)))
> (loop for i across seq do
> (setf (schar result (incf pos)) i)
> ) ; loop
> (loop for i across separator do
> (setf (aref result (incf pos)) i)
> ) ; loop
> ) ; let
> ) ; loop
> (loop for i across (car sequences) do
> (setf (schar result (incf pos)) i)
> ) ; loop
> ) ; let
> result
> ) ; let
> ) ; mapconcat

from my ~/.cmucl-init this is how i expect mapconcat to look in CL

(defun map-concatenate (result-type function sequence separator &key (start 0)
end from-end)
(reduce (lambda (&rest rest)
(when rest
(destructuring-bind (a b) rest
(concatenate result-type a separator b))))
sequence :key function :start start :end end :from-end
from-end))

Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
From: steve
Newsgroups: comp.lang.lisp
Date: Thu, 30 May 2024 01:27 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-1.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 30 May 2024 01:27:52 +0000
From: sgonedes1977@gmail.com (steve)
Newsgroups: comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
References: <v29p14$2mr5l$2@dont-email.me>
<87h6et8x94.fsf@jmertens.eternal-september.org>
<v2irh1$ndjr$2@dont-email.me> <m3zfsish1e.fsf@leonis4.robolove.meer.net>
<87jzjdqve0.fsf@gmail.com> <v362ae$v652$2@dont-email.me>
<m3sey1vvq8.fsf@leonis4.robolove.meer.net>
Date: Wed, 29 May 2024 21:27:52 -0400
Message-ID: <87h6eg5bs7.fsf@gmail.com>
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:rKR0kBSUGiPAxeWWAp5gq3rseac=
MIME-Version: 1.0
Content-Type: text/plain
Lines: 18
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-VdLDqkAqBN10J80gk96IMZq6K4PSdk4iPtLiGcNlMXn076zKb6fy7UVwDlLSYcsvQBXJbxyT8smPC82!TsXJLzv3lnxdB21tQFG8jOE3e6Vj0Yp1+WGOtsTf3/Zf6A==
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
View all headers

Madhu <enometh@meer.net> writes:

> from my ~/.cmucl-init this is how i expect mapconcat to look in CL
>
> (defun map-concatenate (result-type function sequence separator &key (start 0)
> end from-end)
> (reduce (lambda (&rest rest)
> (when rest
> (destructuring-bind (a b) rest
> (concatenate result-type a separator b))))
> sequence :key function :start start :end end :from-end
> from-end))

yes, this is much easier. I just went with emacs and left nmapconcat and
mapconcat...

the use of other keys is worth the effort but I needed something simple.

1

rocksolid light 0.9.8
clearnet tor