lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: scheme-question about accumulating lists of lists


From: Thomas Morley
Subject: Re: scheme-question about accumulating lists of lists
Date: Sat, 20 Apr 2019 12:51:53 +0200

Hi David,

Am Sa., 20. Apr. 2019 um 03:52 Uhr schrieb David Pirotte <address@hidden>:
>
> 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) '()))))

Thanks pointing me to this possibility, in my use-case I then could do:
(define (p) (cons '(1 2 3) '(4 5 6)))
(define l1 '(a b c))
(define l2 '(x y z))
(cons* l1 l2 (car (p)) (cdr (p)) '())
=>
((a b c) (x y z) (1 2 3) (4 5 6))

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

My guile-knowledge is mostly limited to what LilyPond needs.
As far as I can tell (ice-9 match) isn't used in our source.
So I need to study your `blue-walk´ from scratch.

Thanks a lot,
  Harm



reply via email to

[Prev in Thread] Current Thread [Next in Thread]