Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Compare two version numbers to determine their order
ResourceFunction["VersionOrder"][ver1,ver2] gives 1 if ver1 is before ver2 in version order, -1 if ver1 is after ver2 in version order and 0 if ver1 is the same version number as ver2. |
Compare version numbers:
In[1]:= |
Out[1]= |
In[2]:= |
Out[2]= |
In[3]:= |
Out[3]= |
Use numeric values:
In[4]:= |
Out[4]= |
In[5]:= |
Out[5]= |
In[6]:= |
Out[6]= |
Include letters:
In[7]:= |
Out[7]= |
In[8]:= |
Out[8]= |
In[9]:= |
Out[9]= |
Use the operator form:
In[10]:= |
Out[10]= |
Trailing zeros are ignored in the comparison:
In[11]:= |
Out[11]= |
In[12]:= |
Out[12]= |
Preceding zeros change the interpretation:
In[13]:= |
Out[13]= |
In[14]:= |
Out[14]= |
Additional punctuation is ignored:
In[15]:= |
Out[15]= |
In[16]:= |
Out[16]= |
Versions are case-sensitive:
In[17]:= |
Out[17]= |
Versions can have any number of parts:
In[18]:= |
Out[18]= |
In[19]:= |
Out[19]= |
Numbers can be compared with strings:
In[20]:= |
Out[20]= |
Create a function that tests if a version is greater than a given value:
In[21]:= |
In[22]:= |
Out[22]= |
In[23]:= |
Out[23]= |
In[24]:= |
Out[24]= |
In[25]:= |
Out[25]= |
In[26]:= |
Out[26]= |
Filter a list of versions:
In[27]:= |
Out[27]= |
Use the resource function PythonPackageList to get a list of Python packages, and then sort the packages by their version number with VersionOrder:
In[28]:= |
Out[28]= |
Check paclet versions:
In[29]:= |
In[30]:= |
Out[30]= |
In[31]:= |
Out[31]= |
In[32]:= |
Out[32]= |
VersionOrder can be used as an ordering function in Sort:
In[33]:= |
Out[33]= |
Use VersionOrder with Ordering:
In[34]:= |
Out[34]= |
In[35]:= |
Out[35]= |
Compare with Sort:
In[36]:= |
Out[36]= |
In[37]:= |
Out[37]= |
VersionOrder works with OrderedQ:
In[38]:= |
Out[38]= |
Compare to standard ordering:
In[39]:= |
Out[39]= |
Strings with unrelated numbers and letters can have unexpected results:
In[40]:= |
Out[40]= |
In[41]:= |
Out[41]= |
In[42]:= |
Out[42]= |
This work is licensed under a Creative Commons Attribution 4.0 International License