Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

Serial

  1. Outdated egg!
  2. Serial
    1. Introduction
    2. Examples
    3. Authors
    4. Api
      1. Parameters
      2. Addition
      3. Comparison
    5. License

Introduction

An implementation of serialnumbers and their arithmetic as described in http://www.faqs.org/rfcs/rfc1982.html.

Examples

(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)

Authors

David Krentzlin

Api

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.

Parameters

[parameter] current-serial-bits

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.

Comparison

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)))

License

 Copyright (c) 2011 David Krentzlin <david@lisp-unleashed.de>

  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.