lilypond-user
[Top][All Lists]
Advanced

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

Re: unpacking a list


From: Urs Liska
Subject: Re: unpacking a list
Date: Sat, 28 Nov 2015 09:55:18 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0


Am 28.11.2015 um 09:40 schrieb David Kastrup:
> Urs Liska <address@hidden> 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



reply via email to

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