ling-lang-chat-sft / 01_syntax.jsonl
taellinglin's picture
Update ling-lang chat SFT dataset
126f473 verified
Raw
History Blame Contribute Delete
51.6 kB
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "How do I declare a variable in ling-lang?"}, {"role": "assistant", "content": "Use `bind` to create a name-to-value binding:\n\n```ling\nbind x = 42\nbind name = \"Ling\"\nbind flag = true\n```\n\nThere's no separate `let`/`var`/`const` — `bind` is the one binding form. Re-using `bind` on the same name in the same scope shadows the previous binding rather than mutating it:\n\n```ling\nbind i = 0\nbind i = i + 1 # i is now 1, a new binding\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What's the entry point of a ling-lang program supposed to look like?"}, {"role": "assistant", "content": "Every Ling program's entry point is a binding named `start` set to a `do` block:\n\n```ling\nbind start = do {\n bind x = 10\n bind y = 20\n print(x + y)\n}\n```\n\n`do { ... }` evaluates each statement in order and the whole block evaluates to the value of its last expression — that's what gets assigned to `start`."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Explain what a `do` block is in Ling."}, {"role": "assistant", "content": "`do { ... }` is a block *expression* — it runs its statements in order and evaluates to the value of the last one, so you can bind it directly:\n\n```ling\nbind result = do {\n bind a = 3\n bind b = 4\n a * b\n}\n# result == 12\n```\n\nThe canonical use is the program entry point, `bind start = do { ... }`, but `do` blocks can appear anywhere an expression is expected, including as the arms of an `if`."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "How does Ling write functions? Show me the basic form."}, {"role": "assistant", "content": "With the `fn` keyword, a parameter list, and a `{ }` body whose last expression is the return value:\n\n```ling\nfn add(a, b) {\n a + b\n}\n```\n\nYou can also `return` explicitly:\n\n```ling\nfn add(a, b) {\n return a + b\n}\n```\n\nFunctions are values, so you can bind an anonymous one to a name:\n\n```ling\nbind square = fn (n) { n * n }\nbind result = square(7) # 49\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Does Ling support typed function signatures?"}, {"role": "assistant", "content": "Yes — parameters can carry `: Type` annotations and the return type follows `->`:\n\n```ling\nfn fib_iter(n: number) -> number {\n bind a = 0\n bind b = 1\n bind i = 0\n while i < n {\n bind t = a + b\n bind a = b\n bind b = t\n bind i = i + 1\n }\n a\n}\n```\n\nTypes are optional — untyped `fn add(a, b) { a + b }` is just as valid — but annotating is common in performance-sensitive code and is required for `own`-style ownership parameters."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What does an `if`/`else` look like in ling-lang, and can I use it as an expression?"}, {"role": "assistant", "content": "Ordinary branch syntax, no parentheses required around the condition:\n\n```ling\nif x > 0 {\n print(\"positive\")\n} else {\n print(\"non-positive\")\n}\n```\n\n`if` is also an expression — the last line of whichever branch runs becomes the value, so it's idiomatic to write things like:\n\n```ling\nbind greeting = if hour < 12 {\n \"Good morning\"\n} else {\n \"Good evening\"\n}\n```\n\nThis pattern (assigning the result of an `if`) shows up constantly in real Ling code."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "How do while loops work in Ling?"}, {"role": "assistant", "content": "`while <condition> { ... }`, re-binding the loop variable each iteration since Ling has no in-place mutation operator like `i++`:\n\n```ling\nbind i = 0\nwhile i < 10 {\n print(i)\n bind i = i + 1\n}\n```\n\nThis is the standard idiom seen throughout real Ling code — e.g. walking a query result:\n\n```ling\nbind rows = database_query(\"SELECT id, name FROM users\")\nbind i = 0\nwhile i < rows.len {\n bind row = list_get(rows, i)\n print(row.name)\n bind i = i + 1\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What's the syntax for a for loop over a range in ling-lang?"}, {"role": "assistant", "content": "`for <var> in <start>..<end> { ... }`. The range is exclusive of the end value:\n\n```ling\nfor i in 0..10 {\n print(i)\n}\n```\n\nThis is exactly how the game-AI example trains a neural net for 2000 epochs:\n\n```ling\nfor epoch in 0..2000 {\n nn_train(net, [0, 0], [0], 0.5)\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Can Ling's `for` loop iterate over something other than a numeric range?"}, {"role": "assistant", "content": "Yes — `for x in <list>` iterates elements directly, not just `a..b` ranges. From a real controller in production Ling code:\n\n```ling\nbind messages = [\"Hello\", \"World\", \"from\", \"Ling\"]\nfor msg in messages {\n print(msg)\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What is `form` used for in Ling?"}, {"role": "assistant", "content": "`form` declares a record/struct type — a name plus a list of field names:\n\n```ling\nform Point { x, y }\n```\n\nYou construct one by calling the form name like a function, and read fields with `.`:\n\n```ling\nbind start = do {\n bind p = Point(3, 4)\n print(p.x) # 3\n print(p.y) # 4\n}\n```\n\nThis is exactly the pattern used for HTTP response shapes in production Ling sites, e.g. `form Response { status, body, content_type, set_cookie, location }` in ling-lin.me's app.ling, constructed as `Response(status, body, content_type, \"\", \"\")`."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "How do enums / tagged variants work in Ling — what's the `choose` keyword for?"}, {"role": "assistant", "content": "`choose` declares a set of named variants (like a Rust `enum`), and `match` destructures them. From a real animation state machine in the Ling examples:\n\n```ling\nchoose AnimState { Idle, Walk, Run, Sit, Meditate, Swim }\n\nfn state_name(state) {\n return match state {\n Idle() => \"IDLE\",\n Walk() => \"WALK\",\n Run() => \"RUN\",\n Sit() => \"SIT\",\n Meditate() => \"MEDITATE\",\n Swim() => \"SWIM\",\n _ => \"IDLE\",\n }\n}\n```\n\nVariants can also carry data, e.g. `choose Shape { Circle(r), Rect(w, h), Dot }`, matched as `Circle(r) => ...`. The `_` arm is the catch-all/default case."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What does the `use` keyword do in a .ling file?"}, {"role": "assistant", "content": "`use \"path\"` imports another Ling module/file by path (relative, no extension), bringing its top-level bindings and functions into scope. From ling-lin.me's app.ling:\n\n```ling\nuse \"controllers/home\"\n```\n\nand a module can import several others, as fu.ling-lang.org's app.ling does:\n\n```ling\nuse \"models/schema\"\nuse \"models/users\"\nuse \"controllers/home\"\nuse \"controllers/auth\"\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What is `mod` for, and how do I call something inside one?"}, {"role": "assistant", "content": "`mod` groups related functions into a namespace, accessed with `::`:\n\n```ling\nmod timer {\n fn current_hour() {\n return 14\n }\n}\n\nbind start = do {\n bind hour = timer::current_hour()\n print(hour)\n}\n```\n\nThis mirrors the real `complex_hello.ling` example, which defines `mod safe_greet { fn try_print(msg) { ... } }` and calls it as `safe_greet::try_print(\"hi\")`."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "How do comments work in Ling — is it `#` or `//`?"}, {"role": "assistant", "content": "Both are valid comment markers in real Ling source. `#` line comments are used throughout the language reference docs and some examples (e.g. `examples/anim/animations/animation_map.ling`), while `//` line comments are the convention in most production `.ling` files (e.g. `ling-lin.me/app.ling`, `fu.ling-lang.org`'s controllers). Either works:\n\n```ling\n# this is a comment\nbind x = 1 # inline comment\n\n// this also works\nbind y = 2 // inline too\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What's this about Ling not having a unary minus operator?"}, {"role": "assistant", "content": "Correct — Ling has no prefix `-` operator. You can't write `-x`; instead subtract from zero:\n\n```ling\nbind negated = 0 - x\n```\n\nThis is called out explicitly in the language's own syntax reference as a gotcha, since most languages let you write `-x` directly."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What operators does Ling support?"}, {"role": "assistant", "content": "Standard arithmetic and comparison operators, all spelled the same across every language lexicon:\n\n- Arithmetic: `+ - * / %`\n- Comparison: `== != < <= > >=`\n- Logical: `&& || !`\n- `=` binds/assigns in a `bind` statement\n- `->` marks a function's return type: `fn f(n: number) -> number { ... }`\n- `.` does field/method access: `p.x`, `s.len`, `row.contains(\"/\")`\n- `|>` is the pipe operator\n- `::` accesses a name inside a `mod`, e.g. `timer::current_hour()`\n\nNote there is no unary minus — write `0 - x`, not `-x`."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "How do I write a list literal and index into it in Ling?"}, {"role": "assistant", "content": "Square brackets, comma-separated, and `[i]` to index (zero-based):\n\n```ling\nbind nums = [1, 2, 3]\nbind first = nums[0] # 1\n```\n\nBracket indexing is also used for element assignment inside a loop, as in the vector-doubling example from `examples/basics/advanced.ling`:\n\n```ling\nbind result = [0, 0, 0, 0, 0]\nfor i in 0..5 {\n result[i] = data[i] * 2\n}\n```\n\nFor building lists up incrementally (rather than literal `[...]`), use the functional `list_new()` / `list_push(list, value)` / `list_get(list, i)` builtins instead."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What literal values does Ling recognize out of the box?"}, {"role": "assistant", "content": "- Booleans: `true` / `false`\n- Result markers: `ok` / `bad`\n- Absent value: `none`\n- Numbers: `123`, `1.5`, `-7` (numeric literals may have a leading `-`, even though the `-` operator itself isn't unary-usable on a variable)\n- Text: `\"hello\"`\n- Lists: `[1, 2, 3]`\n- Ranges: `0..10`, used with `for`\n\nThese spellings are identical no matter which keyword lexicon (English, Chinese, Thai, ...) the rest of the file uses."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What built-in types does Ling have?"}, {"role": "assistant", "content": "Six built-in types: `number` (integer or float, always f64 under the hood for math builtins), `text` (string), `bool`, `list`, `map` (key/value), and `tuple` (fixed-size). Each has native spellings in every supported lexicon — e.g. `number` is `数` in Chinese, `숫자` in Korean, `จำนวน` in Thai."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "I keep seeing this in Ling docs — what is the 'multilingual keyword aliasing' feature everyone talks about?"}, {"role": "assistant", "content": "It's Ling's signature feature: essentially every keyword and builtin has native spellings in multiple human languages, and the lexer/parser accept all of them interchangeably — even mixed in the same file. `bind` / `令` (Chinese) / `束縛` (Japanese) / `바인드` (Korean) / `ผูก` (Thai) all mean the same thing, and `print`/`str_len`/`html_escape`-style builtins go further, with aliases documented (and implemented in the interpreter) across Chinese, Japanese, Korean, Thai, Persian, Arabic, Hebrew, Urdu, French, German, and Russian. For example `list_new` also accepts `รายการใหม่` (Thai), `新建列表` (Chinese), `فهرست_جدید` (Persian), `قائمة_جديدة` (Arabic), `רשימה_חדשה` (Hebrew), `نئی_فہرست` (Urdu), `nouvelle_liste` (French), `neue_liste` (German), and `новый_список` (Russian) — all calling the exact same builtin. A CLI tool, `lingfu normalize <lang>`, can even rewrite an entire project's keywords/builtins/filenames into one target language."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Show me the same tiny Ling program in two different keyword languages to prove this multilingual thing is real."}, {"role": "assistant", "content": "Here's a minimal program in English and Chinese keywords — both are valid, runnable Ling:\n\n```ling\n# English\nfn main() {\n bind x = 42\n print(\"Hello!\")\n}\n```\n\n```ling\n# Chinese\n函 主函数() {\n 令 甲 = 42\n 打印(\"你好!\")\n}\n```\n\n`函`=`fn`, `令`=`bind`, `打印`=`print`. They compile to the identical AST — you can even mix keyword languages within one file, since the interpreter accepts the union of every alias."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What does `p.x` mean when `p` is a `form` value — is `.` a general field-access operator?"}, {"role": "assistant", "content": "Yes. `.` accesses a named field on a `form` (struct) value, e.g. `p.x` for a `form Point { x, y }`, and it also doubles as a lightweight method-call syntax on built-in types — `s.len` reads a string or list's length, and `name.contains(\"/\")` calls the `contains` string builtin as a method. Both spellings (`contains(s, sub)` and `s.contains(sub)`) work; production Ling code uses the `.` form heavily for readability, e.g. `if name.contains(\"..\") { return false }`."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What does `list_new()` do?"}, {"role": "assistant", "content": "Creates and returns a new, empty list. It's the starting point for building up a list incrementally with `list_push`:\n\n```ling\nbind items = list_new()\nbind items = list_push(items, \"first\")\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Explain `list_push` — does it mutate the list in place?"}, {"role": "assistant", "content": "No — `list_push(list, value)` returns a *new* list with `value` appended; it does not mutate its argument in place. That means you must rebind the result, or the push is lost:\n\n```ling\nbind lst = list_new()\nbind lst = list_push(lst, 42) # correct — lst now has [42]\nlist_push(lst, 99) # WRONG — result discarded, lst still just [42]\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What does `list_get(lst, i)` do, and is it zero-indexed?"}, {"role": "assistant", "content": "`list_get(list, index)` returns the element at `index`, zero-indexed:\n\n```ling\nbind lst = list_new()\nbind lst = list_push(lst, \"a\")\nbind lst = list_push(lst, \"b\")\nbind first = list_get(lst, 0) # \"a\"\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What's the difference between `.len` and `str_len`/`list_len` in Ling?"}, {"role": "assistant", "content": "They return the same thing, just via different syntax. `str_len(s)` (or the shared `len`/`str_len` builtin) returns a string's length in characters, and the same `len` builtin returns a list's length in elements. `.len` is field-access sugar for the identical operation — `row.len` on a list, or `name.len` on a string — which is the form you'll see most in real Ling code, e.g. `if rows.len == 0 { return 0 }` in a database-model function."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What does `substr` do in Ling, and what are its arguments?"}, {"role": "assistant", "content": "`substr(s, start, len)` returns `len` characters of `s` starting at character index `start` (zero-based, clamped to the string's length if `len` runs past the end). `str_slice` is an exact alias for the same builtin. Example, pulling a function name out of a line of source:\n\n```ling\nbind trimmed = \"fn add(a, b) {\"\nbind name = substr(trimmed, 3, 3) # \"add\"\n```\n\nTo grab \"everything to the end\", pass an oversized length — real Ling code does exactly this: `substr(result, pos + 1, 9999)`."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What does `trim` do?"}, {"role": "assistant", "content": "`trim(s)` returns `s` with leading and trailing whitespace stripped:\n\n```ling\nbind clean = trim(\" hello \") # \"hello\"\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What does `split` do in Ling?"}, {"role": "assistant", "content": "`split(s, separator)` breaks a string into a list of pieces on every occurrence of `separator` and returns that list. If you omit the separator it defaults to splitting on newlines:\n\n```ling\nbind parts = split(\"a,b,c\", \",\") # [\"a\", \"b\", \"c\"]\nbind lines = split(source_text) # split on \"\\n\"\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What does `str_replace` do?"}, {"role": "assistant", "content": "`str_replace(s, from, to)` returns a copy of `s` with every occurrence of `from` replaced by `to`:\n\n```ling\nbind safe = str_replace(\"a(b)c\", \"(\", \"_\") # \"a_b)c\"\n```\n\nThis is used in Ling's own example tooling to sanitize function names for filenames — a chain of `str_replace` calls strips out `( ) { } - .` and spaces one at a time."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What does `starts_with` check, and what does it return?"}, {"role": "assistant", "content": "`starts_with(s, prefix)` returns a boolean — `true` if `s` begins with `prefix`, `false` otherwise:\n\n```ling\nif starts_with(line, \"fn \") {\n print(\"found a function definition\")\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What's `ends_with` for?"}, {"role": "assistant", "content": "`ends_with(s, suffix)` returns `true` if the string ends with `suffix`. Real usage from Ling's own visualization tool, classifying command-line arguments by file extension:\n\n```ling\nbind is_ling = ends_with(arg, \".ling\")\nbind is_svg = ends_with(arg, \".svg\")\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What does `str_strip_prefix` do, and how is it different from `starts_with`?"}, {"role": "assistant", "content": "`starts_with(s, prefix)` only tests and returns a bool; `str_strip_prefix(s, prefix)` actually removes `prefix` from the front of `s` and returns the remainder (or the original string unchanged if it doesn't start with `prefix`). It's exactly what you want for parsing an `Authorization: Bearer <token>` header, as fu.ling-lang.org's publish controller does:\n\n```ling\nfn extract_key(request) {\n bind header = request.authorization\n if header == \"\" {\n return \"\"\n }\n return str_strip_prefix(header, \"Bearer \")\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What does `str_find` return?"}, {"role": "assistant", "content": "`str_find(s, needle)` returns the character index of the first occurrence of `needle` in `s`, or `-1` if it's not found — so it's typically checked with `>= 0`:\n\n```ling\nif str_find(body, \"vtex_grid\") >= 0 {\n print(\"uses the grid texture\")\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What does `html_escape` do and when would I use it?"}, {"role": "assistant", "content": "`html_escape(s)` escapes characters that are special in HTML (like `<`, `>`, `&`, quotes) so untrusted text can be safely embedded in an HTML response body — used constantly in Ling web controllers when interpolating user data into markup:\n\n```ling\nbind safe_name = html_escape(user.username)\nbind html = \"<span>\" + safe_name + \"</span>\"\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What is `json_escape` for?"}, {"role": "assistant", "content": "`json_escape(s)` escapes a string so it's safe to embed inside a JSON string literal (escaping quotes, backslashes, control characters, etc.) — used when hand-building JSON responses:\n\n```ling\nbind body = \"{\\\"username\\\":\\\"\" + json_escape(user.username) + \"\\\"}\"\n```\n\nThis mirrors real code in fu.ling-lang.org's users controller, which builds a JSON array of user objects by hand with `json_escape` on every string field."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What does `format` do and what placeholder syntax does it use?"}, {"role": "assistant", "content": "`format(template, args...)` builds a string by substituting `{}` placeholders in `template` with the given arguments, in order — Rust-style formatting:\n\n```ling\nbind msg = format(\"{} v{}\", \"Ling\", 2030) # \"Ling v2030\"\n```\n\nIt also supports precision specifiers like `{:.1}` for one decimal place:\n\n```ling\nbind line = format(\"rating: {:.1} / 5.0\", 4.9) # \"rating: 4.9 / 5.0\"\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "How do I convert a string to a number and back in Ling?"}, {"role": "assistant", "content": "`to_number(s)` parses a string into a number, and `to_str(n)` (also spelled `str`/`num_str`) converts a value to its string form:\n\n```ling\nbind port = to_number(cli_arg(\"port\", \"8420\"))\nbind label = to_str(port) # \"8420\"\n```\n\nThis exact pattern — pulling a numeric CLI/query argument out as text, then parsing it — is how ling-lin.me's `app.ling` reads its `--port` flag."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What print-related builtins does Ling have?"}, {"role": "assistant", "content": "`print` (aliased `println`) writes value(s) to stdout, accepting multiple comma-separated arguments that get concatenated:\n\n```ling\nprint(\"epoch \", epoch, \" loss = \", loss)\n```\n\nThere's also `debug(v)` for inspecting a value while developing, and `panic(msg)` to abort with an error message."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What math builtins does Ling ship with?"}, {"role": "assistant", "content": "All the usual suspects, operating on `number` (f64) with angles in radians: `sin`, `cos`, `tan`, `asin`, `acos`, `atan2`, `sqrt`, `cbrt`, `pow(x, y)`, `abs`, `floor`, `ceil`, `round`, `trunc`, `min(a, b)`, `max(a, b)`, `clamp(x, lo, hi)`, and the constants `pi` and `tau`. Example:\n\n```ling\nbind d = sqrt(dx * dx + dy * dy)\nbind capped = clamp(health, 0, 100)\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What do `is_num`, `is_str`, `is_list`, and `is_bool` do?"}, {"role": "assistant", "content": "None of those exist in ling-lang — there are no runtime type-checking predicates (`is_num`/`is_str`/`is_list`/`is_bool`/`typeof`/etc. are not real builtins, confirmed absent from the interpreter's builtin dispatch). If you need to convert or coerce a value, the real builtins are `to_number(s)` and `to_str(v)`. If you're unsure what shape a value is, structure your program so it doesn't need to ask — e.g. know from context whether a `db_query` column is numeric versus text, rather than probing a value's type at runtime."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What does `str_contains` (or the `.contains` method form) check?"}, {"role": "assistant", "content": "It tests whether a string contains a given substring anywhere, returning a boolean. Ling code commonly calls it as a method: `name.contains(\"/\")`. It's used heavily for input validation — fu.ling-lang.org's publish controller rejects unsafe package names by chaining `.contains` checks:\n\n```ling\nfn is_safe_name(s) {\n if s == \"\" { return false }\n if s.contains(\"/\") { return false }\n if s.contains(\"..\") { return false }\n return true\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a ling-lang function that returns the first 10 characters of a string."}, {"role": "assistant", "content": "```ling\nfn first_10(s) {\n return substr(s, 0, 10)\n}\n```\n\n`substr(s, start, len)` takes a starting index and a length, so `substr(s, 0, 10)` grabs up to 10 characters from the beginning (fewer if the string is shorter)."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a for loop that prints the numbers 0 through 9 in Ling."}, {"role": "assistant", "content": "```ling\nbind start = do {\n for i in 0..9 {\n print(i)\n }\n}\n```\n\n`0..9` is exclusive of the end, so this prints 0 through 8. Use `0..10` if you want it to include 9 (i.e. print exactly ten numbers, 0 through 9)."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "I need a recursive Fibonacci function in Ling with type annotations."}, {"role": "assistant", "content": "```ling\nfn fibonacci(n: number) -> number {\n if n <= 1 {\n n\n } else {\n fibonacci(n - 1) + fibonacci(n - 2)\n }\n}\n\nbind start = do {\n for i in 0..10 {\n print(\"fibonacci(\", i, \") = \", fibonacci(i))\n }\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write an iterative (non-recursive) Fibonacci function in Ling — I want it fast."}, {"role": "assistant", "content": "```ling\nfn fib_iter(n: number) -> number {\n bind a = 0\n bind b = 1\n bind i = 0\n while i < n {\n bind t = a + b\n bind a = b\n bind b = t\n bind i = i + 1\n }\n a\n}\n```\n\nThis mirrors the pattern used in Ling's own benchmark suite (`bench_opt1.ling` etc.) for testing interpreter performance — an accumulator loop instead of exponential recursion."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Define a Point struct in Ling with x and y fields, and write code that creates one and prints both fields."}, {"role": "assistant", "content": "```ling\nform Point { x, y }\n\nbind start = do {\n bind p = Point(3, 4)\n print(p.x)\n print(p.y)\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a function that builds a greeting string by concatenation, mixing a name and a count."}, {"role": "assistant", "content": "```ling\nfn greet(name, count) {\n return \"Hello, \" + name + \"! This is visit number \" + to_str(count) + \".\"\n}\n```\n\n`+` concatenates strings directly; use `to_str()` to turn a number into text first if you're not using `format()`."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Same greeting, but using `format` instead of `+` concatenation."}, {"role": "assistant", "content": "```ling\nfn greet(name, count) {\n return format(\"Hello, {}! This is visit number {}.\", name, count)\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a function that builds a list of squares from 0 to 9 using the list builtins."}, {"role": "assistant", "content": "```ling\nfn squares() {\n bind result = list_new()\n for i in 0..10 {\n bind result = list_push(result, i * i)\n }\n return result\n}\n```\n\nRemember `list_push` returns a *new* list, so each iteration rebinds `result` to the updated one."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a function that sums all the numbers in a list, walking it with a while loop."}, {"role": "assistant", "content": "```ling\nfn sum_list(nums) {\n bind total = 0\n bind i = 0\n while i < nums.len {\n bind total = total + list_get(nums, i)\n bind i = i + 1\n }\n return total\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a function that checks whether a string is a safe filename — no slashes, no `..`, no spaces."}, {"role": "assistant", "content": "```ling\nfn is_safe_name(s) {\n if s == \"\" {\n return false\n }\n if s.contains(\"/\") { return false }\n if s.contains(\"\\\\\") { return false }\n if s.contains(\"..\") { return false }\n if s.contains(\" \") { return false }\n return true\n}\n```\n\nThis is the same defensive pattern fu.ling-lang.org uses before writing an uploaded package name to a file path — reject anything that could enable path traversal."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a function that extracts a Bearer token from an Authorization header string."}, {"role": "assistant", "content": "```ling\nfn extract_bearer_token(header) {\n if header == \"\" {\n return \"\"\n }\n return str_strip_prefix(header, \"Bearer \")\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a Ling function that builds an HTML unordered list from a list of strings, escaping each item."}, {"role": "assistant", "content": "```ling\nfn html_list(items) {\n bind body = \"\"\n bind i = 0\n while i < items.len {\n bind body = body + \"<li>\" + html_escape(list_get(items, i)) + \"</li>\"\n bind i = i + 1\n }\n return \"<ul>\" + body + \"</ul>\"\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a Ling function that builds a minimal JSON array of objects from a list of package records with `name` and `description` fields."}, {"role": "assistant", "content": "```ling\nfn packages_json(pkgs) {\n bind i = 0\n bind parts = \"\"\n while i < pkgs.len {\n bind pkg = list_get(pkgs, i)\n if i > 0 {\n bind parts = parts + \",\"\n }\n bind parts = parts +\n \"{\\\"name\\\":\\\"\" + json_escape(pkg.name) + \"\\\",\" +\n \"\\\"description\\\":\\\"\" + json_escape(pkg.description) + \"\\\"}\"\n bind i = i + 1\n }\n return \"[\" + parts + \"]\"\n}\n```\n\nThis is the exact shape used by fu.ling-lang.org's `/api/organizations` and `/api/users` JSON endpoints — iterate with a while loop, comma-join, `json_escape` every string field."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a function `t(lang, en, th)` that picks between an English and a Thai string based on a language code."}, {"role": "assistant", "content": "```ling\nfn t(lang, en, th) {\n if lang == \"th\" {\n return th\n }\n return en\n}\n```\n\nReal multilingual Ling sites extend this to more languages with the same shape — ling-lin.me's `t(lang, en, th, ko, ja, zh)` checks each code in turn and falls through to English as the default."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a state-machine enum in Ling for a traffic light, with a function that returns the next state."}, {"role": "assistant", "content": "```ling\nchoose Light { Red, Yellow, Green }\n\nfn next_light(state) {\n return match state {\n Red() => Green(),\n Green() => Yellow(),\n Yellow() => Red(),\n _ => Red(),\n }\n}\n```\n\nModeled on the real `AnimState` state machine (`choose AnimState { Idle, Walk, Run, Sit, Meditate, Swim }`) from `examples/anim/animations/animation_map.ling`."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a `mod` in Ling that wraps a couple of time-related helper functions, and call one from `start`."}, {"role": "assistant", "content": "```ling\nmod clock {\n fn current_hour() {\n return 14\n }\n\n fn is_morning(hour) {\n return hour < 12\n }\n}\n\nbind start = do {\n bind hour = clock::current_hour()\n print(clock::is_morning(hour))\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a function that trims a line and checks if it starts with a function definition keyword, in either English or Thai."}, {"role": "assistant", "content": "```ling\nfn is_fn_def(line) {\n bind trimmed = trim(line)\n bind is_en = starts_with(trimmed, \"fn \")\n bind is_th = starts_with(trimmed, \"ฟังก์ชัน \")\n return is_en || is_th\n}\n```\n\nThis mirrors Ling's own `examples/tools/visualize.ling`, which scans source files for function definitions across multiple keyword languages this same way."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a function that splits a comma-separated string into a list and trims whitespace off each piece."}, {"role": "assistant", "content": "```ling\nfn split_trimmed(s, sep) {\n bind raw = split(s, sep)\n bind result = list_new()\n bind i = 0\n while i < raw.len {\n bind result = list_push(result, trim(list_get(raw, i)))\n bind i = i + 1\n }\n return result\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a rate limiter helper: return true if `count` is below `max_allowed`, else false."}, {"role": "assistant", "content": "```ling\nfn under_limit(count, max_allowed) {\n if count > max_allowed {\n return false\n }\n return true\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a small program that opens a window and draws a filled circle, using the `do` block entry point."}, {"role": "assistant", "content": "```ling\nbind start = do {\n open_window(800, 600)\n draw_disc(400.0, 300.0, 120.0)\n present()\n}\n```\n\nThis is Ling's own \"first pixel in ~5 lines\" showcase snippet — `open_window`, a draw call, then `present()` to flush the frame."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a function that safely divides two numbers, returning 0 instead of crashing on division by zero."}, {"role": "assistant", "content": "```ling\nfn safe_div(a, b) {\n if b == 0 {\n return 0\n }\n return a / b\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a function that clamps a health value between 0 and 100 using a math builtin."}, {"role": "assistant", "content": "```ling\nfn clamp_health(hp) {\n return clamp(hp, 0, 100)\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a function that builds a rate-limit key by combining an action name and client IP, falling back when the IP is empty."}, {"role": "assistant", "content": "```ling\nfn rate_limit_key(request, action, id) {\n bind ip = request.client_ip\n if ip == \"\" {\n return action + \": noip:\" + id\n }\n return action + \":\" + ip + \":\" + id\n}\n```\n\nAdapted from fu.ling-lang.org's `models/users.ling`, which builds rate-limit keys this exact way before checking a SQLite-backed counter."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a function that counts how many times a substring appears at the start of any line in a block of text."}, {"role": "assistant", "content": "```ling\nfn count_prefix_lines(text, prefix) {\n bind lines = split(text, \"\\n\")\n bind count = 0\n bind i = 0\n while i < lines.len {\n if starts_with(trim(list_get(lines, i)), prefix) {\n bind count = count + 1\n }\n bind i = i + 1\n }\n return count\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a function that strips a `.ling` file extension off a filename."}, {"role": "assistant", "content": "```ling\nfn strip_ling_ext(name) {\n return str_replace(name, \".ling\", \"\")\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Write a function that returns true only if a value is a non-empty string."}, {"role": "assistant", "content": "```ling\nfn is_nonempty_str(v) {\n if is_str(v) == false {\n return false\n }\n return v != \"\"\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "This crashes: `bind negative = -x`. What's wrong?"}, {"role": "assistant", "content": "Ling doesn't have a unary minus operator, so `-x` isn't valid syntax on its own — it only parses `-` as part of a numeric literal, not as a prefix operator on a variable. Subtract from zero instead:\n\n```ling\nbind negative = 0 - x\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Why doesn't my list have the item I pushed?\n\n```ling\nbind items = list_new()\nlist_push(items, \"hello\")\nprint(items.len) # prints 0\n```"}, {"role": "assistant", "content": "`list_push` doesn't mutate `items` in place — it returns a *new* list with the item appended, and you discarded that return value. Rebind `items` to the result:\n\n```ling\nbind items = list_new()\nbind items = list_push(items, \"hello\")\nprint(items.len) # prints 1\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Fix this — it won't parse:\n\n```ling\nfn add(a, b) {\n a + b\n```"}, {"role": "assistant", "content": "The function body's closing brace is missing. It should be:\n\n```ling\nfn add(a, b) {\n a + b\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What's wrong with this for loop?\n\n```ling\nfor i 0..10 {\n print(i)\n}\n```"}, {"role": "assistant", "content": "It's missing the `in` keyword between the loop variable and the range — Ling's `for` syntax is `for <var> in <range> { ... }`:\n\n```ling\nfor i in 0..10 {\n print(i)\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "This `match` never hits the `Idle` case — what's wrong?\n\n```ling\nreturn match state {\n Idle => \"IDLE\",\n Walk => \"WALK\",\n _ => \"???\",\n}\n```"}, {"role": "assistant", "content": "The `choose` variants need call-style parens in the match arms, even for variants with no data — `Idle()` and `Walk()`, not bare `Idle`/`Walk`:\n\n```ling\nreturn match state {\n Idle() => \"IDLE\",\n Walk() => \"WALK\",\n _ => \"???\",\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "My `while` loop never terminates:\n\n```ling\nbind i = 0\nwhile i < 10 {\n print(i)\n i = i + 1\n}\n```\nWhat's wrong?"}, {"role": "assistant", "content": "`i = i + 1` alone isn't valid — Ling doesn't have a bare re-assignment operator; you must use `bind` again to rebind `i` in the same scope:\n\n```ling\nbind i = 0\nwhile i < 10 {\n print(i)\n bind i = i + 1\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Why does field access fail here?\n\n```ling\nform Point { x, y }\nbind start = do {\n bind p = Point(3, 4, 5)\n print(p.x)\n}\n```"}, {"role": "assistant", "content": "`Point` was declared with two fields (`x, y`) but constructed with three arguments (`3, 4, 5`) — that's a wrong-arity construction and will error. Fix it by matching the field count:\n\n```ling\nform Point { x, y }\nbind start = do {\n bind p = Point(3, 4)\n print(p.x)\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Is this substr call correct if I want just the first 5 characters of `s`?\n\n```ling\nbind head = substr(s, 0, 5)\n```"}, {"role": "assistant", "content": "Yes, that's correct — `substr(s, start, len)` takes a length as its third argument, not an end index, so `substr(s, 0, 5)` returns the first 5 characters. A common mistake is treating the third argument as an end index (e.g. writing `substr(s, 2, 5)` expecting characters 2 through 5); it actually returns 5 characters starting at index 2."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "This is supposed to import a sibling module but nothing gets loaded:\n\n```ling\nload \"controllers/home\"\n```"}, {"role": "assistant", "content": "`load` isn't a Ling keyword — the import keyword is `use`:\n\n```ling\nuse \"controllers/home\"\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Why does this `if`-as-expression fail to bind a value?\n\n```ling\nbind label = if score > 90 {\n \"A\"\n}\n```"}, {"role": "assistant", "content": "An `if` used as an expression needs an `else` branch, since without one there's no value to produce when the condition is false. Add an `else`:\n\n```ling\nbind label = if score > 90 {\n \"A\"\n} else {\n \"B\"\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "What's wrong with this string check?\n\n```ling\nif name.equals(\"admin\") {\n print(\"blocked\")\n}\n```"}, {"role": "assistant", "content": "`equals` isn't a Ling string builtin — string equality uses the `==` operator directly:\n\n```ling\nif name == \"admin\" {\n print(\"blocked\")\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "This function never returns the right thing — help me spot the bug:\n\n```ling\nfn is_safe_name(s) {\n if s.contains(\"/\") {\n false\n }\n return true\n}\n```"}, {"role": "assistant", "content": "The `if` branch's value (`false`) is just an expression sitting in the middle of the function — it's never returned, so execution always falls through to `return true` even for unsafe names. Use an explicit `return` inside the branch:\n\n```ling\nfn is_safe_name(s) {\n if s.contains(\"/\") {\n return false\n }\n return true\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Why does this module call fail?\n\n```ling\nmod clock {\n fn current_hour() {\n return 14\n }\n}\n\nbind h = clock.current_hour()\n```"}, {"role": "assistant", "content": "Namespaced functions inside a `mod` are called with `::`, not `.` — `.` is for field/method access on values, while `::` reaches into a module's namespace:\n\n```ling\nmod clock {\n fn current_hour() {\n return 14\n }\n}\n\nbind h = clock::current_hour()\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "This range loop skips the last element I want — why?\n\n```ling\nbind items = [10, 20, 30]\nfor i in 0..items.len {\n print(list_get(items, i))\n}\n```\nIs the range wrong?"}, {"role": "assistant", "content": "Actually that's correct as written — `0..items.len` with a 3-element list is `0..3`, which is exclusive of the end, giving indices 0, 1, 2 — exactly the valid indices for a 3-element list. If you were seeing a missed element, the likely bug is using `0..(items.len - 1)` instead, which would stop one index too early and skip the last item."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Fix this JSON-building snippet — the output has invalid quoting:\n\n```ling\nbind body = \"{\\\"name\\\":\\\"\" + user.name + \"\\\"}\"\n```"}, {"role": "assistant", "content": "Raw user data is being spliced straight into the JSON string without escaping — if `user.name` contains a `\"` or backslash, the JSON breaks (or worse, allows injection). Wrap it in `json_escape`:\n\n```ling\nbind body = \"{\\\"name\\\":\\\"\" + json_escape(user.name) + \"\\\"}\"\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Why doesn't this print anything useful?\n\n```ling\nbind start = do {\n bind msg = \"hi\"\n}\nprint(msg)\n```"}, {"role": "assistant", "content": "`msg` is bound *inside* the `do { ... }` block that makes up `start`, so it's scoped to that block and doesn't exist outside it — `print(msg)` at the top level references an undefined name. Either print from inside the block, or have the block's last expression produce the value you need:\n\n```ling\nbind start = do {\n bind msg = \"hi\"\n print(msg)\n}\n```"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "This HTML output isn't escaped and I'm worried about XSS — what's the fix?\n\n```ling\nbind html = \"<p>\" + comment.body + \"</p>\"\n```"}, {"role": "assistant", "content": "Untrusted text is being embedded directly into HTML. Run it through `html_escape` first:\n\n```ling\nbind html = \"<p>\" + html_escape(comment.body) + \"</p>\"\n```\n\nThis is the standard pattern in every Ling web controller that renders user-supplied strings."}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "Why does this comparison always evaluate as true?\n\n```ling\nif valid = true {\n print(\"ok\")\n}\n```"}, {"role": "assistant", "content": "`=` is the bind/assignment operator, not equality — inside an `if` condition you need `==`:\n\n```ling\nif valid == true {\n print(\"ok\")\n}\n```\n\n(Or just `if valid { ... }` directly, since `valid` is already a boolean.)"}]}
{"messages": [{"role": "system", "content": "You are a coding assistant for the Ling programming language."}, {"role": "user", "content": "This `choose`/`match` is missing something the compiler complains about — what?\n\n```ling\nchoose Light { Red, Yellow, Green }\n\nfn next(state) {\n return match state {\n Red() => Green(),\n Green() => Yellow(),\n }\n}\n```"}, {"role": "assistant", "content": "The match has no arm for `Yellow()` and no wildcard `_` fallback, so a `Yellow` value has nowhere to go. Add the missing case (and it's good practice to keep a `_` catch-all too):\n\n```ling\nchoose Light { Red, Yellow, Green }\n\nfn next(state) {\n return match state {\n Red() => Green(),\n Green() => Yellow(),\n Yellow() => Red(),\n _ => Red(),\n }\n}\n```"}]}