C(a|d)ⁿr - car, cdr, caaaaddddr, and everything in between

c(a|d)ⁿr is an fun little library I hacked together last night, leveraging Racket's incredible flexibility for language extensions.

This module extends a number of built-in Racket functions that have obvious arbitrary extensions.

For instance, the caaaar-cddddr family of functions are defined for all combinations of as and ds, but only up to four! The obvious extension is to allow for an arbitrary number of each, and to simply generate them on the fly when they are referred to.

With this module required, it’s possible to use these functions just by naming them:

Examples:

> (caddddddddddr '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))
11
> (succcccc 1)
6
> (sub1234 5678)
4444

Read the full documentation and try it out!

2 Likes

Am I getting this right - this is happening at macro expansion - extending the racket compiler handle arbitrary combinations?

Am I right in assuming it be approximately as fast as the native functions at run time?

Stephen

That's right, they are expanded at compile time. They are compiled to normal lambda expressions, so they're as efficient as those.

1 Like