# Bowen language guide for AI assistants This project is written in **Bowen** (`.bow` files), a high-level language that runs on Python 3.10+. Bowen looks like Python but is **not** Python. Follow these rules when you read or write `.bow` code. ## Run and check - Run: `python bowen.py run file.bow`, or in VS Code use the Run button / Ctrl+F5. - Check syntax: `python bowen.py check file.bow`. Errors print as `file:line:col: message`. - Tests: put `test "name"` blocks in `*.test.bow` files, then `python bowen.py test `. - Always run `check` (and the tests) after editing, and fix every reported error. ## Syntax essentials ```bow # Blocks use indentation (spaces only, 4 per level). A trailing colon is optional. name = "Aya" # assignment creates a variable; no let needed count_ = 3 # 'count', 'sum', 'min', 'max', 'first', 'select', 'where', # 'sort', 'group', 'take' are query words: avoid them as names say "Hello, {name}!" # say: the first string is a template label = $"{name} has {count_}" # elsewhere, prefix $ for a template (like Python f"...") note = "braces stay {literal}" # a plain string keeps its braces to square(n) = n ** 2 # one-line function to greet(who, greeting = "Hi") # block function with a default return $"{greeting}, {who}!" memo to fib(n) # memoized function return n if n < 2 else fib(n - 1) + fib(n - 2) to total(...nums) = nums.sum() # rest parameter collects extra arguments double = fn(x) => x * 2 # anonymous function ``` - Conditions must be **booleans**. `if items` is an error; write `if not items.isEmpty()` or `if len(items) > 0`. - `none`, `true`, `false` are lowercase. There is no `None`, `True`, `False`, `elif`, `def`, `class`, `lambda`, `import`, `print(f"...")` or `__init__`. - `else if` (two words), not `elif`. - `x if cond else y` and `when cond then x else y` are both expressions. - `1 < x < 10` chains, `not in` works, `"ab" * 3` repeats. - Ranges are **inclusive**: `1..5` is `[1, 2, 3, 4, 5]`; `range(0, 10, 5)` is `[0, 5, 10]`. - Strings use `"..."` or `'...'`. Multi-line text uses `"""..."""` (indentation is removed automatically). - Template formats follow Python: `"{price:,.2f}"`, `"{name:<10}"`, `"{ratio:.1%}"`. - `repeat 3 times as n` loops with n = 1, 2, 3. `for k, v in pairs(m)` unpacks. - Optional checked types: `to area(w: number, h: number) -> number = w * h`. Types: `text number int bool list map function any` or a record/enum name. `enum Size(small, medium, large)` makes `Size.small == "small"` and `Size.all`. (Don't name parameters with query words such as `by`, `count`, `sum`.) - `a?.b` and `a?.method()` give `none` when `a` is none or lacks the field. `[...xs, 4]`, `{...defaults, k: v}`, `f(...args)` spread. `0..= 70 sort by it desc take 3 # it = current item report = solves |> group by it.puzzle |> select {puzzle: it.key, best: it.items |> min it.seconds} answer = solve best choose x from 1..12 require 24 % x == 0 maximize x yield x ask age: int "Age?" between 1 and 120 # re-asks until valid ``` Stages: `where select sort by [desc] group by distinct by join … on … equals take skip count first sum average min max some every summarize by`. ## Library (no imports needed) `len text typeOf toInt toNumber keys values get put pairs zip indexed range sorted reverse unique map filter find indexOf flatten fold table words tally help` and modules `str math stats date fs json csv random time report`. Paths are relative to the program's folder. Use any Python module with `use python statistics`. Local modules: `use helpers` loads `helpers.bow` (names starting with `_` stay private). ## AI inside Bowen programs After `bowen install claude` and `bowen key claude` (or `chatgpt`), programs can call AI directly: ```bow use claude # or: use chatgpt / use ai (whichever is set up) say claude.ask("Write a haiku", "Answer in English.") # text answer; 2nd arg = instructions record Contact(name: text, email: text) c = claude.extract(email_text, Contact) # typed record filled from text mood = claude.classify(review, ["happy", "unhappy"]) # exactly one choice bot = claude.chat("Be brief.") say bot.send("Hello") # remembers earlier messages ``` Build prompts from values with `$"...{value}..."` (plain strings keep braces). Never put API keys in code. `bowen install ` installs any Python package for `use python `. ## Style Prefer methods and queries over manual loops, records with methods over loose maps, and `say` with templates for output. Keep functions short, and add `test` blocks for behavior you change.