skills/coding/coding-nim/SKILL.md
Nim 2.x: macros, templates, compile-time, memory ARC/ORC, FFI, Nimble, systems programming
npx skillsauth add alphaonedev/openclaw-graph coding-nimInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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.
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.
static blocks.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.
Use the Nim compiler (nim) for core operations. Compile a file: nim c --verbosity:0 -r main.nim (flags: -r for run, --verbosity:0 for minimal output). For Nimble, install packages: nimble install somepkg. Define a macro:
macro doubleIt(x: expr): stmt =
result = quote do: `x` * 2
Call it as echo doubleIt(5). For FFI, import C: proc printf(format: cstring; args: varargs[pointer]) {.importc: "printf", header: "<stdio.h>".}. Config format: Use nim.cfg for settings, e.g., gcc.exe = "gcc" to specify compiler. Environment variables: Set $NIMBLE_DIR for package cache.
Integrate Nim with other languages via FFI; for C++, use importcpp. To embed in a project, compile Nim code to a shared library: nim c --app:lib -d:release mylib.nim. For CI/CD, use GitHub Actions with: run: nim c --opt:speed file.nim. If auth is needed (e.g., for Nimble registry), set env vars like $NIMBLE_TOKEN for private repos. Link against external libs: Add --passL:-lssl for OpenSSL. Ensure path configurations match, e.g., add path = "/path/to/headers" in nim.cfg.
In Nim, use try-except blocks for runtime errors:
try:
raise newException(ValueError, "Invalid input")
except ValueError:
echo "Handled error: ", getCurrentExceptionMsg()
For compile-time errors, enable detailed output with nim c --verbosity:2 file.nim. Check for memory issues by switching to ORC: nim c --gc:orc file.nim. Parse compiler output for specifics; common flags include --warnings:on to catch undeclared vars. Log errors with echo or a logging library like chronicles.
macro forEach(items: seq, body: stmt): stmt =
result = quote do: for item in `items`: `body`
Use it as: forEach(@[1, 2, 3], echo item). This generates efficient loops at compile-time.
proc cPrintf(format: cstring) {.importc: "printf", header: "<stdio.h>".}
cPrintf("%s\n", "Hello from Nim")
Compile with nim c --passC:-I/usr/include file.nim to link C headers, enabling seamless integration.
tools
Root web development: project structure, tooling selection, deployment decisions
development
WebAssembly: Rust/Go/C to WASM, wasm-bindgen, Emscripten, WASM Component Model
development
Vue 3: Composition API script setup, Pinia, Vue Router 4, SFCs, Vite, Nuxt 3
tools
Tailwind CSS 4: utility classes, config, JIT, arbitrary values, darkMode, plugins, shadcn/ui