lilypond-user
[Top][All Lists]
Advanced

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

Re: Need help creating Scheme functions to automate includes of many sco


From: David Kastrup
Subject: Re: Need help creating Scheme functions to automate includes of many scores in a project
Date: Tue, 26 Jun 2018 00:51:32 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Nah <address@hidden> writes:

> I have a project with 100+ scores, each in their own file. I tried to
> create a Scheme function to \include each of them. After searching the
> archive, I got the general idea of why my solution isn't
> working. However, I didn't find something like a snippet that I could
> coax into what I want. I have programming experience in C, Python,
> etc., but I'm still pretty clueless with Scheme.
>
> What I want is a function that does something like:
> foreach fname #{ \include #fname #}
>
> In Python, I would just read all the filenames in the directory, sort
> them, then run the foreach. Can I do something like that in Scheme?
> And how do I put the result in a form that will work with \include?

$(ly:parser-include-string
  (format #f "~{\\include \"/tmp/~a\"\n~}"
          (let ((d (opendir "/tmp")))
            (let loop ((f (readdir d)) (res '()))
              (cond ((eof-object? f)
                     (closedir d)
                     (sort res string<?))
                    ((string-suffix? ".ly" f)
                     (loop (readdir d) (cons f res)))
                    (else
                     (loop (readdir d) res)))))))
Be aware that this is quite a bad idea if the file itself is in the
directory we are talking about here...

-- 
David Kastrup

reply via email to

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