Sujet : Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1
De : joerg-mertens (at) *nospam* t-online.de (Joerg Mertens)
Groupes : comp.lang.lispDate : 19. May 2024, 20:36:23
Autres entêtes
Organisation : privat
Message-ID : <87h6et8x94.fsf@jmertens.eternal-september.org>
References : 1
User-Agent : Gnus/5.13 (Gnus v5.13)
HenHanna <
HenHanna@devnull.tb> writes:
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.'
Another one:
(defun subst-dots (s &optional (pos 0))
(let ((p (search "." s :start2 pos)))
(if p
(append
(subst-dots (replace (copy-seq s) "0" :start1 p) (1+ p))
(subst-dots (replace (copy-seq s) "1" :start1 p) (1+ p)))
(list s))))
Regards