You are looking at historical revision 26952 of this page. It may differ significantly from its current revision.
An implementation of serialnumbers and their arithmetic as described in http://www.faqs.org/rfcs/rfc1982.html.
(use serial) ;;simple addition (display (sn+ 1 2)) ;;wrapping (display (sn+ (sn+ 6 3 bits: 3) 2 bits: 3)) ;; parameterize the bits (parameterize ((current-serial-bits 3)) (sn+ (sn+ 6 3) 2)) ;;comparison (sn> 3 4) (sn< 3 5) (sn= 4 4 bits: 10)
The library defines a small set of procedures that can be used to bring serial-number arithmetic to regular fixnums. There are however certain requirements for a number to be usable as a serial-number. It must be a non-negative fixnum, that does not exceed the allowed range for a given operation.
Every procedure accepts a keyword-argument bits which specifies the number of bits used to represent the biggest acceptable serialnumber for that operation. This is especially important when addtion is performed on boundary values which causes a wrap-around.
The default amount of bits used to do the serial calculations. Defaults to 32.
Addition[procedure] (sn+ serial fixnum #!key (bits (current-serial-bits)))
Adds fixnum to the supplied serial and returns the result of the addition. Note that this procedure may wrap the value if the given serial is the upper boundary value of the range of integers that can be represented using bits bits. This means that (sn> (sn+ serial 1) serial) may be false in this situation.
The standard set of comparison operators that can be applied to fixnums are available for serial-numbers too. They're all prefix by sn. Please refer to 3.2 on http://www.faqs.org/rfcs/rfc1982.html for details on the semantic of those operations. Most of the time they will however have the same sematics as the corresponding procedures on the set of regular fixnums.[procedure] (sn> s1 s2 #!key (bits (current-serial-bits)))
[procedure] (sn< s1 s2 #!key (bits (current-serial-bits)))
[procedure] (sn<= s1 s2 #!key (bits (current-serial-bits)))
[procedure] (sn>= s1 s2 #!key (bits (current-serial-bits)))
[procedure] (sn= s1 s2 #!key (bits (current-serial-bits)))
Copyright (c) 2011 David Krentzlin <firstname.lastname@example.org> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.