Deutsch   English   Français   Italiano  
<v2sd6p$2qqmv$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna <HenHanna@devnull.tb>
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>
Bytes: 2515

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