• (Convert to Brackets) -- (a (b) c) ==> ( [ a [ b ] c ] )

    From HenHanna@21:1/5 to All on Mon Jun 10 17:24:31 2024
    ;;; Another (nice) way to write this?


    (define (atom? x) (not (pair? x)))

    (define (cb x) ; Convert to Brackets
    (if (atom? x) (list x)
    (append '(#\[) (append-map cb x) '(#\])) ))


    (define (pcb x)
    (format #t " ~% ~a ~a ~S ~% " x (cb x) (length (cb x))))

    (pcb 'atom)
    (pcb '(a))
    (pcb '(a b c))
    (pcb '(a (b) c))
    (pcb '(a (b ((c) (d e))) 1 2))

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