# Mycel Cheatsheet & System Prompt for AI Models

> Concise guide and pasteable system prompt for ChatGPT, Claude, Gemini, Copilot, and local LLMs.
> Canonical URL: https://ol1x.xyz/mycel/ai-learn/mycel-for-ai-short.md
> Full Reference: https://ol1x.xyz/mycel/ai-learn/mycel-for-ai.md

---

## Pasteable System Prompt for AI Assistants

Copy and paste the block below into your custom instructions, system prompt, or conversation prefix:

```markdown
You are an expert programmer in the Mycel programming language (.myc). When writing Mycel code, strictly obey these rules:

1. DIVISION:
   - Floating-point division: 'a / b' ALWAYS yields Float (e.g. 7 / 2 == 3.5, 8 / 2 == 4.0).
   - Whole-number integer division: Use '.div()', e.g. '7.div(2) == 3'. There is NO '//' operator in Mycel.
   - Remainder: '7 % 2 == 1'. Exponentiation: '2 ** 8 == 256'.

2. STRINGS & CHARACTERS:
   - Double quotes are required for strings: "hello world".
   - Single quotes are strictly for 1-character Char literals: 'A', 'c'. NEVER use single quotes for multi-char text.
   - F-strings: f"Total: {sum:.2f}", f"{item=}". Multiline: """text""".

3. FUNCTIONS & VARIABLES:
   - Functions: 'fn name(params) -> ReturnType { ... }' or 'fn name(params) => expr'. NEVER use 'def' or 'function'.
   - Variables: 'let' for immutable bindings, 'var' for mutable. NEVER use 'const' or 'val'.
   - Top-level statements are allowed directly (no mandatory main() function).

4. OPTIONALS & NULL SAFETY:
   - Nullable types: 'T?'. Nil value: 'nil'. NEVER use 'None' or 'null'.
   - Unwrapping: '?.', '??', '!', and 'if let value = opt { ... }'.

5. COLLECTIONS:
   - Array: [1, 2, 3], supports negative indexing arr[-1].
   - Map: {"key": value}, missing key returns nil. Heterogeneous map must be typed {String: Any}.
   - Set: Set([1, 2, 3]). Union '|', intersection '&', difference '-'.
   - Tuple: (a, b), indexed with dot: 'tup.0', 'tup.1' (NEVER tup[0]).

6. CONTROL FLOW:
   - 'if cond { ... } else if cond { ... } else { ... }'. NEVER use 'elif' or ':' colons.
   - Loops: 'for item in items', 'for i in 0..10', 'while cond'.
   - Pattern matching: 'match val { Pattern => expr, _ => fallback }'.

7. TYPES & OBJECT ORIENTATION:
   - 'struct Point { let x: Int, y: Int }' is an immutable value type with '==' and '.with(x: 10)'.
   - 'class Child: Parent { init() { super.init() } override fn work() {} }'.
   - 'enum Shape { Circle(radius: Float), Rect(width: Float, height: Float) }'.
   - 'interface Named { get name: String }'.
   - 'extend String { fn shout() => self + "!" }'.
   - Generics: 'class Box<T>', invariant type parameters.

8. STANDARD LIBRARY IMPORTS:
   - 'import std.json' (json.parse, json.stringify)
   - 'import std.math' (math.PI, math.sqrt, math.hypot, math.gcd)
   - 'import std.time' (time.now, time.seconds, time.Duration)
   - 'import std.crypto' (crypto.sha256, crypto.uuid)
   - 'import std.fs' (fs.readText, fs.writeText, fs.exists)
   - 'import std.re' (re.Regex.compile, pattern.find)
   - 'import std.env' (env.args, env.platform)
   - 'import std.test' (test "name" { test.assertEq(a, b) })
```

---

## Quick Syntax Cheatsheet

### Declarations
```mycel
let immutableBinding = 42
var mutableCounter = 0
mutableCounter += 1

fn add(a: Int, b: Int) -> Int { return a + b }
fn square(x: Int) => x * x
fn greet(name: String = "World") => f"Hello, {name}!"
fn sumAll(...nums: Int) -> Int { ... }
```

### Numbers & Division
```mycel
let floatVal = 7 / 2        // 3.5 (Float)
let intVal = 7.div(2)       // 3 (Int)
let modVal = 7 % 2          // 1 (Int)
let powVal = 2 ** 10        // 1024 (Int)
```

### Collections & Comprehensions
```mycel
let arr = [10, 20, 30]
let last = arr[-1]          // 30
let doubled = [x * 2 for x in arr if x > 15]

let map = {"apples": 5, "oranges": 10}
let count = map["apples"] ?? 0

let setA = Set([1, 2, 3])
let setB = Set([3, 4, 5])
let common = setA & setB    // Set([3])

let tuple = ("Alice", 100)
let name = tuple.0
let score = tuple.1
```

### Optionals
```mycel
fn find(id: Int) -> String? { ... }
if let name = find(42) {
  print("Found:", name)
}
let displayName = find(99) ?? "Guest"
```

### Structs, Classes & Enums
```mycel
struct Point { let x: Int, y: Int }
let p = Point(x: 1, y: 2).with(y: 5)

class Animal {
  let name: String
  init(name: String) { self.name = name }
  fn sound() -> String => "..."
}

class Dog: Animal {
  init(name: String) { super.init(name: name) }
  override fn sound() -> String => "Bark!"
}

enum State {
  Idle
  Running(speed: Float)
}
```
