Giter VIP home page Giter VIP logo

r6rs-ulid's Introduction

ULID for R6SA Scheme

This is an implementation of ULID in portable R6RS Scheme.

The library requires the following SRFIs:

  • SRFI-19
  • SRFI-27

Or implementation specific libraries for the below helper libraries:

  • (ulid time)
  • (ulid random)

This library is inspired by ULID for R7RS Scheme

Tested implementations

  • Sagittarius 0.9.8
  • Chez Scheme 9.5.1
  • Racket v8.3 (plt-r6rs)

How to use

(import (rnrs)
        (ulid))
(define gen-ulid (make-ulid-generator))

make-ulid-generator creates a new ULID generator. The procedure may take two optional arguments, random-generator and millisecond-generator.
The first one must take an argument which is an integer indicates how many bits of random integer must be returned.
The second one must be a thunk returning a current millisecond.

(gen-ulid) ;; -> #<ulid>

Calling the generator procedure created with make-ulid-generator returns a new ULID object. You can retrieve its timestamp and randomness fields by ulid-timestamp and ulid-randomness, both in exact nonnegative integers, respectively.

NOTE: This library does increment the randomness field if the timestamp of the previous ULID and creating ULID are the same as the ULID specification mentioned. Also, it takes a millisecond-generator which may return the constant value. If the randomness reaches to the maximum value, (expt 2 80) then &ulid will be raised. It is user's responsibility not to pass constant value generator.

(ulid->integer ulid)    ;; -> an exact integer
(ulid->bytevector ulid) ;; -> a bytevector
(ulid->string ulid)     ;; -> a Base32 encoded string

Above procedures convert the given ulid to an exact integer, bytevector or string, respectively.

(integer->ulid integer) ;; -> #<ulid>
(bytevector->ulid bv)   ;; -> #<ulid>
(string->ulid str)      ;; -> #<ulid>

Above procedures convert the given exect integer, bytevector or string to ULID object, respectively.

(ulid=? ulid0 ulid1 ulid*...)
(ulid<? ulid0 ulid1 ulid*...)
(ulid-hash ulid)

Equality predicate, ordering predicate and hash function.

Unlike the R7RS version of ULID library, this library doesn't provide ULID comparator.

Limitations

On Chez Scheme, it doesn't provide a good way of initialise a random seed. So, the default random generator generates the same value over and over again.

Default implementation of random generator uses SRFI-27, which doesn't require the implementation to provide secure random. Please check your implementation's document which psuedo random algorithm is used and replace with an appropreate alternative if needed.

Testing

If your R6RS implementation supports SRFI-64, you can run the tests/test.scm file.

r6rs-ulid's People

Contributors

ktakashi avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.