[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: new and context
From: |
Noeck |
Subject: |
Re: new and context |
Date: |
Thu, 06 Dec 2012 23:34:58 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Thunderbird/17.0 |
Am 05.12.2012 09:39, schrieb Trevor Daniels:
>
> Noeck, you wrote Tuesday, December 04, 2012 8:43 PM
>
>> what is the difference between \new and \context?
>
> Very little. In most situations they can be used interchangeably.
>
> One difference is that \context Staff = "A" will search for a previously
> defined Staff with the same name and use that existing context,
> whereas \new Staff = "A" will always create a new context, even if
> a context with the same name already exists.
>
> I always use \new the first time a context is created and \context to
> refer back to an existing context, but this is just a convention and
> other users have different conventions.
>
>> I have read 5.1.2 Creating contexts, but I don't understand it yet.
>>
>> It talks about 3 commands for a context:
>> \new type music expression
>> \context type = id music
>> \context type music
>>
>> Why is \new type = id music not listed with an extra bullet? Or, why is
>> \context type = id and \new type = id is not?
>
> This section of the documentation was last amended in 2006, when the
> style was much more casual than the way the earlier sections of the Notation
> Reference are now written. It is likely the author was not very clear how
> contexts worked. It's time this section was revisited. Thanks for drawing
> our atttention to it.
>
>> Where would I need \context?
>> There is an example:
>> <<
>> \new Staff \context Voice = "A" \music
>> \context Voice = "A" \arts
>>>>
>> But I could write \new Staff << \music \\ \arts >>, couldn't I?
>
> Yes.
>
>> Ok, I see some differences in the stem directions, but it's not clear to
>> me why. I would be very happy, if anyone could explain that to me.
>
> The former uses a single Voice context, the latter uses two.
>
>> Would a syntax be possible without new and LilyPond creates the context
>> if it is not there and references an exising one, if it has the same
>> name?
>
> That's essentially what \context does.
>
> Trevor
>
Thanks, I understand it better now.
It still seems to me like there might be a possiblity to simplify the
ly-syntax. Let me make a little comparison:
In C++, if you want to declare a new variable you have to specify the
type (e.g. int) and the name (e.g. var) and you can assign a value (e.g.
5). If you want to use it, you only need the name:
int var = 5
var = 10
In Python, the type is determined from the assignment, which saves some
typing:
var = 5
var = 10
In LilyPond the type (e.g. Staff) can not be guessed, but the two lines
at the end of the C++ paragraph are quite verbose in LilyPond and
compare to:
\new Staff = "var" { a4 }
\context Staff = "var" …
I do not know the parser, but wouldn't it be possible to recognize
whether a named context already exists and use that one and if not
create a new one. That those lines could shrink to:
Staff "var" { a4 }
Staff "var" … or even (?) \var …
I think it is always better to make the usage of the software easy, than
having to explain a lot in the documentation why this has to be done in
a complex way (even if it is easy compared to the knowledge of the
developers).
But probably, I do not know enough about LilyPond to see the reason for
this and the drawbacks my suggestion would have (I wrote it, because I
see a small chance that it is not totally rubbish ;) ).
Cheers,
Joram
- new and context, Noeck, 2012/12/04
- Re: new and context, Trevor Daniels, 2012/12/05
- Re: new and context, David Kastrup, 2012/12/05
- Re: new and context,
Noeck <=
- Re: new and context, Trevor Daniels, 2012/12/06
- Re: new and context, Joram Berger, 2012/12/07
- Re: new and context, Trevor Daniels, 2012/12/06
- Re: new and context, Noeck, 2012/12/06
- Re: new and context, Trevor Daniels, 2012/12/07
- Re: new and context, Keith OHara, 2012/12/08
- Re: new and context, David Kastrup, 2012/12/08
- Re: new and context, David Kastrup, 2012/12/07
- Re: new and context, Noeck, 2012/12/07
- Re: new and context, David Kastrup, 2012/12/07