Using the power of Nim to defile its type safety
- Nim 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| src | ||
| tests | ||
| .gitignore | ||
| dynval.nimble | ||
| LICENSE | ||
| README.md | ||
dynval
Using the power of Nim to defile its type safety
What?
This is a library that provides a type called DynVal which can box all primitives, strings and references to objects inheriting from RootObj.
It provides necessary converters and type coercion to provide dynamic typing in Nim.
Importing this module will destroy the type safety and performance of your program.
Examples
import dynval
var thing1: DynVal = 10
assert thing1 == "10"
thing1 = true
if thing1:
assert true
inc thing1
var thing2: DynVal = thing1 * 10
thing2 &= 1 + false
assert thing2 == "200" + 1
import dynval
var times: DynVal = "10"
proc loopNTimes(n: int) =
for i in 0 ..< n:
echo "i: ", i
loopNTimes(times)
See the tests directory for more examples.
What's missing?
- Dynamic objects (basically tables with normal field access syntax)
- Support for putting procs inside
DynVal- This would require using a macro to generate typeguards, and then exposing a dot call operator with a signature like
proc (args: varargs[auto]), and then doing magic on that for runtime type checking.
- This would require using a macro to generate typeguards, and then exposing a dot call operator with a signature like