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

    From HenHanna@21:1/5 to B. Pym on Sun May 26 21:57:32 2024
    XPost: comp.lang.scheme

    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)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)