Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/metagn/applicates

generalized compile time routine and symbol pointers
https://github.com/metagn/applicates

functional-programming library macros nim optimization templates

Last synced: about 1 month ago
JSON representation

generalized compile time routine and symbol pointers

Awesome Lists containing this project

README

        

# applicates

Generalized routine and symbol pointers, achieved by instantiating cached
routine definitions or symbols. The cached AST is referenced by a key,
this key is passed around as a compile time value to be instantiated.

This allows for fully inlined lambdas via anonymous templates, which is
the construct that the macros in this library mainly focus on.

```nim
import applicates

# `ApplicateArg` is `static Applicate`
proc map[T](s: seq[T], f: ApplicateArg): seq[T] =
result.newSeq(s.len)
for i in 0.. f

assert @[1, 2, 3, 4, 5].map(applicate do (x: int) -> int: x - 1) == @[0, 1, 2, 3, 4]
assert @[1, 2, 3, 4, 5].map(toApplicate(succ)) == @[2, 3, 4, 5, 6]
const double = x ==> x * 2
assert @[1, 2, 3, 4, 5].map(double) == @[2, 4, 6, 8, 10]
```

See [docs](https://metagn.github.io/applicates/docs/applicates.html) and
[tests](https://github.com/metagn/applicates/tree/master/tests) for more
example uses of this library. Tests are ran for multiple backends.

Note: Since `Applicate` is implemented as `distinct ApplicateKey` and is also usually used as `static Applicate` (for which `ApplicateArg` is an alias), this library fairly pushes Nim's type system, and errors are likely to be cryptic.