Changeset 39842 in project


Ignore:
Timestamp:
04/05/21 08:42:28 (2 weeks ago)
Author:
Kon Lovett
Message:

add tail-zero parameter, purity control

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/5/semantic-version/trunk/semantic-version.scm

    r39841 r39842  
    1010(;export
    1111  version-punctuation
     12  version-tail-zero
    1213  make-version
    1314  version-valid?
     
    1516  version<? version=? version>? version<=? version>=?
    1617  version-hash
    17   #;version-hash-both
     18  ;version*<? version*=? version*>? version*<=? version*>=?
     19  ;version*-hash
    1820  version-comparator
    1921  version-parse
     
    4345
    4446(: version-punctuation  (#!optional string -> string))
    45 (: make-version         (#!rest ver-part -> ver))
     47(: make-version         (#!rest ver-part --> ver))
    4648(: version-compare      (ver ver #!rest --> integer))
    4749(: version-valid?       (ver --> boolean))
    48 (: version-parse        (string -> ver))
    49 (: version-string       (ver -> string))
    50 (: version-parts        (ver -> ver-parts))
    51 (: version-puncs        (ver -> ver-puncs))
     50(: version-parse        (string --> ver))
     51(: version-string       (ver --> string))
     52(: version-parts        (ver --> ver-parts))
     53(: version-puncs        (ver --> ver-puncs))
    5254(: version-inc!         (ver #!optional integer number -> ver))
    5355(: version-dec!         (ver #!optional integer number -> ver))
    54 (: version-inc          (ver #!optional integer number -> ver))
    55 (: version-dec          (ver #!optional integer number -> ver))
     56(: version-inc          (ver #!optional integer number --> ver))
     57(: version-dec          (ver #!optional integer number --> ver))
    5658
    5759;;
     
    9496(define version-punctuation (make-parameter VERSION-PUNCT))
    9597
    96 #;
    97 (define version-tail-zero? (make-parameter #f))
     98(define version-tail-zero (make-parameter #f))
    9899
    99100(define (drop-tailing-zeros ls)
     
    118119          (ver-puncs? puncs) ) ) ) ) )
    119120
    120 (define (version-compare ver1 ver2 #!key (tail-zero? #f))
     121(define (version-compare ver1 ver2 #!key (tail-zero? (version-tail-zero)))
    121122  (define (tail-zeros ls) (if tail-zero? ls (drop-tailing-zeros ls)))
    122123  (let loop ((p1 (tail-zeros (ver-parts (check-version 'version-compare ver1))))
     
    137138            cmp ) ) ) ) ) )
    138139
    139 (define (version<? ver1 ver2 #!key (tail-zero? #f))
     140(define (version<? ver1 ver2 #!key (tail-zero? (version-tail-zero)))
    140141  (negative? (version-compare ver1 ver2 #:tail-zero? tail-zero?)) )
    141142
    142 (define (version=? ver1 ver2 #!key (tail-zero? #f))
     143(define (version=? ver1 ver2 #!key (tail-zero? (version-tail-zero)))
    143144  (zero? (version-compare ver1 ver2 #:tail-zero? tail-zero?)) )
    144145
    145 (define (version>? ver1 ver2 #!key (tail-zero? #f))
     146(define (version>? ver1 ver2 #!key (tail-zero? (version-tail-zero)))
    146147  (positive? (version-compare ver1 ver2 #:tail-zero? tail-zero?)) )
    147148
    148 (define (version<=? ver1 ver2 #!key (tail-zero? #f))
     149(define (version<=? ver1 ver2 #!key (tail-zero? (version-tail-zero)))
    149150  (<= (version-compare ver1 ver2 #:tail-zero? tail-zero?) 0) )
    150151
    151 (define (version>=? ver1 ver2 #!key (tail-zero? #f))
     152(define (version>=? ver1 ver2 #!key (tail-zero? (version-tail-zero)))
    152153  (>= (version-compare ver1 ver2 #:tail-zero? tail-zero?) 0) )
    153154
    154155(define (version-hash ver . rest)
    155   (apply equal?-hash (ver-parts ver) rest) )
     156  (apply equal?-hash (ver-parts (check-version 'version-hash ver)) rest) )
    156157
    157158#;
    158 (define (version-hash-both ver . rest)
    159   (equal?-hash ver rest) )
     159(define (version*=? ver1 ver2 #!key (tail-zero? (version-tail-zero)))
     160  (and
     161    (zero? (version-compare ver1 ver2 #:tail-zero? tail-zero?))
     162    (equal? (ver-puncs1 ver) (ver-puncs ver2))) )
     163
     164#;
     165(define (version*-hash ver . rest)
     166  (equal?-hash (check-version 'version-hash* ver) rest) )
    160167
    161168(define (version-comparator)
Note: See TracChangeset for help on using the changeset viewer.