[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lilypond-user
Subject:    Re: scheme function containing score {...}
From:       Gianmaria Lari <gianmarialari () gmail ! com>
Date:       2017-12-24 12:42:36
Message-ID: CAKhGe3zPyHxx5UFVucJA283tScPU7Lj_hCsJMpkCGXvc12_QOQ () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On 25 November 2017 at 10:00, Gianmaria Lari <gianmarialari@gmail.com>
wrote:

> On 24 November 2017 at 18:18, David Kastrup <dak@gnu.org> wrote:
>
>> Gianmaria Lari <gianmarialari@gmail.com> writes:
>>
>> > I'm trying to put the score functionality inside a function (consider
>> it a
>> > test). Here it is the code:
>> >
>> > \version "2.19.80"
>> > myScore =
>> > #(define (music) (ly:music?) #{
>> >   \score {
>> >     $music
>> >     \layout{}
>> >     \midi{}
>> >    } #} )
>> >
>> > \myScore {a b c'}
>> >
>> >
>> > The code correctly generate a score but it does not generate the midi
>> file.
>> > Why???
>>
>> There is a difference between define (which defines a pure Scheme
>> function or expression) and define-music-function (which defines
>> something taking arguments in LilyPond syntax and returning a music
>> expression) and your input is an interesting mashup where \myScore will
>> probably be left as *unspecified* after you define an argumentless
>> Scheme function named `music' that first calls ly:music? without
>> argument and then would return a score if the ly:music? call had not
>> already caused an error due to a missing argument.
>>
>> Now a score is not a music expression anyway, so you should rather
>> replace define with define-scheme-function here in order to avoid
>> errors: the resulting \myScore can then return arbitrary expressions
>> including whole scores.
>>
>> --
>> David Kastrup
>>
>
> David, I changed "define" in "define-music-function" and now it works
> perfectly, thank you David!
>
> I think this is something can be useful to others so I post the new
> working code:
>
> \version "2.19.80"
> myScore =
> #(define-scheme-function (music) (ly:music?) #{
>   \score {
>     $music
>     \layout{}
>     \midi{}
>    } #} )
>
> \myScore {a b c'}
>
>
David, we discussed these things few weeks ago and I have a new problem.
The previous function myScore was working well. But when I tried to make it
returning two scores (splitting the layout and midi) it stopped to work.
This is the code:

\version "2.19.80"
myScore =
#(define-scheme-function (music) (ly:music?) #{

  \score {
    $music
    \layout{}
  }

  \score {
     $music
     \midi{}
   }

#})

\myScore {a b c'}

and this is the error


error: syntax error, unexpected \score, expecting end of input

\score {


error: error in #{ ... #}


Any suggestion?
Thank you, Gianmaria

[Attachment #5 (text/html)]

<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 25 November 2017 \
at 10:00, Gianmaria Lari <span dir="ltr">&lt;<a href="mailto:gianmarialari@gmail.com" \
target="_blank">gianmarialari@gmail.com</a>&gt;</span> wrote:</div><div \
class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div \
class="gmail-m_4318805000353502219gmail-HOEnZb"><div \
class="gmail-m_4318805000353502219gmail-h5"><div class="gmail_extra"><div \
class="gmail_quote">On 24 November 2017 at 18:18, David Kastrup  <span \
dir="ltr">&lt;<a href="mailto:dak@gnu.org" target="_blank">dak@gnu.org</a>&gt;</span> \
wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Gianmaria Lari &lt;<a \
href="mailto:gianmarialari@gmail.com" target="_blank">gianmarialari@gmail.com</a>&gt; \
writes:<br><br>&gt; I&#39;m trying to put the score functionality inside a function \
(consider it a<br>&gt; test). Here it is the code:<br>&gt;<br>&gt; \version \
&quot;2.19.80&quot;<br>&gt; myScore =<br>&gt; #(define (music) (ly:music?) #{<br>&gt; \
\score {<br>&gt;        $music<br>&gt;        \layout{}<br>&gt;        \
\midi{}<br>&gt;      } #} )<br>&gt;<br>&gt; \myScore {a b \
c&#39;}<br>&gt;<br>&gt;<br>&gt; The code correctly generate a score but it does not \
generate the midi file.<br>&gt; Why???<br><br>There is a difference between define \
(which defines a pure Scheme<br>function or expression) and define-music-function \
(which defines<br>something taking arguments in LilyPond syntax and returning a \
music<br>expression) and your input is an interesting mashup where \myScore \
will<br>probably be left as *unspecified* after you define an argumentless<br>Scheme \
function named `music&#39; that first calls ly:music? without<br>argument and then \
would return a score if the ly:music? call had not<br>already caused an error due to \
a missing argument.<br><br>Now a score is not a music expression anyway, so you \
should rather<br>replace define with define-scheme-function here in order to \
avoid<br>errors: the resulting \myScore can then return arbitrary \
expressions<br>including whole scores.<br><span \
class="gmail-m_4318805000353502219gmail-m_58746284523271993HOEnZb"><font \
color="#888888"><br>--<br>David \
Kastrup<br></font></span></blockquote></div><br></div></div></div></blockquote><blockquote \
class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex"><div dir="ltr">David, I changed &quot;define&quot; \
in &quot;define-music-function&quot; and now it works perfectly, thank you \
David!<div><br><div>I think this is something can be useful to others so I post the \
new working code:</div><div><br></div><blockquote style="margin:0px 0px 0px \
40px;border:none;padding:0px"><div><div><span style="font-size:12.8px">\version \
&quot;2.19.80&quot;</span></div></div><div><div style="font-size:12.8px"><span \
style="font-size:12.8px">myScore =  </span></div></div><div><div \
style="font-size:12.8px"><span style="font-size:12.8px">#(define-scheme-function \
(music) (ly:music?) #{</span></div></div><span \
class="gmail-m_4318805000353502219gmail-"><div><div style="font-size:12.8px"><span \
style="font-size:12.8px">   \score {</span></div></div><div><div \
style="font-size:12.8px"><span style="font-size:12.8px">      \
$music</span></div></div><div><div style="font-size:12.8px"><span \
style="font-size:12.8px">      \layout{}</span></div></div><div><div \
style="font-size:12.8px"><span style="font-size:12.8px">      \
\midi{}</span></div></div><div><div style="font-size:12.8px"><span \
style="font-size:12.8px">     } #} )</span></div></div><div><div \
style="font-size:12.8px"><br></div></div><div><div><span \
style="font-size:12.8px">\myScore {a b \
c&#39;}</span></div></div></span></blockquote></div></div></blockquote><div><br></div><div>David, \
we discussed these things few weeks ago and I have a new problem.  </div><div>The \
previous function myScore was working well. But when I tried to make it returning two \
scores (splitting the layout and midi) it stopped to work. This is the \
code:</div><div><br></div></div></div><blockquote style="margin:0px 0px 0px \
40px;border:none;padding:0px"><div class="gmail_extra"><div \
class="gmail_quote"><div><div style="font-size:12.8px"><span \
style="background-color:rgb(255,255,255)">\version \
&quot;2.19.80&quot;</span></div></div></div></div><div class="gmail_extra"><div \
class="gmail_quote"><div><div style="font-size:12.8px"><span \
style="background-color:rgb(255,255,255)">myScore =  </span></div><div \
style="font-size:12.8px"><span \
style="background-color:rgb(255,255,255)">#(define-scheme-function (music) \
(ly:music?)  </span><span style="font-size:12.8px">#{  </span></div></div><div \
style="font-size:12.8px"><span \
style="font-size:12.8px"><br></span></div></div></div><div class="gmail_extra"><div \
class="gmail_quote"><div><div style="font-size:12.8px"><span \
style="background-color:rgb(255,255,255)">   \<span class="gmail-il">score</span>  \
{</span></div></div></div></div><div class="gmail_extra"><div \
class="gmail_quote"><div><div style="font-size:12.8px"><span \
style="background-color:rgb(255,255,255)">      \
$music</span></div></div></div></div><div class="gmail_extra"><div \
class="gmail_quote"><div><div style="font-size:12.8px"><span \
style="background-color:rgb(255,255,255)">      \
\layout{}</span></div></div></div></div><div class="gmail_extra"><div \
class="gmail_quote"><div><div style="font-size:12.8px"><span \
style="background-color:rgb(255,255,255)">   }</span></div></div><div \
style="font-size:12.8px"><span \
style="background-color:rgb(255,255,255)"><br></span></div></div></div><div \
class="gmail_extra"><div class="gmail_quote"><div><div style="font-size:12.8px"><span \
style="background-color:rgb(255,255,255)">   \<span class="gmail-il">score</span>  \
{</span></div></div></div></div><div class="gmail_extra"><div \
class="gmail_quote"><div><div style="font-size:12.8px"><span \
style="background-color:rgb(255,255,255)">        \
$music</span></div></div></div></div><div class="gmail_extra"><div \
class="gmail_quote"><div><div style="font-size:12.8px"><span \
style="background-color:rgb(255,255,255)">        \
\midi{}</span></div></div></div></div><div class="gmail_extra"><div \
class="gmail_quote"><div><div style="font-size:12.8px"><span \
style="background-color:rgb(255,255,255)">     }</span><span \
style="font-size:12.8px">  </span></div><div style="font-size:12.8px"><span \
style="font-size:12.8px"><br></span></div><div style="font-size:12.8px"><span \
style="font-size:12.8px">#})</span></div></div></div></div><div \
class="gmail_extra"><div class="gmail_quote"><div><div style="font-size:12.8px"><span \
style="background-color:rgb(255,255,255)"><br></span></div></div></div></div><div \
class="gmail_extra"><div class="gmail_quote"><div><div style="font-size:12.8px"><span \
style="background-color:rgb(255,255,255)">\myScore {a b \
c&#39;}</span></div></div></div></div><div class="gmail_extra"><div \
class="gmail_quote"><div><br></div></div></div></blockquote><div \
class="gmail_extra"><div class="gmail_quote"><div>and this is the error</div><div><p \
style="margin:0px"><span \
style="font-family:monospace;font-size:9pt"><br></span></p></div></div></div><blockquote \
style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_extra"><div \
class="gmail_quote"><div><p style="margin:0px"><span \
style="font-family:monospace;font-size:9pt">error: syntax error, unexpected \score, \
expecting end of input</span></p></div></div></div><div class="gmail_extra"><div \
class="gmail_quote"><p style="margin:0px"><span \
style="font-family:monospace;font-size:9pt">  \score {</span></p></div></div><div \
class="gmail_extra"><div class="gmail_quote"><p \
style="margin:0px;font-family:monospace;font-size:9pt"><br></p></div></div><div \
class="gmail_extra"><div class="gmail_quote"><p style="margin:0px"><span \
style="font-family:monospace;font-size:9pt">error: error in #{ ... \
#}</span></p></div></div></blockquote><font face="monospace"><span \
style="font-size:12px"><br></span></font><div class="gmail_extra"><div \
class="gmail_quote"> <p style="margin:0px"><span \
style="font-family:monospace;font-size:9pt">  </span></p>


</div></div><div><font face="monospace"><span style="font-size:12px">Any \
suggestion?</span></font></div><div><font face="monospace"><span \
style="font-size:12px">Thank you, Gianmaria</span></font></div></div>



_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic