yaklang-syntax

Teaches Yaklang DSL syntax with runnable examples covering variables, functions, closures, and error handling.

10|1|Updated Jun 16, 2026
One-click install
npx skills add https://github.com/yaklang/yak-skills --skill yaklang-syntax-yaklang
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: yaklang-syntax
Source: https://github.com/yaklang/yak-skills/tree/main/skills/yaklang-syntax
Command: npx skills add https://github.com/yaklang/yak-skills --skill yaklang-syntax-yaklang

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing or reading Yaklang (.yak) code is error-prone for AI agents and developers unfamiliar with this security-focused DSL, and guessing at syntax leads to subtle bugs like broken arrow functions or misused for-range loops. ## Core Features & Use Cases - Syntax Reference: Covers variables, types, slices, maps, control flow, functions (func/fn/arrow/closures/variadic/multiple returns), f-string interpolation, and the three error-handling patterns (~ tilde, if err, defer recover). - Documented Pitfalls: Lists real, tested traps such as _ placeholders breaking for-range values, arrow functions requiring block bodies, and reserved identifiers like double. - Runnable Examples: Ships examples/syntax-tour.yak and examples/error-handling.yak that self-test via yak <file> with assertions. - Use Case: When asked to write a hot-patch hook like beforeRequest = func(https, originReq, req) { return req }, consult this Skill to get the function literal and error-handling syntax right the first time. ## Quick Start Ask the AI to write a Yaklang script that iterates a slice, builds a map, and handles errors with the tilde operator, using this Skill's syntax rules.

Frequently Asked Questions about yaklang-syntax

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write functions in Yaklang?▼

Yaklang functions are values assigned to variables using func, fn, def, or arrow syntax, such as add = func(a, b) { return a + b }. Arrow functions require a block body like (x) => { return x * 2 }, since expression bodies are not parsed.

How does error handling work in Yaklang?▼

Yaklang library functions return an error as the last value, handled three ways: manual if err != nil checks, die(err) to panic on failure, or the tilde operator like codec.DecodeBase64(s)~ which auto-panics on error. Use defer with recover to catch panics.

Why does my Yaklang for-range loop produce undefined values?▼

Using an underscore placeholder like for _, v in slice makes the value undefined in Yaklang. Use a single variable for v in slice to get element values directly, or for i, v in slice with a real index name.

Does Yaklang support string interpolation like f-strings?▼

Yes, Yaklang supports f-string interpolation with the syntax f"user=${user} port=${port}". You can also use sprintf("%d-%s", 7, "x") for printf-style formatting.

What are common Yaklang syntax mistakes to avoid?▼

Common mistakes include using expression-bodied arrow functions, naming variables after reserved identifiers like double, assuming codec.RandomBytes exists, and trying to return values after a panic skips the return statement. Verify unknown APIs with desc(object) or by running test scripts.