Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #141: disks spinning backwards - toggle the hemisphere jumper.


comp / comp.lang.scheme / Re: Given string 'a.bc.' -- each dot(.) is to be replaced with 0 or 1

SubjectAuthor
* Given string 'a.bc.' -- each dot(.) is to be replaced with 0 or 1HenHanna
`* Re: Given string 'a.bc.' -- each dot(.) is to be replaced with 0 or 1HenHanna
 `- Re: Given string 'a.bc.' -- each dot(.) is to be replaced with 0 or 1Jens Thiele

1
Subject: Given string 'a.bc.' -- each dot(.) is to be replaced with 0 or 1
From: HenHanna
Newsgroups: comp.lang.scheme
Organization: A noiseless patient Spider
Date: Sat, 18 May 2024 08:28 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: comp.lang.scheme
Subject: Given string 'a.bc.' -- each dot(.) is to be replaced with 0 or 1
Date: Sat, 18 May 2024 01:28:37 -0700
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <v29orm$2mr5l$1@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:28:38 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7c7ccf8d8ecc9b5171c5fa73857bd316";
logging-data="2845877"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+HVCvKa3a+xhE3cindjzQfB8z0Wl/56NA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:uNGNzC28P/bfTskYKCUYwzrDMzw=
Content-Language: en-US
View all headers

How can i write this function simply? (in Scheme (Gauche))

-- Given a string 'a.bc.' -- each dot(.) is to be replaced 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, say, (a $ b c $) rather than 'a.bc.'

Subject: Re: Given string 'a.bc.' -- each dot(.) is to be replaced with 0 or 1
From: HenHanna
Newsgroups: comp.lang.scheme, comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sun, 19 May 2024 07:19 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: comp.lang.scheme,comp.lang.lisp
Subject: Re: Given string 'a.bc.' -- each dot(.) is to be replaced with 0 or 1
Date: Sun, 19 May 2024 00:19:15 -0700
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <v2c95k$38qpc$4@dont-email.me>
References: <v29orm$2mr5l$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 19 May 2024 09:19:17 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c9b538879cf3e39a2903d58d140dec87";
logging-data="3435308"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19LDIq/cPCWae23HdPqwDVu2YkumN79jt0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:q9pcDeYDFiydBTCiLv7kyneVbLI=
In-Reply-To: <v29orm$2mr5l$1@dont-email.me>
Content-Language: en-US
View all headers

On 5/18/2024 1:28 AM, HenHanna wrote:
>
> How can i write this function simply?   (in Scheme (Gauche))
>
> -- Given a string  'a.bc.' -- each dot(.) is to be replaced 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, say,   (a $ b c $)  rather than  'a.bc.'

___________________________________________________
From the Gauche (Scheme) manual:

(cartesian-product ’((a b c) (0 1)))
⇒ ((a 0) (a 1) (b 0) (b 1) (c 0) (c 1))

________________________________________

The Gauche (Scheme) manual describes
string-count and cartesian-product

as built-in functions, but I couldn't use them and ended up defining
them myself -- Why is that?
Do i have to import libraries, as in Python?

(define (countDots s)
(count (lambda (c) (equal? c #\.))
(string->list s)))

Subject: Re: Given string 'a.bc.' -- each dot(.) is to be replaced with 0 or 1
From: Jens Thiele
Newsgroups: comp.lang.scheme
Organization: A noiseless patient Spider
Date: Fri, 24 May 2024 14:45 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: karme@karme.de (Jens Thiele)
Newsgroups: comp.lang.scheme
Subject: Re: Given string 'a.bc.' -- each dot(.) is to be replaced with 0 or 1
Date: Fri, 24 May 2024 16:45:53 +0200
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <v2q971$2c9oj$1@dont-email.me>
References: <v29orm$2mr5l$1@dont-email.me> <v2c95k$38qpc$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 24 May 2024 16:45:53 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b94e1cae6ea11a87d6448bba3bf9d7c7";
logging-data="2500371"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18bfL9GcZn7OQlZM73GpdNU"
Cancel-Lock: sha1:rJcFX0P8x4J58JvFrCmecLHrmBk=
View all headers

HenHanna <HenHanna@devnull.tb> writes:

> On 5/18/2024 1:28 AM, HenHanna wrote:
>> How can i write this function simply?   (in Scheme (Gauche))
>> -- Given a string  'a.bc.' -- each dot(.) is to be replaced 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, say,   (a $ b c $)  rather than  'a.bc.'
>
>
> ___________________________________________________
> From the Gauche (Scheme) manual:
>
> (cartesian-product ’((a b c) (0 1)))
> ⇒ ((a 0) (a 1) (b 0) (b 1) (c 0) (c 1))
>
>
> ________________________________________
>
> The Gauche (Scheme) manual describes
> string-count and cartesian-product
>
> as built-in functions, but I couldn't use them and ended up defining
> them myself -- Why is that?
> Do i have to import libraries, as in Python?

yes.
As the manual states this is in the util.combinations library:

gosh> (cartesian-product '((a b c) (0 1)))
*** UNBOUND-VARIABLE-ERROR: unbound variable: cartesian-product
Stack Trace:
_______________________________________
0 (report-error e)
1 (eval expr env)
at "/usr/share/gauche-0.98/0.9.14/lib/gauche/interactive.scm":359
2 (evaluator exp (vm-current-module))
3 (with-error-handler (^e (report-error e) #t) (^ () (let loop2 ...
gosh> (use util.combinations)
gosh> (cartesian-product '((a b c) (0 1)))
((a 0) (a 1) (b 0) (b 1) (c 0) (c 1))

Greetings
karme

1

rocksolid light 0.9.8
clearnet tor