Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

It was all so different before everything changed.


comp / comp.lang.lisp / (Convert to Brackets) -- (a (b) c) ==> ( [ a [ b ] c ] )

SubjectAuthor
o (Convert to Brackets) -- (a (b) c) ==> ( [ a [ b ] c ] )HenHanna

1
Subject: (Convert to Brackets) -- (a (b) c) ==> ( [ a [ b ] c ] )
From: HenHanna
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Tue, 11 Jun 2024 00:24 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: comp.lang.lisp
Subject: (Convert to Brackets) -- (a (b) c) ==> ( [ a [ b ] c ] )
Date: Mon, 10 Jun 2024 17:24:31 -0700
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <v485g0$mmpl$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 11 Jun 2024 02:24:33 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="23ada1589ef46ac2eedbf74b37f8c23e";
logging-data="744245"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/eOkOdYHkvrlSTdhgIJSKRBriOfx2Plek="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:nZDXmfbN+Q2TbuuUbziOUEtqL/k=
Content-Language: en-US
View all headers

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

1

rocksolid light 0.9.8
clearnet tor