From a45b047cc170a9e239067c1e9dfd7abc5eed2cdc Mon Sep 17 00:00:00 2001 From: Urs Liska Date: Tue, 21 Feb 2017 12:42:48 +0100 Subject: [PATCH] 5067: Add ly:version? and lexicographic-list-compare? Squashed commits: 5067: Restrict ly:version? to number list 5067: version-list-compare? rename to lexicographic-list-compare? 5067: version-list-compare? typo ly:version? and version-list-compare? A lexicographic list comparison for arbitrary element types, but with special treatment of trailing elements (additional elements of the longer list are ignored, which is typical for version comparisons such as LilyPond 2.19 is equal to 2.19.4) Simplify lilypond-version operator and create new interface Add lilypond version predicates/operators This set of predicates/operators compares a given reference version to the LilyPond version that is currently being executed. This makes it possible to implement "version switches" to write (library) code that is compatible over syntax changes. --- scm/lily-library.scm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scm/lily-library.scm b/scm/lily-library.scm index 214c095cf2..c6f066ca32 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -888,6 +888,29 @@ and will be applied to NUM." (fancy-format #f (car custom-format) num)) (else (fancy-format #f "~(~@r~)" num)))) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; lilypond version + +(define (lexicographic-list-compare? op a b) + "Lexicographically compare two lists @var{a} and @var{b} using + the operator @var{op}. The types of the list elements have to + be comparable with @var{op}. If the lists are of different length + the trailing elements of the longer list are ignored." + (let* ((ca (car a)) + (iseql (op ca ca))) + (let loop ((ca ca) (cb (car b)) (a (cdr a)) (b (cdr b))) + (let ((axb (op ca cb))) + (if (and (pair? a) (pair? b) + (eq? axb iseql (op cb ca))) + (loop (car a) (car b) (cdr a) (cdr b)) + axb))))) + +(define (ly:version? op ver) + "Using the operator @var{op} compare the currently executed LilyPond + version with a given version @var{ver} which is passed as a list of + numbers." + (lexicographic-list-compare? op (ly:version) ver)) + ;;;;;;;;;;;;;;;; ;; other -- 2.39.5