]> git.donarmstrong.com Git - lilypond.git/blob - scm/c++.scm
8f4986a257ba72fe1ef0cefba10f792062cb2c6f
[lilypond.git] / scm / c++.scm
1 ;;;; This file is part of LilyPond, the GNU music typesetter.
2 ;;;;
3 ;;;; Copyright (C) 1998--2012 Jan Nieuwenhuizen <janneke@gnu.org>
4 ;;;;                 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 ;;;;
6 ;;;; LilyPond is free software: you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation, either version 3 of the License, or
9 ;;;; (at your option) any later version.
10 ;;;;
11 ;;;; LilyPond is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;;;; GNU General Public License for more details.
15 ;;;;
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18
19 ;;; Note: this file can't be used without LilyPond executable
20
21
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23 ;; type predicates.
24 (define-public (number-pair? x)
25   (and (pair? x)
26        (number? (car x)) (number? (cdr x))))
27
28 (define-public (fraction? x)
29   (and (pair? x)
30        (index? (car x)) (index? (cdr x))))
31
32 (define-public (number-or-grob? x)
33   (or (ly:grob? x) (number? x)))
34
35 (define-public (grob-list? x)
36   (list? x))
37
38 (define-public (number-list? x)
39   (and (list? x) (every number? x)))
40
41 (define-public (index? x)
42   (and (integer? x) (>= x 0)))
43
44 (define-public (moment-pair? x)
45   (and (pair? x)
46        (ly:moment? (car x)) (ly:moment? (cdr x))))
47
48 (define-public (boolean-or-symbol? x)
49   (or (boolean? x) (symbol? x)))
50
51 (define-public (symbol-list? x)
52   (and (list? x) (every symbol? x)))
53
54 (define-public (symbol-list-or-music? x)
55   (if (list? x)
56       (every symbol? x)
57       (ly:music? x)))
58
59 (define-public (string-or-symbol? x)
60   (or (string? x) (symbol? x)))
61
62 (define-public (number-or-string? x)
63   (or (number? x) (string? x)))
64
65 (define-public (number-or-markup? x)
66   (or (number? x) (markup? x)))
67
68 (define-public (string-or-pair? x)
69   (or (string? x) (pair? x)))
70
71 (define-public (string-or-music? x)
72   (or (string? x) (ly:music? x)))
73
74 (define-public (number-or-pair? x)
75   (or (number? x) (pair? x)))
76
77 (define-public (cheap-list? x)
78   (or (pair? x) (null? x)))
79
80 (define-public (symbol-list-or-symbol? x)
81   (if (list? x)
82       (every symbol? x)
83       (symbol? x)))
84
85 (define-public (scheme? x) #t)
86
87 (define-public (symbol-or-boolean? x)
88   (or (symbol? x) (boolean? x)))
89
90 (define-public (void? x)
91   (unspecified? x))
92
93 ;; moved list to end of lily.scm: then all type-predicates are
94 ;; defined.
95 (define type-p-name-alist '())
96
97 (define (match-predicate obj alist)
98   (if (null? alist)
99       "Unknown type"
100       (if (apply (caar alist) obj)
101           (cdar alist)
102           (match-predicate obj (cdr alist)))))
103
104 (define-public (object-type obj)
105   (match-predicate obj type-p-name-alist))
106
107 (define-public (object-type-name obj)
108   (type-name (match-predicate obj type-p-name-alist)))
109
110 (define-public (type-name predicate)
111   (let ((entry (assoc predicate type-p-name-alist)))
112     (if (pair? entry) (cdr entry)
113         (string-trim-right
114          (symbol->string (procedure-name predicate))
115          #\?))))