Scheme Variablentypen

Zur Navigation springen Zur Suche springen
Scheme bietet keine eingebaute Funktionalität, um den Typ einer Variablen festzustellen. Folgendes Programm liefert diese Funktion unter Berücksichtigung der Lilypond-Eigenschaften.
#(define of-type
   (lambda (x)
     (cond
      ((ly:music? x)            "music")
      ((ly:duration? x)         "duration")
      ((ly:book? x)             "book")
      ((ly:box? x)              "box")
      ((ly:context? x)          "context")
      ((ly:context-def? x)      "context-def")
      ((ly:context-mod? x)      "context-mod")
      ((ly:dimension? x)        "dimension")
      ((ly:dir? x)              "dir")
      ((ly:dispatcher? x)       "dispatcher")
      ((ly:duration? x)         "duration")
      ((ly:event? x)            "event")
      ((ly:font-metric? x)      "font-metric")
      ((ly:grob? x)             "grob")
      ((ly:grob-array? x)       "grob-array")
      ((ly:input-location? x)   "input-location")
      ((ly:item? x)             "item")
      ((ly:iterator? x)         "iterator")
      ((ly:lily-lexer? x)       "lily-lexer")
      ((ly:lily-parser? x)      "lily-parser")
      ((ly:listener? x)         "listener")
      ((ly:moment? x)           "moment")
      ((ly:music-function? x)   "music-function")
      ((ly:music-list? x)       "music-list")
      ((ly:music-output? x)     "music-output")
      ((ly:otf-font? x)         "otf-font")
      ((ly:output-def? x)       "output-def")
      ((ly:page-marker? x)      "page-marker")
      ((ly:pango-font? x)       "pango-font")
      ((ly:paper-book? x)       "paper-book")
      ((ly:paper-system? x)     "paper-system")
      ((ly:pitch? x)            "pitch")
      ((ly:prob? x)             "prob")
      ((ly:score? x)            "score")
      ((ly:skyline? x)          "skyline")
      ((ly:skyline-pair? x)     "skyline-pair")
      ((ly:source-file? x)      "source-file")
      ((ly:spanner? x)          "spanner")
      ((ly:spring? x)           "spring")
      ((ly:stencil? x)          "stencil")
      ((ly:stream-event? x)     "stream-event")
      ((ly:translator? x)       "translator")
      ((ly:translator-group? x) "translator-group")
      ((integer? x)   "integer")
      ((rational? x)  "rational")
      ((real? x)      "real")
      ((complex? x)   "complex")
      ((number? x)    "number")
      ((list? x)      "list")
      ((pair? x)      "pair")
      ((string? x)    "string")
      ((vector? x)    "vector")
      ((boolean? x)   "boolean")
      ((char? x)      "char")
      ((symbol? x)    "symbol")
      ((null? x)      "null")
      ((procedure? x)   "procedure")
      ((eof-object? x)  "eof-object")
      ((input-port? x)  "input-port")
      ((output-port? x) "output-port")
      ((macro? x)       "macro")
      ((void? x)        "void")
      ((promise? x)     "promise")
      ((scheme? x)      "scheme")
      (#t "undef")
      )))

Anwendung

Code

#(display (of-type (ly:font-config-display-fonts)))
#(newline)
#(display (of-type  ly:font-config-display-fonts))

Ausgabe

void
procedure