• Given string 'a.bc.' -- each dot(.) is to be replaced with 0 or 1

    From HenHanna@HenHanna@devnull.tb to comp.lang.scheme on Sat May 18 01:28:37 2024
    From Newsgroup: comp.lang.scheme


    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.'
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From HenHanna@HenHanna@devnull.tb to comp.lang.scheme,comp.lang.lisp on Sun May 19 00:19:15 2024
    From Newsgroup: comp.lang.scheme


    On 5/18/2024 1:28 AM, HenHanna wrote:

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

    -- Given a string-a 'a.bc.' -- each dot(.) is to be replaced with 0 or 1.

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

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

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


    ___________________________________________________
    From the Gauche (Scheme) manual:

    (cartesian-product rCO((a b c) (0 1)))
    rcA ((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)))


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Jens Thiele@karme@karme.de to comp.lang.scheme on Fri May 24 16:45:53 2024
    From Newsgroup: comp.lang.scheme

    HenHanna <HenHanna@devnull.tb> writes:

    On 5/18/2024 1:28 AM, HenHanna wrote:
    How can i write this function simply?-a-a (in Scheme (Gauche))
    -- Given a string-a 'a.bc.' -- each dot(.) is to be replaced with 0
    or 1.
    -a-a-a-a-a-a -- So the value is a list of 4 strings:
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a (a0bc0 a0bc1 a1bc0
    a1bc1)
    -- The order is not important.
    -a-a-a-a-a-a-a-a-a-a-a If the string has 3 dots, the value is a list of length 8.
    If the program is going to be simpler,
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a pls use, say,-a-a (a $ b c $)-a rather than-a 'a.bc.'


    ___________________________________________________
    From the Gauche (Scheme) manual:

    (cartesian-product rCO((a b c) (0 1)))
    rcA ((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
    --- Synchronet 3.22a-Linux NewsLink 1.2