[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scheme-question about unnesting list
From: |
Thomas Morley |
Subject: |
scheme-question about unnesting list |
Date: |
Fri, 10 Apr 2015 14:28:05 +0200 |
Hi,
consider the following list:
(define ls
(list
"a"
(list
(cons 'x "xx")
(cons 'y "yy")
(list 1 2 3))
(cons 'z "zz")))
I want to unnest it one level.
It can be done with the procedure 'unnest-list-one-lvl', which I
defined for that purpose:
(define (unnest-list-one-lvl l)
(append-map
(lambda (e)
(if (list? e)
e
(list e)))
l))
(unnest-list-one-lvl ls)
-> ("a" (x . "xx") (y . "yy") (1 2 3) (z . "zz"))
Question:
Is there a better, easier way?
Cheers,
Harm
- scheme-question about unnesting list,
Thomas Morley <=