You are looking at historical revision 39854 of this page. It may differ significantly from its current revision.
semantic-version
- semantic-version
- Documentation
- Usage
- version-punctuation
- version-tail-zero
- make-version
- check-version
- error-version
- version-copy
- version?
- version-depth
- version-parts
- version-puncs
- version->list
- list->version
- version-compare
- version<?
- version=?
- version>?
- version<=?
- version>=?
- version-hash
- version-comparator
- string->version
- version->string
- version-depth+!
- version-depth-!
- version-depth+
- version-depth-
- version-extend!
- version-extend
- version-inc!
- version-dec!
- version-inc
- version-dec
- Example
- Requirements
- Author
- Version history
- License
Documentation
Semantic-Version handling.
Usage
(import semantic-version)
version-punctuation
[procedure] (version-punctuation [STR]) -> stringReturns the string (set) of punctuation characters. The first is always the default.
- STR
- string ; default is "._- +;:,"
version-tail-zero
[procedure] (version-tail-zero [BOOL]) -> booleanReturns whether trailing 0's are ignored during comparision.
make-version
check-version
error-version
[procedure] (make-version ELM...) --> version[procedure] (check-version LOC OBJ [NAM]) -> version
[procedure] (error-version LOC OBJ [NAM])
Returns a new version with the specified elements, ELM..., and the default punctuation (see version-punctuation).
- ELM
- (or number string symbol) ; version element.
Note that the symbol printname is used internally. Returns whether trailing 0's are ignored during comparision.
version-copy
[procedure] (version-copy VER) --> versionReturn a copy of the version, sharing only atoms.
- VER
- version ; version to copy.
version?
[procedure] (version? OBJ) --> boolean- OBJ
- * ; object to test.
version-depth
[procedure] (version-depth VER) --> integerReturn the number of elements in the version.
- VER
- version ; version to query.
version-parts
[procedure] (version-parts VER) --> listReturns list of version elements.
- VER
- version ; version to query.
version-puncs
[procedure] (version-puncs VER) --> listReturns list of separator characters.
- VER
- version ; version to query.
version->list
[procedure] (version->list VER) --> (list-of (or number string char))Returns an "exploded" form, with version elements interleaved with punctuation characeters.
- VER
- version ; version to list.
list->version
[procedure] (list->version LIS) --> versionReturns a version from an "exploded" form, see version->list.
- LIS
- (list-of (or number string symbol char)) ; list of version components.
version-compare
[procedure] (version-compare VER1 VER2 [TAIL-ZERO?]) --> integerReturns a negative, zero, or positive integer representing the relative order of VER1 and VER2. Compares number & string elements natively, but in a comparison between a number & a string element, the string always takes precedence. Thus "1.a.2" < "a.1.2".
- VER1
- version ; version 1 to compare.
- VER2
- version ; version 2 to compare.
- TAIL-ZERO?
- boolean ; ignore trailing 0's?
Orders versions in the same manner as the chicken-install tool.
version<?
version=?
version>?
version<=?
version>=?
[procedure] (version<? VER1 VER2 [TAIL-ZERO?]) --> boolean[procedure] (version=? VER1 VER2 [TAIL-ZERO?]) --> boolean
[procedure] (version>? VER1 VER2 [TAIL-ZERO?]) --> boolean
[procedure] (version<=? VER1 VER2 [TAIL-ZERO?]) --> boolean
[procedure] (version>=? VER1 VER2 [TAIL-ZERO?]) --> boolean
See version-compare.
version-hash
[procedure] (version-hash VER [BND RND]) --> integerA SRFI 69 compliant hash function for the version type.
- VER
- version ; version to hash.
- BND
- integer ; bounds (limit), see SRFI 69.
- RND
- integer ; randomization (salt), see SRFI 69.
version-comparator
[procedure] (version-comparator) --> comparatorReturns a SRFI 128 comparator for the version type.
string->version
[procedure] (string->version STR) --> versionReturn the parsed form of the STR. The source separator (punctuation) is preserved, and restored by version->string.
- STR
- string ; version string.
version->string
[procedure] (version->string VER) --> stringReturn the string form of the VER.
- VER
- version ; version to hash.
version-depth+!
[procedure] (version-depth+! VER CNT PART [PUNC]) -> versionReturns VER with more "depth", as PART, interspersed with PUNC.
- VER
- version ; version to extend.
- CNT
- integer ; element count.
- PART
- (or number string symbol) ; version element.
- PUNC
- char ; version punctuation, default is as above.
version-depth-!
[procedure] (version-depth-! VER CNT) -> versionReturns VER with less "depth", as CNT elements are dropped, along with the corresponding punctuation.
- VER
- version ; version to extend.
- CNT
- integer ; element count.
version-depth+
[procedure] (version-depth+ VER CNT PART [PUNC]) --> versionReturns a copy of VER with more "depth", as PART, interspersed with PUNC.
- VER
- version ; version to extend.
- CNT
- integer ; element count.
- PART
- (or number string symbol) ; version element.
- PUNC
- char ; version punctuation, default is as above.
version-depth-
[procedure] (version-depth- VER CNT) --> versionReturns a copy of VER with less "depth", as CNT elements are dropped, along with the corresponding punctuation.
- VER
- version ; version to extend.
- CNT
- integer ; element count.
version-extend!
[procedure] (version-extend! VER COMP...) -> versionReturns VER with added "depth", in the form of a new "tail", in "exploded" form.
- VER
- version ; version to extend.
- COMP
- (list-of (or number string symbol char)) ; version components.
version-extend
[procedure] (version-extend VER COMP...) --> versionReturns copy of VER with added "depth", in the form of a new "tail", in "exploded" form.
- VER
- version ; version to extend.
- COMP
- (list-of (or number string symbol char)) ; version components.
version-inc!
[procedure] (version-inc! VER [INDEX AMOUNT]) -> versionReturn VER with INDEX element incremented by AMOUNT.
- VER
- version ; version to adjust.
- INDEX
- integer ; which element to adjust.
- AMOUNT
- number ; amount to adjust.
Currently only number elements may be targets.
version-dec!
[procedure] (version-dec! VER [INDEX AMOUNT]) -> versionReturn VER with INDEX element decremented by AMOUNT.
- VER
- version ; version to adjust.
- INDEX
- integer ; which element to adjust.
- AMOUNT
- number ; amount to adjust.
Currently only number elements may be targets.
version-inc
[procedure] (version-inc VER [INDEX AMOUNT]) --> versionReturn copy of VER with INDEX element incremented by AMOUNT.
- VER
- version ; version to adjust.
- INDEX
- integer ; which element to adjust.
- AMOUNT
- number ; amount to adjust.
Currently only number elements may be targets.
version-dec
[procedure] (version-dec VER [INDEX AMOUNT]) --> versionReturn copy of VER with INDEX element decremented by AMOUNT.
- VER
- version ; version to adjust.
- INDEX
- integer ; which element to adjust.
- AMOUNT
- number ; amount to adjust.
Currently only number elements may be targets.
Example
(import (chicken base) (chicken file) (chicken pathname) (chicken sort) (srfi 1) semantic-version) (define (egg-repo-versions repo egg) (map! (o string->version pathname-strip-directory) (glob (make-pathname `(,repo ,egg "tags") "*"))) ) (for-each (o print version->string) (sort (egg-repo-versions REPO "apropos") version<?)) ;=> prints release versions in ascending order (string=? "a.1,b" ((o version->string string->version) "a.1,b")) ;=> #t ; but, assuming baseline `version-punctuation' (string=? "a.1.b" (version->string (make-version 'a 1 'b))) ;=> #t (define ver1 (make-version 'a 1 'b 2)) ((o print version->string) ver1) ;=> "a.1.b.2" (version-inc! ver1) ((o print version->string) ver1) ;=> "a.1.b.3" (version-dec! ver1 1) ((o print version->string) ver1) ;=> "a.0.b.3"
Requirements
srfi-1 srfi-69 srfi-128 string-utils
Author
Version history
- 0.0.1
- Release.
License
Copyright (C) 2021 Kon Lovett. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICESLOSS OF USE, DATA, OR PROFITSOR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.