• Re: binary rep as list? string-to-list?

    From B. Pym@21:1/5 to All on Mon Jun 16 12:30:03 2025
    .. 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)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From B. Pym@21:1/5 to B. Pym on Mon Jul 14 19:32:26 2025
    B. Pym wrote:

    .. 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)

    Gauche Scheme

    (map (cut - <> 48) (map char->integer (string->list "1001")))

    --
    [T]he problem is that lispniks are as cultish as any other
    devout group and basically fall down frothing at the mouth if
    they see [heterodoxy]. --- Kenny Tilton (05 Dec 2004)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)