lilypond-devel
[Top][All Lists]
Advanced

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

music-function type-check options


From: Mark Polesky
Subject: music-function type-check options
Date: Sat, 15 Aug 2009 18:28:45 -0700 (PDT)

In scm/lily.scm, the alist "type-p-name-alist" associates certain
type-predicates (eg. ly:music?) with strings (eg. "music") so that
type-check failures can be reported:

  wrong type for argument 1.  Expecting music, found 1.0

Any predicate that doesn't appear in the alist is assigned the
string "unknown" (this happens in the "type-name" procedure at the
end of c++.scm). For example, the positive? predicate is not in
the alist, so if the user does this:

  test =
  #(define-music-function (parser location pos-num) (positive?)
    #{ c''4 #})

  { c''2 \test #-1 } 

this message is sent to the console:

    wrong type for argument 1.  Expecting unknown, found -1

So I'd like to add some more predicates to the alist. I've
arranged the predicates into five groups to keep things easier to
follow:

R5RS Scheme -- primary
R5RS Scheme -- secondary
SRFI-1
LilyPond scheme predicates
LilyPond C++ predicates


There are also about 75 or so guile-specific predicates, but most
of them didn't seem so useful. I've listed a handful of them in a
separate section just in case someone here thinks that some of
them could be useful (array? closure? hash-table? macro? etc).


For the "LilyPond C++ predicates" group, I commented out the
predicates that are currently absent from the alist. I recall Carl
mentioning that some of them would never be applicable from within
a music-function, but perhaps someone here could specify which
ones those are.

Thanks!
- Mark

;; add (use-modules (srfi srfi-1)) if needed

(set! type-p-name-alist
      `(
        ;; R5RS Scheme -- primary
        (,boolean? . "boolean")
        (,char? . "char")
        (,number? . "number")
        (,pair? . "pair")
        (,procedure? . "procedure")
        (,string? . "string")
        (,symbol? . "symbol")
        (,vector? . "vector")
        (,port? . "port")


        ;; R5RS Scheme -- secondary
        (,char-alphabetic? . "alphabetic character")
        (,char-lower-case? . "lower-case character")
        (,char-numeric? . "numeric character")
        (,char-upper-case? . "upper-case character")
        (,char-whitespace? . "whitespace character")
        ;(,eof-object? . "EOF") ;; pointless, right?

        (,complex? . "complex number")
        (,even? . "even number")
        (,exact? . "exact number")
        (,inexact? . "inexact number")
        (,integer? . "integer")
        (,negative? . "negative number")
        (,odd? . "odd number")
        (,positive? . "positive number")
        (,rational? . "rational number")
        (,real? . "real number")
        (,zero? . "zero")

        (,list? . "list")
        (,null? . "null")

        (,input-port? . "input port")
        (,output-port? . "output port")


        ;; SRFI-1
        (,circular-list? . "circular list")
        (,dotted-list? . "dotted list")
        (,not-pair? . "non-pair")
        (,null-list? . "null list")
        (,proper-list? . "proper list")


        ;; LilyPond scheme predicates
        (,boolean-or-symbol? . "boolean or symbol")
        (,grob-list? . "list of grobs")
        (,hash-table? . "hash table")
        (,markup? . "markup")
        (,markup-list? . "list of markups")
        (,number-or-grob? . "number or grob")
        (,number-or-string? . "number or string")
        (,number-pair? . "pair of numbers")
        (,rhythmic-location? . "rhythmic location")
        (,scheme? . "any type")


        ;; LilyPond C++ predicates
        ;(,ly:box . "box")
        (,ly:context? . "context")
        (,ly:dimension? . "dimension, in staff space")
        (,ly:dir? . "direction")
        ;(,ly:dispatcher? . "dispatcher")
        (,ly:duration? . "duration")
        (,ly:font-metric? . "font metric")
        (,ly:grob? . "layout object")
        (,ly:grob-array? . "array of grobs")
        (,ly:input-location? . "input location")
        ;(,ly:item iterator? . "item iterator")
        ;(,ly:lily-lexer? . "lily-lexer")
        ;(,ly:lily-parser? . "lily-parser")
        ;(,ly:listener? . "listener")
        (,ly:moment? . "moment")
        (,ly:music? . "music")
        ;(,ly:music-function? . "music-function")
        (,ly:music-list? . "list of music objects")
        (,ly:music-output? . "music output")
        ;(,ly:otf-font? . "OpenType font")
        ;(,ly:output-def? . "output definition")
        ;(,ly:page-marker? . "page marker")
        ;(,ly:pango-font? . "pango font")
        ;(,ly:paper-book? . "paper book")
        ;(,ly:paper-system? . "paper-system Prob")
        (,ly:pitch? . "pitch")
        ;(,ly:prob? . "Prob")
        ;(,ly:score? . "score")
        (,ly:simple-closure? . "simple closure")
        ;(,ly:skyline? . "skyline")
        (,ly:skyline-pair? . "pair of skylines")
        ;(,ly:source-file? . "source file")
        ;(,ly:spanner? . "spanner")
        (,ly:stencil? . "stencil")
        ;(,ly:stream-event? . "stream event")
        (,ly:translator? . "translator")
        ;(,ly:translator-group? . "translator group")
))


Here are a few guile-specific predicates:

array?
char-set?
closure?
entity?
file-port?
debug-object?
frame?
hash-table?
hook?
inf?
keyword?
macro?
nan?
operator?
q?
record?
stack?
struct?
thunk?
variable?



      




reply via email to

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