REPL Tour

The BioLang REPL (Read-Eval-Print Loop) is an interactive environment for exploring data, testing ideas, and prototyping analyses. It features syntax highlighting, tab completion, persistent history, and built-in commands.

Starting the REPL

Launch the REPL from your terminal:

bl repl

You will see the BioLang prompt:

BioLang v0.1.0 — Type :help for commands, :quit to exit
bl>

Type any expression and press Enter to evaluate it. The result is automatically printed:

bl> 2 + 2
4

bl> "hello" |> upper()
"HELLO"

bl> dna"GATTACA" |> len()
7

REPL Commands

Commands start with a colon (:) and are not BioLang expressions. They control the REPL itself.

Command Short Description
:help :h Show available commands and usage
:quit :q Exit the REPL
:clear :c Clear the screen
:type <expr> :t Show the type of an expression without evaluating
:load <file> :l Load and execute a .bl file in the current session
:save <file> :s Save the current session's expressions to a file
:time <expr> Evaluate an expression and show elapsed time
:env List all variables and their types in the current scope
:reset Reset the session, clearing all variables and imports

Type Inspection

The :type command is invaluable for understanding what types flow through your pipe chains:

bl> :type dna"ATCG"
Dna

bl> :type [1, 2, 3] |> map(|x| x * 2.0)
List<Float>

bl> :type { "name": "sample", "reads": 1000 }
Map<String, Any>

bl> :type |x: Int| x + 1
Fn(Int) -> Int

Timing Expressions

Use :time to benchmark operations directly in the REPL:

bl> :time range(1, 1_000_000) |> map(|x| x * x) |> sum()
333333833333500000
Elapsed: 42ms

bl> :time dna"ATCGATCG" * 1000 |> gc_content()
0.5
Elapsed: 0.3ms

Session Management

Load external files to bring their functions and variables into the current session:

bl> :load utils.bl
Loaded 3 functions, 2 variables from utils.bl

bl> my_custom_function("test")
"TEST_processed"

bl> :env
  seq       : Dna
  threshold : Float = 30.0
  samples   : List<Map<String, Any>>
  my_custom_function : Fn(String) -> String

Save your current session to a file for later reuse:

bl> let data = [10, 20, 30, 40, 50]
bl> let filtered = data |> filter(|x| x > 25)
bl> :save session.bl
Saved 2 expressions to session.bl

Tab Completion

Press Tab at any time to see contextual completions. The REPL completes:

  • Built-in functionsmap, filter, reduce, print, etc.
  • Sequence functions — type dna"ATCG" |> then Tab
  • Variable names — any variable defined in the current session
  • REPL commands — type : then Tab
bl> dna"ATCG" |> [Tab]
gc_content    reverse_complement    complement    transcribe    len
translate     subseq                find_motif    kmers         kmer_count

bl> mea[Tab]
mean    mean_phred    median

Multi-line Input

The REPL automatically detects incomplete expressions. When you open a brace, bracket, or parenthesis without closing it, the prompt changes to ... to indicate continuation:

bl> let samples = [
...   { "id": "S1", "reads": 1_000_000 },
...   { "id": "S2", "reads": 2_500_000 },
...   { "id": "S3", "reads": 800_000 }
... ]

bl> fn greet(name: String) -> String {
...   "Hello, {name}!"
... }

bl> greet("BioLang")
"Hello, BioLang!"

You can also force multi-line mode by ending a line with a backslash:

bl> [1, 2, 3, 4, 5] \
...   |> map(|x| x * 10) \
...   |> filter(|x| x > 20) \
...   |> sum()
120

History

The REPL maintains a persistent history across sessions, stored in ~/.biolang/history. Navigate with:

  • Up / Down — previous and next entries
  • Ctrl+R — reverse search through history
  • Ctrl+P / Ctrl+N — same as Up/Down

History search is prefix-aware. Type the beginning of a previous command and press Up to find matching entries:

bl> dna[Up]
# Cycles through previous commands starting with "dna"
bl> dna"GATTACA" |> reverse_complement()

Working with Genomic Data

The REPL is especially useful for exploring genomic data interactively:

bl> let reads = read_fastq("sample.fastq")

bl> reads |> take(5) |> map(|r| r.id)
["read_001", "read_002", "read_003", "read_004", "read_005"]

bl> reads |> map(|r| r.length) |> mean()
151.4

bl> gc_content(reads[0].seq)
0.4172

bl> kmers(reads[0].seq, 3) |> take(5)
[dna"ATG", dna"TGC", dna"GCA", dna"CAT", dna"ATT"]

Configuration

Customize the REPL by creating a ~/.biolang/replrc.bl file. It runs automatically when the REPL starts:

# ~/.biolang/replrc.bl
# Define handy shortcuts

fn qc(path: String) {
  let reads = read_fastq(path)
  reads
    |> map(|r| mean_phred(r.quality))
    |> describe()
}

print("REPL ready.")

Keyboard Shortcuts

Shortcut Action
Tab Auto-complete
Ctrl+C Cancel current input
Ctrl+D Exit the REPL
Ctrl+L Clear the screen
Ctrl+R Reverse history search
Ctrl+A Move to beginning of line
Ctrl+E Move to end of line
Ctrl+W Delete word backward
Alt+B / Alt+F Move backward/forward by word

Next Steps

Now that you are comfortable with the REPL, check out the From Python/R guide if you are coming from an existing bioinformatics workflow.