]> git.donarmstrong.com Git - lilypond.git/blob - scm/c++.scm
Merge branch 'lilypond/translation' into staging
[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        (integer? (car x)) (integer? (cdr x))
31        (>= (car x) 0) (>= (cdr x) 0)))
32
33 (define-public (number-or-grob? x)
34   (or (ly:grob? x) (number? x)))
35
36 (define-public (grob-list? x)
37   (list? x))
38
39 (define-public (number-list? x)
40   (and (list? x) (every number? x)))
41
42 (define-public (moment-pair? x)
43   (and (pair? x)
44        (ly:moment? (car x)) (ly:moment? (cdr x))))
45
46 (define-public (boolean-or-symbol? x)
47   (or (boolean? x) (symbol? x)))
48
49 (define-public (string-or-symbol? x)
50   (or (string? x) (symbol? x)))
51
52 (define-public (number-or-string? x)
53   (or (number? x) (string? x)))
54
55 (define-public (string-or-pair? x)
56   (or (string? x) (pair? x)))
57
58 (define-public (number-or-pair? x)
59   (or (number? x) (pair? x)))
60
61 (define-public (cheap-list? x)
62   (or (pair? x) (null? x)))
63
64 (define-public (list-or-symbol? x)
65   (or (cheap-list? x) (symbol? x)))
66
67 (define-public (scheme? x) #t)
68
69 (define-public (symbol-or-boolean? x)
70   (or (symbol? x) (boolean? x)))
71
72 (define-public (void? x)
73   (unspecified? x))
74
75 ;; moved list to end of lily.scm: then all type-predicates are
76 ;; defined.
77 (define type-p-name-alist '())
78
79 (define (match-predicate obj alist)
80   (if (null? alist)
81       "Unknown type"
82       (if (apply (caar alist) obj)
83           (cdar alist)
84           (match-predicate obj (cdr alist)))))
85
86 (define-public (object-type obj)
87   (match-predicate obj type-p-name-alist))
88
89 (define-public (object-type-name obj)
90   (type-name (match-predicate obj type-p-name-alist)))
91
92 (define-public (type-name predicate)
93   (let ((entry (assoc predicate type-p-name-alist)))
94     (if (pair? entry) (cdr entry)
95         (string-trim-right
96          (symbol->string (procedure-name predicate))
97          #\?))))