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