Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Latest commit

 

History

History
571 lines (432 loc) · 8.84 KB

File metadata and controls

571 lines (432 loc) · 8.84 KB

Rohas Language Guide

Complete reference for the Rohas programming language.

Table of Contents

  1. Variables
  2. Data Types
  3. Operators
  4. Template Literals
  5. Functions
  6. Control Flow
  7. Prompts
  8. Flows
  9. Tool Calls
  10. Type System
  11. Memory & State

Variables

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"

Data Types

Primitives

  • string - Text data
  • number - Numeric data (integers and floats)
  • boolean - true or false
  • null - Null value

Collections

  • array - Ordered lists: [1, 2, 3]
  • record - Key-value pairs: { name: "Alice", age: 30 }

Examples

# 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" }
    ]
}

Operators

Arithmetic

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

Comparison

a = 10
b = 20

a == b  # false
a != b  # true
a < b   # true
a > b   # false
a <= b  # true
a >= b  # false

Logical

a = true
b = false

a && b  # false (AND)
a || b  # true  (OR)
!a      # false (NOT)

String Concatenation

firstName = "Alice"
lastName = "Smith"
fullName = firstName + " " + lastName  # "Alice Smith"

Template Literals

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}"

Functions

Synchronous Functions

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

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")

Function Parameters

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 + "!"
}

Control Flow

If/Else

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"
}

Loops

For Loop

# 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
    }
}

While Loop

count = 0
while count < 10 {
    print count
    count = count + 1
}

Prompts

Prompts are the core feature for interacting with LLMs:

Basic Prompt

prompt "Hello, how are you?"

Prompt with Options

prompt "Explain quantum computing"
  model: "gpt-4"
  temperature: 0.7
  maxTokens: 500
  stream: true

Prompt with Variables

topic = "artificial intelligence"
prompt "Explain " + topic + " in simple terms"
  model: "gpt-4"
  temperature: 0.5

Prompt with Template Literals

name = "Alice"
age = 30
prompt "{name} is {age} years old. Write a birthday message."
  model: "gpt-4"

Prompt with Tools

prompt "What's the weather in San Francisco?"
  tools: [
    {
      name: "weatherTool",
      description: "Get weather for a city",
      parameters: {
        city: "String"
      }
    }
  ]
  model: "gpt-4"

Prompt with Memory

prompt "Remember my name is Alice"
  memory: "long_term"

prompt "What's my name?"
  memory: "long_term"

Prompt with State

prompt "Process this order"
  state: {
    orderId: "12345",
    customerId: "67890",
    priority: "high"
  }

Flows

Flows enable multi-step workflows. See FLOWS.md for detailed documentation.

Basic Flow

flow myFlow {
    step first {
        prompt "First step"
    }

    step second {
        prompt "Second step"
    }
}

Flow with State

flow processOrder {
    step validate {
        prompt "Validate order"
          state: { orderId: "12345" }
    }

    step process {
        prompt "Process order"
          state: { orderId: "12345", status: "processing" }
    }
}

Parallel Steps

flow parallelFlow {
    parallel step task1 {
        prompt "Task 1"
    }

    parallel step task2 {
        prompt "Task 2"
    }

    step combine {
        prompt "Combine results"
    }
}

Tool Calls

Calling Tools

# Call a tool
result = call calculatorTool("add", 10, 20)

# Multiple calls
weather = call weatherTool("San Francisco")
temp = call temperatureTool(weather)

Tool Results

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}"

Type System

Type Annotations

# Variable types
name: string = "Alice"
age: number = 30
isActive: boolean = true

# Function types
function add(a: number, b: number): number {
    return a + b
}

Record Types

type Person = record {
    name: string,
    age: number,
    email: string
}

person: Person = {
    name: "Alice",
    age: 30,
    email: "alice@example.com"
}

Array Types

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" }
]

Type Inference

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

Memory & State

Memory Types

  • short_term - Temporary memory for the current session
  • long_term - Persistent memory across sessions

Using Memory

# 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 Management

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" }
    }
}

Comments

# Single-line comment

# Multi-line comments use multiple single-line comments
# This is a multi-line comment
# spanning multiple lines

Best Practices

  1. Use type annotations for better code clarity and error detection
  2. Use const for values that shouldn't change
  3. Use template literals for string interpolation
  4. Organize complex logic into functions
  5. Use flows for multi-step workflows
  6. Leverage parallel steps for independent operations
  7. Use memory to maintain context across prompts
  8. Use state to pass data between flow steps

Error Handling

Rohas provides static analysis to catch errors before runtime:

rohas analyze script.ro

Common errors include:

  • Undefined variables
  • Type mismatches
  • Invalid function calls
  • Missing required parameters