Complete reference for the Rohas programming language.
- Variables
- Data Types
- Operators
- Template Literals
- Functions
- Control Flow
- Prompts
- Flows
- Tool Calls
- Type System
- Memory & State
Variables in Rohas are dynamically typed by default, but can be explicitly typed.
# Simple assignment
name = "Alice"
age = 30
isActive = true
# Type annotations (optional)
name: string = "Alice"
age: number = 30
isActive: boolean = true
Variables are mutable by default. Use const for constants:
const PI = 3.14159
const API_URL = "https://api.example.com"
string- Text datanumber- Numeric data (integers and floats)boolean-trueorfalsenull- Null value
array- Ordered lists:[1, 2, 3]record- Key-value pairs:{ name: "Alice", age: 30 }
# Strings
greeting = "Hello, World!"
multiline = "Line 1
Line 2
Line 3"
# Numbers
integer = 42
float = 3.14
negative = -10
# Booleans
isTrue = true
isFalse = false
# Arrays
numbers = [1, 2, 3, 4, 5]
names = ["Alice", "Bob", "Charlie"]
mixed = [1, "two", true]
# Records
person = {
name: "Alice",
age: 30,
city: "San Francisco"
}
# Nested structures
company = {
name: "Acme Corp",
employees: [
{ name: "Alice", role: "Engineer" },
{ name: "Bob", role: "Designer" }
]
}
a = 10
b = 3
sum = a + b # 13
difference = a - b # 7
product = a * b # 30
quotient = a / b # 3.333...
remainder = a % b # 1
power = a ^ b # 1000
a = 10
b = 20
a == b # false
a != b # true
a < b # true
a > b # false
a <= b # true
a >= b # false
a = true
b = false
a && b # false (AND)
a || b # true (OR)
!a # false (NOT)
firstName = "Alice"
lastName = "Smith"
fullName = firstName + " " + lastName # "Alice Smith"
Template literals allow embedded expressions using {expression} syntax:
name = "Alice"
age = 30
city = "San Francisco"
# Simple interpolation
greeting = "Hello, {name}!"
# Expression evaluation
info = "{name} is {age} years old and lives in {city}"
# Complex expressions
count = 5
message = "You have {count} items, which is {count * 2} total"
# Nested expressions
price = 10.50
quantity = 3
total = "Total: ${price * quantity}"
function greet(name): String {
return "Hello, " + name + "!"
}
function add(a, b): Number {
return a + b
}
# Usage
message = greet("World")
result = add(5, 3)
Async functions can use await to wait for asynchronous operations:
async function fetchData(url): String {
response = await httpGet(url)
return response
}
async function processData(input): String {
data = await fetchData("https://api.example.com/data")
processed = await process(data)
return processed
}
# Usage
data = await fetchData("https://api.example.com")
Functions can have typed or untyped parameters:
# Typed parameters
function multiply(a: number, b: number): number {
return a * b
}
# Untyped parameters
function greet(name) {
return "Hello, " + name + "!"
}
# Default values (if supported)
function greet(name = "World") {
return "Hello, " + name + "!"
}
age = 20
if age >= 18 {
status = "adult"
} else {
status = "minor"
}
# Nested conditions
if score >= 90 {
grade = "A"
} else if score >= 80 {
grade = "B"
} else if score >= 70 {
grade = "C"
} else {
grade = "F"
}
# Iterate over array
numbers = [1, 2, 3, 4, 5]
for num in numbers {
print num * 2
}
# Iterate over records
sales = [
{ product: "Widget", quantity: 10 },
{ product: "Gadget", quantity: 5 }
]
for sale in sales {
if sale.quantity > 5 {
prompt "High volume: " + sale.product
}
}
count = 0
while count < 10 {
print count
count = count + 1
}
Prompts are the core feature for interacting with LLMs:
prompt "Hello, how are you?"
prompt "Explain quantum computing"
model: "gpt-4"
temperature: 0.7
maxTokens: 500
stream: true
topic = "artificial intelligence"
prompt "Explain " + topic + " in simple terms"
model: "gpt-4"
temperature: 0.5
name = "Alice"
age = 30
prompt "{name} is {age} years old. Write a birthday message."
model: "gpt-4"
prompt "What's the weather in San Francisco?"
tools: [
{
name: "weatherTool",
description: "Get weather for a city",
parameters: {
city: "String"
}
}
]
model: "gpt-4"
prompt "Remember my name is Alice"
memory: "long_term"
prompt "What's my name?"
memory: "long_term"
prompt "Process this order"
state: {
orderId: "12345",
customerId: "67890",
priority: "high"
}
Flows enable multi-step workflows. See FLOWS.md for detailed documentation.
flow myFlow {
step first {
prompt "First step"
}
step second {
prompt "Second step"
}
}
flow processOrder {
step validate {
prompt "Validate order"
state: { orderId: "12345" }
}
step process {
prompt "Process order"
state: { orderId: "12345", status: "processing" }
}
}
flow parallelFlow {
parallel step task1 {
prompt "Task 1"
}
parallel step task2 {
prompt "Task 2"
}
step combine {
prompt "Combine results"
}
}
# Call a tool
result = call calculatorTool("add", 10, 20)
# Multiple calls
weather = call weatherTool("San Francisco")
temp = call temperatureTool(weather)
Tool calls return values that can be used in expressions:
result1 = call calculatorTool("add", 10, 20)
result2 = call calculatorTool("multiply", 5, 6)
prompt "Calculations: 10 + 20 = {result1}, 5 * 6 = {result2}"
# Variable types
name: string = "Alice"
age: number = 30
isActive: boolean = true
# Function types
function add(a: number, b: number): number {
return a + b
}
type Person = record {
name: string,
age: number,
email: string
}
person: Person = {
name: "Alice",
age: 30,
email: "alice@example.com"
}
type NumberArray = number[]
numbers: NumberArray = [1, 2, 3, 4, 5]
# Generic array type
type PersonList = Person[]
people: PersonList = [
{ name: "Alice", age: 30, email: "alice@example.com" },
{ name: "Bob", age: 25, email: "bob@example.com" }
]
Rohas supports type inference, so explicit types are optional:
# Type inferred as string
name = "Alice"
# Type inferred as number
age = 30
# Type inferred as boolean
isActive = true
short_term- Temporary memory for the current sessionlong_term- Persistent memory across sessions
# Store in memory
prompt "My favorite color is blue"
memory: "long_term"
# Retrieve from memory
prompt "What's my favorite color?"
memory: "long_term"
State is passed between flow steps:
flow myFlow {
step first {
prompt "First step"
state: { step: 1, data: "initial" }
}
step second {
prompt "Second step"
state: { step: 2, data: "processed" }
}
}
# Single-line comment
# Multi-line comments use multiple single-line comments
# This is a multi-line comment
# spanning multiple lines
- Use type annotations for better code clarity and error detection
- Use const for values that shouldn't change
- Use template literals for string interpolation
- Organize complex logic into functions
- Use flows for multi-step workflows
- Leverage parallel steps for independent operations
- Use memory to maintain context across prompts
- Use state to pass data between flow steps
Rohas provides static analysis to catch errors before runtime:
rohas analyze script.roCommon errors include:
- Undefined variables
- Type mismatches
- Invalid function calls
- Missing required parameters