Hi again, > Note that the above will only work if the last 'blue item' has 3 elements, > you'd > need to adapt for other use case (which also 'speak' in favor of the cleaner > approach.
Actually, I didn't like what I wrote, here is a slightly better code:
(use-modules (ice-9 match))
(define (blue-walk blue proc)
(let loop ((blue blue)
(result '()))
(match blue
((a . rest)
(if (pair? a)
(loop rest
(cons (proc a) result))
(reverse! (cons a result))))
(()
(reverse! result)))))
It solves the above note (it avoids to have to know how many elements the last
pair
has), and also let you process both 'your' structure and the 'cleaner' one:
(define blue
(cons '(a b c) (cons '(1 2 3) '(x y z))))
(define fox
(cons '(a b c) (cons '(1 2 3) (cons '(x y z) '()))))
scheme@(guile-user)> (load "blue.scm")
;;; note: source file /usr/alto/projects/guile/blue.scm
;;; newer than ...
scheme@(guile-user)> (blue-walk fox car)
$2 = (a 1 x)
scheme@(guile-user)> (blue-walk blue car)
$3 = (a 1 x)
Cheers,
David
pgpq3Krn_OVTN.pgp
Description: OpenPGP digital signature
_______________________________________________ lilypond-user mailing list [email protected] https://lists.gnu.org/mailman/listinfo/lilypond-user
