]> git.donarmstrong.com Git - lilypond.git/blob - scm/c++.scm
Merge branch 'master' into lilypond/translation
[lilypond.git] / scm / c++.scm
1 ;;;; This file is part of LilyPond, the GNU music typesetter.
2 ;;;;
3 ;;;; Copyright (C) 1998--2011 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-or-grob? x)
29   (or (ly:grob? x) (number? x)))
30
31 (define-public (grob-list? x)
32   (list? x))
33
34 (define-public (moment-pair? x)
35   (and (pair? x)
36        (ly:moment? (car x)) (ly:moment? (cdr x))))
37
38 (define-public (boolean-or-symbol? x)
39   (or (boolean? x) (symbol? x)))
40
41 (define-public (string-or-symbol? x)
42   (or (string? x) (symbol? x)))
43
44 (define-public (number-or-string? x)
45   (or (number? x) (string? x)))
46
47 (define-public (string-or-pair? x)
48   (or (string? x) (pair? x)))
49
50 (define-public (number-or-pair? x)
51   (or (number? x) (pair? x)))
52
53 (define-public (cheap-list? x)
54   (or (pair? x) (null? x)))
55
56 (define-public (list-or-symbol? x)
57   (or (cheap-list? x) (symbol? x)))
58
59 (define-public (scheme? x) #t)
60
61 (define-public (symbol-or-boolean? x)
62   (or (symbol? x) (boolean? x)))
63
64 (define-public (void? x)
65   (eq? x (begin)))
66
67 ;; moved list to end of lily.scm: then all type-predicates are
68 ;; defined.
69 (define type-p-name-alist '())
70
71 (define (match-predicate obj alist)
72   (if (null? alist)
73       "Unknown type"
74       (if (apply (caar alist) obj)
75           (cdar alist)
76           (match-predicate obj (cdr alist)))))
77
78 (define-public (object-type obj)
79   (match-predicate obj type-p-name-alist))
80
81 (define-public (object-type-name obj)
82   (type-name (match-predicate obj type-p-name-alist)))
83
84 (define-public (type-name predicate)
85   (let ((entry (assoc predicate type-p-name-alist)))
86     (if (pair? entry) (cdr entry)
87         (string-trim-right
88          (symbol->string (procedure-name predicate))
89          #\?))))