Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: "B. Pym" Newsgroups: comp.lang.lisp Subject: Re: binary rep as list? string-to-list? Date: Mon, 16 Jun 2025 12:30:03 -0000 (UTC) Organization: A noiseless patient Spider Lines: 19 Message-ID: <102p2o9$1kjru$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Injection-Date: Mon, 16 Jun 2025 14:30:04 +0200 (CEST) Injection-Info: dont-email.me; posting-host="ad57f5770a242b8737b27d668beca359"; logging-data="1724286"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19bp2FxxE9H9jtRazqtrllQ" User-Agent: XanaNews/1.18.1.6 Cancel-Lock: sha1:R5v/kiVBIZB2t8BKecsP0dUIOsM= > > .. 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)