From a2f0f4f890e4dbc3062a86f4d6e1e9bf65dcac98 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Fri, 12 Feb 2016 18:02:10 +0100 Subject: [PATCH] Issue 4798/3: Define key?, key-list?, key-list-or-music?, key-list-or-symbol? A key (previously a symbol) can be either a non-negative integer (obeying the predicate index?) or a symbol. When used for overrides/reverts, the first elements of a path may not actually be numbers but they are flagged as an error by other means: since a full override path can be the concatenation of several key lists, the leading elements are not treated differently by the list predicates. Strictly speaking this should not be the case for key-list-or-music? or key-list-or-symbol? predicates, but making them behave differently seems unwarranted. Arguably key-list-or-symbol? should possibly be key-list-or-key? instead. --- scm/c++.scm | 16 ++++++++++++++++ scm/lily.scm | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/scm/c++.scm b/scm/c++.scm index badac67e5c..a455afdd78 100644 --- a/scm/c++.scm +++ b/scm/c++.scm @@ -60,6 +60,22 @@ (define-public (boolean-or-symbol? x) (or (boolean? x) (symbol? x))) +(define-public (key? x) + (or (symbol? x) (index? x))) + +(define-public (key-list? x) + (and (list? x) (every key? x))) + +(define-public (key-list-or-music? x) + (if (list? x) + (every key? x) + (ly:music? x))) + +(define-public (key-list-or-symbol? x) + (if (list? x) + (every key? x) + (symbol? x))) + (define-public (symbol-list? x) (and (list? x) (every symbol? x))) diff --git a/scm/lily.scm b/scm/lily.scm index 3d7a326c64..5ead4e6c9c 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -678,6 +678,10 @@ messages into errors.") (,fraction? . "fraction, as pair") (,grob-list? . "list of grobs") (,index? . "non-negative integer") + (,key? . "index or symbol") + (,key-list? . "list of indexes or symbols") + (,key-list-or-music? . "key list or music") + (,key-list-or-symbol? . "key list or symbol") (,markup? . "markup") (,markup-command-list? . "markup command list") (,markup-list? . "markup list") -- 2.39.2