lilypond-user
[Top][All Lists]
Advanced

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

Re: Scheme expressions on lilypond command line (-e)


From: Dave Seidel
Subject: Re: Scheme expressions on lilypond command line (-e)
Date: Tue, 20 Oct 2020 06:18:50 -0400

This is excellent, Aaron, thanks very much. Learning by example suits me well, and I'm enjoying getting into Scheme. I use Python + Java all day long on the job (in fact used Python to generate all of the music parts of the score I'm working on -- it's originally a Csound piece that was written using Python in the first place), and it's good for the brain to get stretched into a different paradigm.

- Dave

On Mon, Oct 19, 2020 at 11:26 PM Aaron Hill <lilypond@hillvisions.com> wrote:
On 2020-10-19 7:51 pm, Dave Seidel wrote:
> More succinct:
>
> #(begin
>   (use-modules (guile-user))
>
>   (if (not(defined? 'part))
>     (define partName "")
>     (define partName (string-append "S" (number->string part)))
>   )
> )

To be even more succinct, observe the following:

====
Avoid negated predicates by swapping the consequent and alternate.
;;;;
(if (defined? 'part)
     (define partName (string-append "S" (number->string part)))
     (define partName ""))
;;;;

====
Extract common logic from consequent and alternate.
;;;;
(define partName
   (if (defined? 'part)
       (string-append "S" (number->string part))
       ""))
;;;;

====
Use formatted output instead of manual string conversion/concatenation.
;;;;
(define partName
   (if (defined? 'part)
       (format #f "S~d" part)
       ""))
;;;;


-- Aaron Hill


reply via email to

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