Am 28.11.2015 um 09:40 schrieb David Kastrup: > Urs Liska <[email protected]> writes: > >> Hi all, >> >> I don't seem to find a way to "unpack" a list. I think I won't explain >> the background, but basically what I need is that >> (list (list 1 2 3) 4) >> becomes >> (list 1 2 3 4) >> >> This is a mock-up of my real code: >> >> #(define (func-a) >> (list 1 2 3)) >> >> #(define (func-b) >> (list >> (func-a) >> 4)) >> >> #(display (func-b)) >> >> What I need is that the call to (func-a) doesn't evaluate to a list but >> to its elements. >> I have "solved" it by actually using something like >> (append (func-a) (list f4)) >> but I think that's not really clean. > It most definitely _is_ clean. > >> I'd prefer directly "unpacking" the list in situ. >> >> Any suggestions? > You can write > > #(define (func-b) > `(,@(func-a) 4)) > > but this will not result in anything significantly different in the > ultimate code. > > You can also write a generic unpacker like > > #(define (list-elts x) > (cond ((null? x) x) > ((pair? x) (append! (list-elts (car x)) (list-elts (cdr x)))) > (else (list x)))) > > And then use something like (list-elts (cons (func-a) 4)) > > But that in no way is cleaner than the call to append when you know your > original structures anyway. >
Thank you for these explanations. I'll keep the current solution then. If someone might want to have a second look at the actual code it's (currently) in https://github.com/openlilylib/snippets/blob/just-intonation-stub/notation-snippets/just-intonation/definitions.ily, towards the end where it reads "(append (color-music col) ..." Best Urs _______________________________________________ lilypond-user mailing list [email protected] https://lists.gnu.org/mailman/listinfo/lilypond-user
