[Top][All Lists]

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

Re: Having trouble understanding optional and variable amount of argumen

From: Stefano Troncaro
Subject: Re: Having trouble understanding optional and variable amount of arguments
Date: Thu, 8 Mar 2018 19:46:21 -0300

With your last update, the following syntax popped to mind:
\version "2.19.80"

%Functional copy of your example
#(define rules
      (req payload 
           (target ,symbol?))
      (opt accepted-without-type 
           (accepted-arg ,fraction?) 
           (ind ,number? 5) 
           (msg ,string? "No message given"))))

%Accepts any argument, but provides a type-check and a default for msg
#(define rules2
      (opt (msg ,string? "No message given"))))
I like it because:
1) It eliminates the need for the boolean argument to context-mod->props, and puts that information together with all the other rules, which makes them easier to read and parse (mentally) because all the information is in the same place. I know it's a minor thing but it's not much more typing and it feels cleaner to me. The other way you have a 'rules object' that does not contain the whole ruleset.
2) It eliminates unnecessary parens.
3) It eliminates the need to flag many arguments with opt.
4) Also, arguments that have default values feel optional to me, and here they are grouped together. With this I can at first glance know what arguments I need to give and what is optional.

It may have defects I'm not seeing. What do you think? If you like it I can do the rework.

@David, Harm
I didn't know 1.8 was not maintained anymore. I imagine we're still using it because updating it would take a lot of work (and create instability) and dev time is better placed elsewhere, or something among those lines, am I right? Also, Harm, is that guilev2-lilypond that you named v2.21.0 a personal thing or is it something that is coming after the stable 2.20 release is done? Sorry for asking so many questions, you picked my curiosity with your conversation.

2018-03-08 18:07 GMT-03:00 David Kastrup <address@hidden>:
Thomas Morley <address@hidden> writes:

> 2018-03-08 17:29 GMT+01:00 David Kastrup <address@hidden>:
>> Stefano Troncaro <address@hidden> writes:
>>> @David
>>> Thank you. The define-syntax and syntax-rules thing looked easier to
>>> understand at first glance so I tried to use that. I'll experiment with
>>> macros then.
>> If we want to get rid of those problems: Guile-1.8 is no longer
>> officially maintained.  I think someone forked it for his own purposes.
>> We might want to cooperate with him regarding some official place where
>> one can fix those bugs.
> I've tested with my guilev2-lilypond.:
> \version "2.21.0"
> #(define-syntax test
>    (syntax-rules ()
>      ((test conditional true false)
>       (if conditional
>           true
>           false))))
> #(test #t (display "I'm true!\n") (display "I'm false!\n"))
> Works out of the box, no need for (use-syntax (ice-9 syncase)).
> `use-syntax' gives an error now. Obviously it's dropped from guilev2.

Sure, it's been part of Scheme standards for quite a while now.

David Kastrup

lilypond-user mailing list

reply via email to

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