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 <lilyp...@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