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

2020-10-20 Thread Dave Seidel
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 
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
>
>


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

2020-10-19 Thread Aaron Hill

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



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

2020-10-19 Thread Aaron Hill

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)))
  )
)



partName =
#(or (false-if-exception (format #f "S~d" (@ (guile-user) part)))
 ""))



Interesting. I don't understand the '@' syntax -- been trying to look 
it

up but so far to no avail.


https://www.gnu.org/software/guile/docs/docs-1.8/guile-ref/Using-Guile-Modules.html#Using-Guile-Modules


-- Aaron Hill



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

2020-10-19 Thread Dave Seidel
More succinct:

#(begin
  (use-modules (guile-user))

  (if (not(defined? 'part))
(define partName "")
(define partName (string-append "S" (number->string part)))
  )
)

though the warning still prints, but that's not a big deal for me.

On Mon, Oct 19, 2020 at 10:23 PM Dave Seidel  wrote:

> Interesting. I don't understand the '@' syntax -- been trying to look it
> up but so far to no avail.
>
> Here's what I ended up with:
>
> #(begin
>   (use-modules (guile-user))
>
>   (if (not(symbol? 'part))
> (define part 0)
>   )
>
>   (if (= part 0)
> (define partName "")
> (define partName (string-append "S" (number->string part)))
>   )
> )
>
> which gives me a default value for "part" if not defined on the command
> line. The "partName" variable is used later: if non-null, the script will
> print parts instead of a full score, thus
>
> lilypond -o Hexany_Permutations hexany_permutations.ly
> lilypond -e "(define part 1)" -o Hexany_Permutations_S1
> hexany_permutations.ly
> lilypond -e "(define part 2)" -o Hexany_Permutations_S2
> hexany_permutations.ly
> lilypond -e "(define part 3)" -o Hexany_Permutations_S3
> hexany_permutations.ly
> lilypond -e "(define part 4)" -o Hexany_Permutations_S4
> hexany_permutations.ly
> lilypond -e "(define part 5)" -o Hexany_Permutations_S5
> hexany_permutations.ly
> lilypond -e "(define part 6)" -o Hexany_Permutations_S6
> hexany_permutations.ly
>
> which yields a PDF for the full score and a separate PDF for each part
> (where the instruments are designated as S1 through S6). I guess I could
> probably do it all in a single invocation, but I haven't gotten that far
> yet -- only been using Lilypond for about a week now.
>
> - Dave
>
> On Mon, Oct 19, 2020 at 6:22 PM Aaron Hill 
> wrote:
>
>> On 2020-10-19 2:45 pm, Jean Abou Samra wrote:
>> > You can ignore the warning that shows up
>> > (https://gitlab.com/lilypond/lilypond/-/issues/3613).
>>
>> You can avoid the warning by using the @ syntax:
>>
>>  eval-scope.ly 
>> \version "2.20.0"
>> #(format #t "\nvalue = ~s"
>>(false-if-exception (@ (guile-user) value)))
>> 
>>
>> 
>> > lilypond eval-scope.ly
>> GNU LilyPond 2.20.0
>> Processing `eval-scope.ly'
>> Parsing...
>> value = #f
>> Success: compilation successfully completed
>>
>> > lilypond -e "(define-public value 123)" eval-scope.ly
>> GNU LilyPond 2.20.0
>> Processing `eval-scope.ly'
>> Parsing...
>> value = 123
>> Success: compilation successfully completed
>> 
>>
>>
>> -- Aaron Hill
>>
>>


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

2020-10-19 Thread Dave Seidel
Interesting. I don't understand the '@' syntax -- been trying to look it up
but so far to no avail.

Here's what I ended up with:

#(begin
  (use-modules (guile-user))

  (if (not(symbol? 'part))
(define part 0)
  )

  (if (= part 0)
(define partName "")
(define partName (string-append "S" (number->string part)))
  )
)

which gives me a default value for "part" if not defined on the command
line. The "partName" variable is used later: if non-null, the script will
print parts instead of a full score, thus

lilypond -o Hexany_Permutations hexany_permutations.ly
lilypond -e "(define part 1)" -o Hexany_Permutations_S1
hexany_permutations.ly
lilypond -e "(define part 2)" -o Hexany_Permutations_S2
hexany_permutations.ly
lilypond -e "(define part 3)" -o Hexany_Permutations_S3
hexany_permutations.ly
lilypond -e "(define part 4)" -o Hexany_Permutations_S4
hexany_permutations.ly
lilypond -e "(define part 5)" -o Hexany_Permutations_S5
hexany_permutations.ly
lilypond -e "(define part 6)" -o Hexany_Permutations_S6
hexany_permutations.ly

which yields a PDF for the full score and a separate PDF for each part
(where the instruments are designated as S1 through S6). I guess I could
probably do it all in a single invocation, but I haven't gotten that far
yet -- only been using Lilypond for about a week now.

- Dave

On Mon, Oct 19, 2020 at 6:22 PM Aaron Hill  wrote:

> On 2020-10-19 2:45 pm, Jean Abou Samra wrote:
> > You can ignore the warning that shows up
> > (https://gitlab.com/lilypond/lilypond/-/issues/3613).
>
> You can avoid the warning by using the @ syntax:
>
>  eval-scope.ly 
> \version "2.20.0"
> #(format #t "\nvalue = ~s"
>(false-if-exception (@ (guile-user) value)))
> 
>
> 
> > lilypond eval-scope.ly
> GNU LilyPond 2.20.0
> Processing `eval-scope.ly'
> Parsing...
> value = #f
> Success: compilation successfully completed
>
> > lilypond -e "(define-public value 123)" eval-scope.ly
> GNU LilyPond 2.20.0
> Processing `eval-scope.ly'
> Parsing...
> value = 123
> Success: compilation successfully completed
> 
>
>
> -- Aaron Hill
>
>


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

2020-10-19 Thread Aaron Hill

On 2020-10-19 2:45 pm, Jean Abou Samra wrote:

You can ignore the warning that shows up
(https://gitlab.com/lilypond/lilypond/-/issues/3613).


You can avoid the warning by using the @ syntax:

 eval-scope.ly 
\version "2.20.0"
#(format #t "\nvalue = ~s"
  (false-if-exception (@ (guile-user) value)))




lilypond eval-scope.ly

GNU LilyPond 2.20.0
Processing `eval-scope.ly'
Parsing...
value = #f
Success: compilation successfully completed


lilypond -e "(define-public value 123)" eval-scope.ly

GNU LilyPond 2.20.0
Processing `eval-scope.ly'
Parsing...
value = 123
Success: compilation successfully completed



-- Aaron Hill



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

2020-10-19 Thread Dave Seidel
Thanks Jean! I need to read more carefully!

On Mon, Oct 19, 2020 at 5:45 PM Jean Abou Samra  wrote:

>
> Le 19/10/2020 à 23:14, Dave Seidel a écrit :
>
> Hi all,
>
> I am trying to define a variable on the command line that I can use within
> the .ly file. I've tried both
>
> -e "(define-public part 1)"
>
> and
>
> -e "(define part 1)"
>
>
> In the .ly file, I have a Scheme expression
>
> #(if (= part 0)
>   (define partName "")
>   (define partName (string-append "S" part))
> )
>
>
> In either case, I get the error
>
> GUILE signaled an error for the expression beginning here
> #
>  (if (= part 0)
> Unbound variable: part
>
>
> I guess I'm either defining the variable incorrectly, or dereferencing it
> incorrectly within the script. Can someone help?
>
> Thanks,
>
> Dave
>
>
> Hi,
>
> Have a look at
>
>
> lilypond.org/doc/v2.21/Documentation/usage/command_002dline-usage#basic-command-line-options-for-lilypond.html
>
> You need
>
> #(use-modules (guile-user))
>
> at the top of your LilyPond source.
>
> You can ignore the warning that shows up 
> (https://gitlab.com/lilypond/lilypond/-/issues/3613).
>
> Best,
> Jean
>
>


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

2020-10-19 Thread Jean Abou Samra


Le 19/10/2020 à 23:14, Dave Seidel a écrit :

Hi all,

I am trying to define a variable on the command line that I can use 
within the .ly file. I've tried both


-e "(define-public part 1)"

and

-e "(define part 1)"


In the .ly file, I have a Scheme expression

#(if (= part 0)
  (define partName "")
  (define partName (string-append "S" part))
)


In either case, I get the error

GUILE signaled an error for the expression beginning here
#
 (if (= part 0)
Unbound variable: part


I guess I'm either defining the variable incorrectly, or dereferencing 
it incorrectly within the script. Can someone help?


Thanks,
Dave


Hi,

Have a look at

lilypond.org/doc/v2.21/Documentation/usage/command_002dline-usage#basic-command-line-options-for-lilypond.html

You need

#(use-modules (guile-user))

at the top of your LilyPond source.

You can ignore the warning that shows up 
(https://gitlab.com/lilypond/lilypond/-/issues/3613).

Best,
Jean