REPL in GoloScript

Introduction

The REPL (Read-Eval-Print Loop) is an interactive shell that lets you execute GoloScript expressions and statements one at a time. It’s ideal for quick experiments, exploring the language, and testing code snippets without creating a file.

Getting Started

Launching the REPL

To start the REPL, simply run golo without any arguments:

./golo

You’ll see the welcome message with the current version:

Starting Golo REPL...
Golo REPL v0.0.2 | dev.20260129
Type 'exit' to quit

golo>

Launching with Debug Mode

You can enable the interactive debugger in the REPL:

./golo --debug
Starting Golo REPL...
Debug mode enabled
Golo REPL v0.0.2 | dev.20260129
Type 'exit' to quit

golo>

Basic Interaction

Evaluating Expressions

Type any GoloScript expression at the golo> prompt. The result is automatically displayed:

golo> 1 + 2
3
golo> "Hello" + " " + "World"
Hello World
golo> [1, 2, 3]: size()
3

Declaring Variables

Variables persist across the session. Use let for immutable variables and var for mutable ones:

golo> let name = "Alice"
Alice
golo> let age = 30
30
golo> println(name + " is " + age + " years old")
Alice is 30 years old

Defining Functions

You can define and call functions:

golo> function greet = |name| { return "Hello, " + name + "!" }
golo> greet("Bob")
Hello, Bob!

Working with Collections

golo> let numbers = [1, 2, 3, 4, 5]
[1, 2, 3, 4, 5]
golo> numbers: size()
5
golo> numbers: contains(3)
true
golo> let unique = set[1, 2, 3, 2, 1]
[1, 2, 3]

Importing Modules

The REPL supports importing modules from your current working directory:

golo> import mymodule
golo> mymodule.myFunction()

Module resolution uses the directory from which you launched the REPL.

Exiting the REPL

To exit, type exit or quit:

golo> exit
Goodbye!

You can also press Ctrl+D (EOF) to exit.

State Persistence

The REPL maintains a single environment throughout the session. This means:

golo> let x = 10
10
golo> let y = 20
20
golo> x + y
30

Error Handling

Parser Errors

If you type invalid syntax, the REPL displays the parser error and lets you continue:

golo> let = 42
Parser errors:
	expected next token to be IDENT, got ASSIGN instead
golo>

Runtime Errors

Runtime errors are also displayed without crashing the REPL:

golo> let x = 1 / 0
Error: division by zero
golo>

Limitations

Complete Example Session

$ ./golo
Starting Golo REPL...
Golo REPL v0.0.2 | dev.20260129
Type 'exit' to quit

golo> let name = "GoloScript"
GoloScript
golo> let version = 2
2
golo> println(name + " v" + version)
GoloScript v2
golo> function factorial = |n| { if n <= 1 { return 1 } else { return n * factorial(n - 1) } }
golo> factorial(5)
120
golo> let numbers = [1, 2, 3, 4, 5]
[1, 2, 3, 4, 5]
golo> let doubled = list[x * 2 foreach x in numbers]
[2, 4, 6, 8, 10]
golo> let unique = set[1, 1, 2, 2, 3, 3]
[1, 2, 3]
golo> exit
Goodbye!

Quick Reference

Action Command
Launch REPL ./golo
Launch with debug ./golo --debug
Exit exit or quit
Declare immutable variable let x = value
Declare mutable variable var x = value
Define function function name = |args| { body }
Import module import modulename

© 2026 GoloScript Project | Built with Gu10berg

Subscribe: 📡 RSS | ⚛️ Atom