Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ktakashi/r6rs-ulid
ULID for R6RS Scheme
https://github.com/ktakashi/r6rs-ulid
chez r6rs r6rs-scheme racket sagittarius scheme ulid
Last synced: about 2 months ago
JSON representation
ULID for R6RS Scheme
- Host: GitHub
- URL: https://github.com/ktakashi/r6rs-ulid
- Owner: ktakashi
- License: bsd-2-clause
- Created: 2022-02-09T13:28:30.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-02-09T20:10:02.000Z (almost 3 years ago)
- Last Synced: 2024-10-06T01:21:50.206Z (4 months ago)
- Topics: chez, r6rs, r6rs-scheme, racket, sagittarius, scheme, ulid
- Language: Scheme
- Homepage:
- Size: 6.84 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
ULID for R6SA Scheme
====================This is an implementation of [ULID](https://github.com/ulid/spec) in
portable R6RS Scheme.The library requires the following SRFIs:
- SRFI-19
- SRFI-27Or implementation specific libraries for the below helper libraries:
- `(ulid time)`
- `(ulid random)`This library is inspired by [ULID for R7RS Scheme](https://github.com/shirok/scheme-ulid)
Tested implementations
----------------------- Sagittarius 0.9.8
- Chez Scheme 9.5.1
- Racket v8.3 (plt-r6rs)How to use
----------```scheme
(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.```scheme
(gen-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.```scheme
(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.```scheme
(integer->ulid integer) ;; -> #
(bytevector->ulid bv) ;; -> #
(string->ulid str) ;; -> #
```
Above procedures convert the given exect integer, bytevector or string to
ULID object, respectively.```scheme
(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`](tests/test.scm) file.