Path: local-4.nntp.ord.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Sun, 19 May 2024 06:06:15 +0000 From: steve Newsgroups: comp.lang.lisp Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1 References: Date: Sun, 19 May 2024 02:06:15 -0400 Message-ID: <87frueibe0.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:fdwsoqwbdqRWEkrZ0Bl6hrSOyqU= MIME-Version: 1.0 Content-Type: text/plain Lines: 33 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-E3assmZ/jG3sK/We6SebW1sBXmQdfvxEgQiCOuba2HLW8rQpWP/ObKQwJoUXSFvl6/ymXACfXfX42/3!U7FK17917RbSpXOQKGZR5r0goq1SBRWl2a1XVE/4hUNs2Q== X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 Bytes: 2087 Madhu writes: > * HenHanna : > Wrote on Sat, 18 May 2024 01:31:32 -0700: > < > 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') > > (defun adjusted-logbitp (pos num total-width) > (let* ((int-len (integer-length num)) > (i (- pos (- total-width int-len)))) > (if (< i 0) > nil > (logbitp i num)))) > > (defun bindots (str) > (let* ((indices (loop for c across str for i from 0 > if (eql c #\.) collect i)) > (width (length indices))) > (loop for i below (expt 2 width) > collect (let ((ret (copy-seq str))) > (loop for j in indices > do (setf (aref ret j) > (if (adjusted-logbitp j i width) > #\1 > #\0))) > ret)))) what about substitute? common lisp is not scheme of the week.