Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Q: Why did the WASP cross the road? A: To get to the middle.


comp / comp.lang.lisp / Cut (and Cute) are new to me... Did that come from MIT?

SubjectAuthor
o Cut (and Cute) are new to me... Did that come from MIT?HenHanna

1
Subject: Cut (and Cute) are new to me... Did that come from MIT?
From: HenHanna
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Mon, 27 May 2024 04:57 UTC
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: Cut (and Cute) are new to me... Did that come from MIT?
Date: Sun, 26 May 2024 21:57:32 -0700
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <v313rs$3sj4k$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 27 May 2024 06:57:32 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="d85a4709db20b239337d0b8397209e43";
logging-data="4082836"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/h0dM2Ky7uzh6GknXb/FjalFbq31HpJ6s="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:1Ry/wMNwQGUCi2LfqACAwPQgOuc=
Content-Language: en-US
View all headers

On 5/25/2024 3:34 PM, B. Pym wrote:
> 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")

Thank you!!! (map (cut ... is new to me. Did that come from MIT?

weird Gensym stuff!!!

(cut cons (+ a 1) <>) ≡ (lambda (x2) (cons (+ a 1) x2))

(cut list 1 <> 3 <> 5) ≡ (lambda (x2 x4) (list 1 x2 3 x4 5))

(cut list) ≡ (lambda () (list))

(cut <> a b) ≡ (lambda (f) (f a b))

;; Usage
(map (cut * 2 <>) ’(1 2 3 4))

(for-each (cut write <> port) exprs)

1

rocksolid light 0.9.8
clearnet tor