Liste des Groupes | Revenir à cl lisp |
On 5/18/2024, HenHanna wrote:nice... The description "a Lisp Haiku" seems appropriate
>Gauche Scheme:
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.'
(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")
Les messages affichés proviennent d'usenet.