Effects & I/O
I/O as a Suffix Family
I/O in Ragul is not special-cased by the compiler. Every I/O channel is a named scope defined with -nk-hatás / -ours-effect. This makes every channel a suffix that can appear in any suffix chain — while the compiler enforces it can only be called from within another effect scope.
The Effect Scope — -hatás / -effect
Lazy evaluation means sentences only execute when their result is needed. A sentence that writes to screen has no result — so the lazy evaluator would never run it. The -hatás / -effect suffix solves this by marking a scope as eager: everything inside executes in order, top to bottom, unconditionally.
Two rules enforced by the compiler:
- Inside a
-hatás/-effectscope, all sentences execute eagerly in order - A pure scope (without
-hatás) cannot call an effectful scope — compile error E004
I/O Channels
Every channel is a built-in effect scope. The table below lists all channels with their English aliases.
| Hungarian root | English alias | Direction | Meaning |
|---|---|---|---|
képernyőre |
stdout / -print |
write | Console stdout |
bemenetről |
stdin |
read | Console stdin |
stderr |
stderr |
write | Stderr |
fájlból |
filein |
read | File read |
fájlra |
fileout |
write | File write |
hálózatból |
netin |
read | Network read (stub — v0.4.0) |
hálózatra |
netout |
write | Network write (stub — v0.4.0) |
stdout and stdin normalise to képernyőre and bemenetről at lex time — they are full aliases, not separate channels.
Console Output
-print / -képernyőre writes a value to stdout. stderr writes to stderr.
Console Input
stdin / bemenetről reads a line from the user when resolved as a source value.
File Write
-fileout / -fájlra writes a value to a file. The filename is the inline argument immediately before the channel suffix.
File paths are relative to the working directory
File paths resolve relative to where you invoke ragul run, not to the script file itself. If you run ragul run examples/en/10_file_io.ragul from the project root, files are created in the project root. Subdirectory paths work — "output/results.txt" writes into an output/ subfolder relative to your cwd (the directory must already exist).
The filename can also be a variable:
File Read
-filein / -fájlból reads the entire contents of a file and returns a string. It returns a Hiba value if the file cannot be read.
Paths are relative to the working directory where ragul run is invoked. Subdirectory paths work as expected — "myfiles/data.txt" reads from a subfolder of your cwd.
Operations can be chained directly onto the read — for example, parse a JSON file in one step:
File I/O with Error Handling
File operations can fail. -filein / -fájlból returns a Hiba value when the file does not exist or cannot be read. Attach -e / -? to propagate the error to the nearest -catch / -hibára handler.
The same pattern applies to writing — -fileout / -fájlra returns a Hiba if the file cannot be written (for example, a read-only path):
A complete read-transform-write pipeline with error handling on both ends:
Defining Custom Channels
Channels are not compiler magic — they are Ragul scopes, defined exactly like any other scope with -nk-hatás / -ours-effect. The standard library provides the built-in channels, but you can define your own:
Once defined, adatbázisba becomes a suffix usable anywhere — identically to built-in channels:
Suffix Reference
| Hungarian | English | Meaning |
|---|---|---|
-nk-hatás |
-ours-effect |
Declares an effect scope — eager, I/O permitted |
-va / -ve |
-doing |
Action — executes the operation |
-képernyőre |
-print / stdout |
Write to stdout |
bemenetről |
stdin |
Read from stdin (used as root value) |
stderr |
stderr |
Write to stderr |
-fájlból |
-filein |
Read entire file, returns Szöveg or Hiba |
-fájlra |
-fileout |
Write value to file (filename is inline arg) |
-e / -? |
-e / -? |
Propagate Hiba to nearest -catch handler |