lilypond-user
[Top][All Lists]
Advanced

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

Re: A question about a scheme function with two input notes


From: Jean Abou Samra
Subject: Re: A question about a scheme function with two input notes
Date: Fri, 30 Dec 2022 22:51:30 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0



Le 30/12/2022 à 15:07, David Kastrup a écrit :
Jean Abou Samra <jean@abou-samra.fr> writes:

Le 30/12/2022 à 13:51, David Kastrup a écrit :
However, it doesn't work right now for local variables,
like function parameters, in #{ ... #}.
I think you may underestimate the cost of magic involved with making #/$
integrate into local Scheme scoping.  If you want Scheme semantics, $
offers those along with Scheme syntax.


What is the cost of that magic precisely?

In the basic case of \ being used outside #{ #}, the extra cost
of \ being supported in #{ #} would be an assv-ref into an
empty alist of closures, i.e., ~0 cost.

While parsing #{ #}, we'd catch \ in addition to # and $.
We already read the entire #{ #} for that. I don't think
catching \ would add much overhead to it.
You conflate "parsing" and "reading".  For #{...#}, there is a
rudimentary scan for # and $ that tends to deliver false positives
(which then just don't get evaluated later on) and may get confused into
overlooking actual positives.  \ offers a lot more potential for getting
this wrong.

It would also make Guile evaluate one (lambda () <variable>) per use
of \ in #{ #}, which I don't believe is costly.
It is.  The optimisation of not putting up closures for most constants
made a relevant performance difference.

While evaluating the \, the parser would need to do an assv-ref
into the closure alist, which in most cases will have under
10 elements (the number of '#' / '$' / '\' in the #{ #} expression).
If the linear cost of assv-ref is a concern, an obvious improvement
is to use a hash table.
The number of non-constant #/$ in a #{ ... #} will have a large hit rate
of actually needed scoping.  I don't see this for \xxx .

Overall, I don't see what could have a worrisome cost.
Did I miss something?
See above.  And there is absolutely no associated gain at all since
$identifier will work just fine where scoping is needed.  The gain of
"people using Scheme but not understanding it might by chance escape
trivial errors" is not really a gamechanger.


I'll reply on -devel, as we are getting off-topic for this list.

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

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