lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Add lilypond version predicates/operators (issue 317270043 by addres


From: git
Subject: Re: Add lilypond version predicates/operators (issue 317270043 by address@hidden)
Date: Tue, 14 Feb 2017 07:12:25 -0800

Reviewers: dak, pwm,

Message:
I'm choking a little bit with having the operator as the first argument
instead of
actually being the first element. But apart from that this solution
works very well.
And as this is not intended to be end-user facing code it's of course OK
to have
just one single possible input format (number list and no version
string).

Description:
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.

NOTE: I'm not sure where (and if) this should be documented.
Please make suggestions

Please review this at https://codereview.appspot.com/317270043/

Affected files (+48, -0 lines):
  M scm/lily-library.scm


Index: scm/lily-library.scm
diff --git a/scm/lily-library.scm b/scm/lily-library.scm
index 214c095cf2c720c0429cb8dfc6b753acc1304b77..ab6d5655321d2a20feef569c74fb799101a0710b 100644
--- a/scm/lily-library.scm
+++ b/scm/lily-library.scm
@@ -888,6 +888,54 @@ and will be applied to NUM."
     (fancy-format #f (car custom-format) num))
    (else (fancy-format #f "~(address@hidden)" num))))

+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; lilypond version
+
+(define (calculate-version ref-version)
+  "Return an integer representation of the LilyPond version,
+   can be compared with the operators."
+  (let*
+   ((v-list
+     (if (number-list? ref-version)
+         (map truncate ref-version)
+         (map string->number (string-split ref-version #\.))))
+    (use-list
+     (list-head
+      (append v-list (make-list (max 0 (- 3 (length v-list))) 0)) 3)))
+   (+ (* 1000000 (first use-list))
+     (* 1000 (second use-list))
+     (third use-list))))
+
+(define-public (lilypond>? ref-version)
+  "Return #t if the executed LilyPond version
+   is greater than the given @var{ref-version}"
+  (> (calculate-version (ly:version))
+     (calculate-version ref-version)))
+
+(define-public (lilypond>=? ref-version)
+  "Return #t if the executed LilyPond version
+   is greater than or equal to the given @var{ref-version}"
+  (>= (calculate-version (ly:version))
+      (calculate-version ref-version)))
+
+(define-public (lilypond<? ref-version)
+  "Return #t if the executed LilyPond version
+   is less than the given @var{ref-version}"
+  (< (calculate-version (ly:version))
+     (calculate-version ref-version)))
+
+(define-public (lilypond<=? ref-version)
+  "Return #t if the executed LilyPond version
+   is less than or equal to @var{ref-version}"
+  (<= (calculate-version (ly:version))
+      (calculate-version ref-version)))
+
+(define-public (lilypond=? ref-version)
+  "Return #t if the executed LilyPond version
+   is equal to @var{ref-version}"
+  (= (calculate-version (ly:version))
+     (calculate-version ref-version)))
+
 ;;;;;;;;;;;;;;;;
 ;; other






reply via email to

[Prev in Thread] Current Thread [Next in Thread]