lilypond-user
[Top][All Lists]
Advanced

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

Re: tiny function


From: David Kastrup
Subject: Re: tiny function
Date: Fri, 01 Jul 2016 11:50:57 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

David Kastrup <address@hidden> writes:

> Thomas Morley <address@hidden> writes:
>
>> 2016-07-01 7:05 GMT+02:00 David Kastrup <address@hidden>:
>>> Thomas Morley <address@hidden> writes:
>>
>>>> %% works:
>>>> tstII =
>>>> \with { instrumentName = "foo" shortInstrumentName = "foo" }
>>>> \new Staff \tstII { r1 }
>>>
>>> Issue 4911 is supposed to harmonize this by stopping the second example
>>> from working.  This makes it possible to recognize the syntax without
>>> knowing the type of \tstII in advance (could be a music expression,
>>> leading to completely different structure).
>>
>> I'm in two minds here.
>> Hormonizing code is always preferable, but being able to spare the
>> extra \with would be nice as well.
>
> Why?  There are technical considerations underlying this change that are
> also related to usability changes, like editors having a chance to
> properly identify and indent parts of an expression.
>
> It is not possible to let an argument-less scheme function work in the
> same manner/syntax as a fixed context modification works right now.
> Fixing that comes at a high cost, basically requiring special-casing
> scheme functions in a similar vein as now music/event functions are
> special-cased.  Which is something that makes it impossible to create
> structures of music/event functions and other things.

Sigh.  I make a hash of my communication.  This sounds just like a rant.
But the "Why?" was actually an honest question.  A lot of the work I do
is focused about making entry more convenient and better reflecting the
writers' ways of thinking about music.  LilyPond has sort-of a free-form
syntax that tends to create quite a few ambiguities.  So there are some
balancing acts involved here.

Now in this case I was working on some parser refactoring and it dumped
out something like a dozen shift/reduce conflicts (meaning ambiguities
in the resulting syntax in need of resolution) of which more than a
third were due to the \with thing.  The particular stuff I was working
on was of the

xxx = ...
\xxx

variety where xxx needs to get consulted to decide whether it is still
part of ... or not.  Now many such decisions can be made on the basis
"anything of form \xxx cannot become part of ...".  For example, if I
allow a.b and have seen a, I only need to know whether the next token is
. or not, and I don't need to know what value/type \xxx has, only that
it is not a period.

But to make decisions on that level, \xxx basically falls into two
tokens, the first just saying "this is an escaped identifier" and the
second actually looking at the type of xxx.

Now the parser works only with very limited and specific lookahead.  If
I split escape sequences like \xxx into two tokens effectively, the
parser stops being able to make some decisions timely that it currently
still can do with a lookahead of a single token.

I am still making a hash of my communication.  Being able to omit \with
comes at a cost in complexity because

\new Staff \xxx

causes completely different syntactical meaning depending on whether
\xxx is a context modification or music.  When writing

\new Staff \with { \xxx }

\xxx _still_ can be either a music expression (like \hide BarLine) or a
context modification, but at that point it does not cause a complete
rewiring of the parse tree: LilyPond can just evaluate, take a look at
the resulting expression, and then decide what to do with it, namely
_how_ to make it part of the resulting context modification.  There is
still ambiguity but it does not influence how to parse the expression.

So being able to omit \with comes at a cost, and it works only with
fixed identifiers.  So how to justify the cost?  And that's where "why?"
comes into play.  User friendliness is an argument.

Now personally, I find it distracting to see something like
\RemoveEmptyStaves without \with.  I haven't omitted it myself, and it's
present in most of LilyPond's documentation and examples as well (the
convert-ly rule has very little actual impact on the code).
Independently of just having figured out or remembered that this thing
comes at a non-zero cost in Bison parsing complexity.

Obviously, that's not how you feel about the construct.  So I have
historically already felt bad about the construct and avoided it, and
the LilyPond code base does look like particularly embracing it either
even though it's been basically available forever.  It's always sort of
a bad feeling to let something stop working but I judged the cost and
said "ok, nobody seems to particularly want that anyway".

Obviously, I was wrong about that and need to reestimate the cost.
I might still end up with the same decision after considering all
available information.  But right now I am obviously missing
information.

-- 
David Kastrup



reply via email to

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