Hi again,
Replying twice to myself in a row, how is that :)
A little tired I guess ...
> > 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:
And here is a corrected version: the code in the mail I'm answering now would
not
return proper (expected) results for any other operator then car ... this one
will
let you really walk :)
(use-modules (ice-9 match))
(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) '()))))
(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 (proc (cons a rest))
result))))
(()
(reverse! result)))))
scheme@(guile-user)> (load "blue.scm")
;;; note: source file /usr/alto/projects/guile/blue.scm
;;; ...
scheme@(guile-user)> (blue-walk blue car)
$2 = (a 1 x)
scheme@(guile-user)> (blue-walk fox car)
$3 = (a 1 x)
scheme@(guile-user)> (blue-walk blue cdr)
$4 = ((b c) (2 3) (y z))
scheme@(guile-user)> (blue-walk fox cdr)
$5 = ((b c) (2 3) (y z))
Cheers,
David
pgpj47BxMMxuy.pgp
Description: OpenPGP digital signature
_______________________________________________ lilypond-user mailing list [email protected] https://lists.gnu.org/mailman/listinfo/lilypond-user
