coding-nim
coding-nim
Purpose
This skill equips the AI to handle Nim 2.x programming tasks, focusing on advanced features like macros, templates, compile-time execution, memory management (ARC/ORC), FFI for interoperability, Nimble for package handling, and systems programming. Use it to generate, debug, and optimize Nim code efficiently.
When to Use
Apply this skill for systems-level programming needing low-level control, such as embedded systems, performance-critical apps, or when integrating with C/C++ via FFI. Use it for projects requiring compile-time metaprogramming (e.g., via macros) or automatic memory management with ARC/ORC to avoid manual garbage collection.
Key Capabilities
- Macros for code generation: Define reusable code transformations at compile-time.
- Templates for type-safe string-based metaprogramming.
- Compile-time execution: Run code during compilation using
staticblocks. - Memory management: Switch between ARC (automatic reference counting) and ORC (optional reference counting) via compiler flags.
- FFI: Call external libraries (e.g., C functions) without wrappers.
- Nimble: Manage dependencies and build projects like a package manager.
- Systems programming: Direct hardware access, concurrency, and cross-platform compilation.
Usage Patterns
To accomplish tasks, structure Nim code with modules and use the compiler for builds. For macros, define them in a separate proc and invoke at compile-time. When writing FFI code, use the importc pragma for C functions. For memory management, specify --gc:arc or --gc:orc flags during compilation. Always test code with nim check before full builds to catch errors early. Integrate templates for generic functions to reduce boilerplate.