Re: [frogs] Adding docstring support to def-grace-function

[ Thread Index | Date Index | More lilynet.net/frogs Archives ]




On 1/7/09 12:03 PM, "Patrick McCarty" <pnorcks@xxxxxxxxx> wrote:

> On Wed, Jan 7, 2009 at 7:40 AM, Carl D. Sorensen <c_sorensen@xxxxxxx> wrote:
>> 
>> On 1/7/09 12:51 AM, "Patrick McCarty" <pnorcks@xxxxxxxxx> wrote:
>>> 
>>> For A., using acciaccatura as an example, I propose the following syntax:
>>> 
>>> acciaccatura =
>>> #(def-grace-function (_i "add docstring") startAcciaccaturaMusic
>>> stopAcciaccaturaMusic)
>> 
>> There are two reasons I'd like to try something different than this syntax.
>> 
>> First, docstrings always come after the arguments to the function.
> 
> Ah, yes.  I did not think this through carefully enough.
> 
>> Second this syntax would require a convert-ly rule, and so would need to
>> wait until work begins on 2.13.
> 
> Okay, I understand this now.
> 
>> A syntax that would not require a convert-ly rule would be
>> 
>> acciaccatura =
>> #(def-grace-function startAcciaccaturaMusic stopAcciaccaturaMusic
>>  (_i "Here is the docstring."))
>> 
>> because the docstring argument can be written as an optional argument
>> in the macro definition for def-grace-function.  So adding a docstring
>> is a syntax addition, not a change, and no convert-ly rule is needed.
> 
> I see a few Scheme procedures that use the #:optional keyword.  This
> is what you are referring to, right?

It's not what I was referring to, but it may have been what I should have
been referring to.

What I was referring to is something that Nicolas used in his redefinition
of define-music-function.  You can define a procedure

(define (my-proc arg1 arg2 . optional-arguments) (...))

and call it with

(my-proc 1 2 3 4 5 6 7 8)

and inside my-proc you'll have arg = 1, arg2 = 2, and
optional-arguments = (3 4 5 6 7 8).

This is what I was referring to.  You can read about optional
arguments in the Guile reference manual at

<http://www.gnu.org/software/guile/manual/html_node/Lambda.html#Lambda>

which is unfortunately defined in the context of lambda procedures.  Lambda
procedures are always confusing to new Scheme programmers.

You can read in the Guile reference manual about optional arguments at

<http://www.gnu.org/software/guile/manual/html_node/Optional-Arguments.html#
Optional-Arguments>

You can also paste the following in at the guile> prompt, which is obtained
by typing

guile

in a terminal window:

(define (test-opt-args arg1 arg2 . t-opt-args arg1 arg2 . rest)
   (display "arg1 ")(display arg1)(newline)
   (display "arg2 ")(display arg2)(newline)
   (display "rest ")(display rest)(newline))
(test-opt-args 1 2 3 4 5 6 7 8 9)


This will define and execute a procedure named test-opt-args that has two
fixed arguments and the remainder are optional.

HTH,

Carl
> 
> Thanks,
> Patrick
> 
> ---
> 
> ----
> Join the Frogs!


---

----
Join the Frogs!


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/