lilypond-user
[Top][All Lists]
Advanced

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

Re: define-void-function


From: Aaron Hill
Subject: Re: define-void-function
Date: Thu, 07 May 2020 22:44:47 -0700
User-agent: Roundcube Webmail/1.4.2

On 2020-05-07 9:42 pm, Freeman Gilmore wrote:
On Thu, May 7, 2020 at 11:32 PM Aaron Hill <address@hidden> wrote:
%%%%
\version "2.20.0"

sum =
#(define-void-function
   (args)
   (number-list?)
I know the the function uses a list for this because of the
undetermined number of args as the lambda procedure did.   In
(number-list?) how do you know what goes here, say it is not a number,
like a list of similes?

You put whatever type predicate makes sense for the function. The Notation Reference lists all of the predefined ones, whether they are primitives specified by R5RS (the Scheme standard that Guile follows) or defined by LilyPond itself.

But you can also define your own type predicates:

%%%%
\version "2.20.0"

#(define (flavor? x)
  (member x '(vanilla chocolate strawberry)))

cake =
#(define-void-function
  (flavor) (flavor?)
  (format #t "\n~a cake is delicious!" flavor))

\cake chocolate

#(define (flavor-list? x)
  (and (list? x)
       (every flavor? x)))

layeredCake =
#(define-void-function
  (flavors) (flavor-list?)
  (format #t "\n~{~a~^ and ~} cake is delicious!" flavors))

\layeredCake vanilla, strawberry
%%%%

====
GNU LilyPond 2.20.0
Processing `type-predicate.ly'
Parsing...
chocolate cake is delicious!
vanilla and strawberry cake is delicious!
Success: compilation successfully completed
====


   (format #t "\nargs: ~s, sum: ~s" args (apply + args)))
I do not have a clue what this all means "(format #t "\nargs: ~s, sum:
~s" args"   Where can i find this information?

See the documentation on Formatted Output [1]. I have shared a PDF version of the Guile 1.8 docs here [2] that makes a handy companion to the LilyPond docs for offline use. Also included is the R5RS reference.

[1]: https://www.gnu.org/software/guile/docs/docs-1.8/guile-ref/Formatted-Output.html#Formatted-Output
[2]: https://drive.google.com/open?id=1WQ6zhMRUxf6-zdw3Gcv0SuuUI311Bu90


\sum 2, 3, 5
Tried this and {a \sum2,3,5 b} (note spacing) and it worked, which is
what i was looking for.   But {a \sum 2, -3, 5 b} does not work?   How
to fix this so it does?

Technically, when one says something like "2,3,5" in LilyPond, that is a key-list? as far as the parser's logic is concerned. A "key" in this context refers to either an index (non-negative integer) or a symbol.

To support general numbers, you will need to use Scheme syntax:

%%%%
\sum #'(1 -2/3 4.5)
%%%%
====
args: (1 -2/3 4.5), sum: 4.83333333333333
====


-- Aaron Hill



reply via email to

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