ak-coram / cl-frugal-uuid

Common Lisp UUID library with zero dependencies
https://github.com/ak-coram/cl-frugal-uuid/blob/main/README.org
MIT License
22 stars 3 forks source link

Add uuid string functions #7

Closed kilianmh closed 3 months ago

kilianmh commented 3 months ago

String is probably the most used form of uuid, but currently it is a bit cumbersome to produce:

(to-string (make-v7))

Should we introduce functions to directly output strings?

Here would be some obvious naming ideas: make-v7-string v7-string make-v7-to-string

Or would you prefer a different name?

mdbergmann commented 3 months ago

IMO string is only used when converting from/to some external format. Otherwise I'd like to work with the uuid type. Not sure if additional constructors will confuse the user.

ak-coram commented 3 months ago

While I wouldn't necessarily call this cumbersome, I agree that it is common enough to be a useful addition to the API (especially when you need pass a function argument). If we add this then all supported conversions should be considered (integer, octets, symbol and string).

I prefer the name make-vN-TYPE (make-v1-octets, make-v4-integer, make-v7-sym, etc.) and the functions should probably be defined in the respective files for each UUID version (this would be non-frugal/name-based.lisp for versions 3 and 5).

Having multiple constructors shouldn't be too confusing I think, we already have them in the current API (e.g. make-v7-from-timestamp).

ak-coram commented 3 months ago

At some point these could be optimized to avoid some allocations as well.

ak-coram commented 3 months ago

@kilianmh I hope this works for you: https://github.com/ak-coram/cl-frugal-uuid/commit/c310845c472ea214a60477fb8e33d168041a1017