]> git.donarmstrong.com Git - lilypond.git/blob - scm/c++.scm
Run grand-replace (issue 3765)
[lilypond.git] / scm / c++.scm
1 ;;;; This file is part of LilyPond, the GNU music typesetter.
2 ;;;;
3 ;;;; Copyright (C) 1998--2014 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 (number-pair-list? x)
29   (and (list? x)
30        (every number-pair? x)))
31
32 (define-public (fraction? x)
33   (and (pair? x)
34        (index? (car x)) (index? (cdr x))))
35
36 (define-public (rational-or-procedure? x)
37   (or
38    (and (rational? x) (exact? x))
39    (procedure? x)))
40
41 (define-public (number-or-grob? x)
42   (or (ly:grob? x) (number? x)))
43
44 (define-public (grob-list? x)
45   (list? x))
46
47 (define-public (number-list? x)
48   (and (list? x) (every number? x)))
49
50 (define-public (index? x)
51   (and (integer? x) (>= x 0)))
52
53 (define-public (moment-pair? x)
54   (and (pair? x)
55        (ly:moment? (car x)) (ly:moment? (cdr x))))
56
57 (define-public (boolean-or-symbol? x)
58   (or (boolean? x) (symbol? x)))
59
60 (define-public (symbol-list? x)
61   (and (list? x) (every symbol? x)))
62
63 (define-public (symbol-list-or-music? x)
64   (if (list? x)
65       (every symbol? x)
66       (ly:music? x)))
67
68 (define-public (string-or-symbol? x)
69   (or (string? x) (symbol? x)))
70
71 (define-public (number-or-string? x)
72   (or (number? x) (string? x)))
73
74 (define-public (number-or-markup? x)
75   (or (number? x) (markup? x)))
76
77 (define-public (string-or-pair? x)
78   (or (string? x) (pair? x)))
79
80 (define-public (string-or-music? x)
81   (or (string? x) (ly:music? x)))
82
83 (define-public (number-or-pair? x)
84   (or (number? x) (pair? x)))
85
86 (define-public (cheap-list? x)
87   (or (pair? x) (null? x)))
88
89 (define-public (symbol-list-or-symbol? x)
90   (if (list? x)
91       (every symbol? x)
92       (symbol? x)))
93
94 (define-public (scheme? x) #t)
95
96 (define-public (symbol-or-boolean? x)
97   (or (symbol? x) (boolean? x)))
98
99 (define-public (void? x)
100   (unspecified? x))
101
102 ;; moved list to end of lily.scm: then all type-predicates are
103 ;; defined.
104 (define type-p-name-alist '())
105
106 (define (match-predicate obj alist)
107   (if (null? alist)
108       "Unknown type"
109       (if (apply (caar alist) obj)
110           (cdar alist)
111           (match-predicate obj (cdr alist)))))
112
113 (define-public (object-type obj)
114   (match-predicate obj type-p-name-alist))
115
116 (define-public (object-type-name obj)
117   (type-name (match-predicate obj type-p-name-alist)))
118
119 (define-public (type-name predicate)
120   (let ((entry (assoc predicate type-p-name-alist)))
121     (if (pair? entry) (cdr entry)
122         (string-trim-right
123          (symbol->string (procedure-name predicate))
124          #\?))))