RSS Feed

Lisp Project of the Day


You can support this project by donating at:

Donate using PatreonDonate using Liberapay

Or see the list of project sponsors.


Tests ๐Ÿ˜€
CI ๐Ÿ˜€

This small library from @guicho271828 does some sort of pattern matching but for type specifiers.

With "type-unify" you can extract information from type specifiers and use it macroses or for other purposes.

This way you might discover interesting traits of a type such as the limits of a number.

Of cause, in these examples limits are obvious, but in real life, you might not know which type specifier user will pass to your macro:

POFTHEDAY> (trivialib.type-unify:type-unify1
            '(a)       ;; this is a variable bindings
            '(integer * a)      ;; the template
            '(unsigned-byte 8)) ;; the type specifier
((A . 255))

POFTHEDAY> (trivialib.type-unify:type-unify1
            '(a b)
            '(integer a b)
            '(signed-byte 8))
((A . -128) (B . 127))

POFTHEDAY> (trivialib.type-unify:type-unify1
            '(integer * a)
((A . 4611686018427387903))

It is also possible to work with other data types, for example, with vectors:

POFTHEDAY> (trivialib.type-unify:type-unify1
            '(a b)
            '(array a (b))
            '(array char (3)))
((A . CHAR) (B . 3))

POFTHEDAY> (trivialib.type-unify:type-unify1
            '(a b)
            '(array a (b))
((A . CHARACTER) (B . *))

README contains more complex examples.

I think this is a very interesting library for anybody who is doing something with types in Common Lisp.

Brought to you by 40Ants under Creative Commons License