Sujet : Re: binary rep as list? string-to-list?
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lispDate : 16. Jun 2025, 13:30:03
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <102p2o9$1kjru$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
.. but now stuck on how to convert the "1001" string into a (1 0 0 1)
integer list. Any help appreciated --- thanks!
an iterative solution:
(loop for digit across (write-to-string 9 :base 2) collect
(if (char= digit #\1) 1 0))
or a more functional solution:
(map 'list
#'(lambda (x) (if (char= x #\1) 1 0))
(write-to-string 9 :base 2))
Scheme:
(map string->number (map string (string->list "1001")))
===>
(1 0 0 1)