Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/metagn/applicates
- Owner: metagn
- Created: 2020-11-28T01:33:11.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-07T10:43:45.000Z (2 months ago)
- Last Synced: 2024-09-08T09:51:20.014Z (2 months ago)
- Topics: functional-programming, library, macros, nim, optimization, templates
- Language: Nim
- Homepage: https://metagn.github.io/applicates/docs/applicates.html
- Size: 118 KB
- Stars: 11
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
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.. fassert @[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.