Basic Syntax
Variables
Section titled “Variables”Vibe has two ways to declare variables: let for mutable values and const for immutable values.
Let (Mutable)
Section titled “Let (Mutable)”let count = 0let name: text = "Alice"count = count + 1 // OK - can reassignConst (Immutable)
Section titled “Const (Immutable)”const API_KEY = "sk-..."const MAX_RETRIES: number = 3// API_KEY = "new" // Error - cannot reassign constPrivate Variables
Section titled “Private Variables”Mark variables as private to exclude them from AI context:
private let apiSecret = "sensitive-data"let publicInfo = "This is visible to AI"
// When AI processes prompts, it won't see apiSecretdo "Summarize the available data"Literals
Section titled “Literals”Strings
Section titled “Strings”Use double quotes, single quotes, or backticks:
let s1 = "double quoted"let s2 = 'single quoted'let s3 = `template with {variable} interpolation`Backticks support multi-line strings:
let poem = `Roses are red,Violets are blue,Vibe is great,And so are you.`All string types support {variable} interpolation:
let name = "Alice"let greeting = "Hello {name}!" // "Hello Alice!"Use backslash to escape braces:
let literal = "Use \{braces\} literally" // "Use {braces} literally"let path = "C:\\Users\\name" // "C:\Users\name"Numbers
Section titled “Numbers”let integer = 42let negative = -10let decimal = 3.14Booleans
Section titled “Booleans”let yes = truelet no = falselet maybe: text = null // Type annotation requiredlet data: json = null // OK - type is explicit// let empty = null // Error: cannot infer type from nullArrays
Section titled “Arrays”let empty: text[] = []let numbers = [1, 2, 3]let names = ["Alice", "Bob", "Carol"]Use + to concatenate arrays:
let a = [1, 2]let b = [3, 4]let combined = a + b // [1, 2, 3, 4]Objects
Section titled “Objects”let person = { name: "Alice", age: 30 }let config = { timeout: 5000, retries: 3 }Operators
Section titled “Operators”Arithmetic
Section titled “Arithmetic”| Operator | Description |
|---|---|
+ | Addition / string / array concatenation |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Modulo |
let sum = 10 + 5 // 15let greeting = "Hello, " + name // String concatenationComparison
Section titled “Comparison”| Operator | Description |
|---|---|
== | Equal |
!= | Not equal |
< | Less than |
> | Greater than |
<= | Less than or equal |
>= | Greater than or equal |
Logical
Section titled “Logical”| Operator | Description |
|---|---|
and | Logical AND |
or | Logical OR |
not | Logical NOT (unary) |
if x > 0 and x < 100 { print("In range")}
if not isValid { print("Invalid")}Member Access
Section titled “Member Access”Object Properties
Section titled “Object Properties”let person = { name: "Alice", age: 30 }let name = person.name // "Alice"Array Indexing
Section titled “Array Indexing”let items = ["a", "b", "c", "d", "e"]let first = items[0] // "a"let third = items[2] // "c"
// Negative indices count from the endlet last = items[-1] // "e"let secondLast = items[-2] // "d"Array Slicing
Section titled “Array Slicing”Python-style slicing with [start:end] syntax:
let items = [1, 2, 3, 4, 5]let slice = items[1:3] // [2, 3]let fromStart = items[:2] // [1, 2]let toEnd = items[3:] // [4, 5]
// Negative indices in sliceslet allButLast = items[:-1] // [1, 2, 3, 4]let lastTwo = items[-2:] // [4, 5]let middle = items[1:-1] // [2, 3, 4]Comments
Section titled “Comments”// Single-line commentlet x = 42 // Inline comment
/* Multi-line block comment */