applicates

generalized routine and symbol pointers

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version 0.4.0
License MIT
CI Status Failing
Downloads 0
Last Indexed 2026-09-01 07:18

Authors

  • metagn

Installation

nimble install applicates
choosenim install applicates
git clone https://github.com/metagn/applicates

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
applicates - - - - - - -

Dependencies

Package Version Optional
nim >= 0.20.0 No

Source

Repository https://github.com/metagn/applicates
Homepage https://metagn.github.io/applicates/applicates.html
Registry Source nimble_official

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.

import applicates

# `ApplicateArg` is `static Applicate`
proc map[T](s: seq[T], f: ApplicateArg): seq[T] =
  result.newSeq(s.len)
  for i in 0..<s.len:
    let x = s[i]
    result[i] = f.apply(x) # inlined at AST level
    # with `import applicates/calloperator`:
    result[i] = f(x)
    result[i] = x.f
    # with `import applicates/operators`:
    result[i] = \f(x)
    result[i] = \x.f
    result[i] = x |> 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 and 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.