This content originally appeared on DEV Community and was authored by Hiroshi Tsubokawa
In previous posts, I’ve introduced some of the key syntax and features of Turbine, a Markdown-inspired scripting language.
This time, let’s look at one of its practical features, the out parameter, a mechanism for returning multiple values from a function, similar to how C and C++ handle it.
Why Do We Need an Out Parameter?
In Turbine, a function can only have one return value.
But sometimes, you want to return a main result and an additional status flag, for example, when you want to detect division by zero in a divide() function.
Many scripting languages, such as Python, can easily return multiple values using tuples:
def divide(a, b):
if b == 0:
return 0, False
return a / b, True
result, ok = divide(10, 2)
That’s convenient and expressive.
However, in C or C++, a function can only return a single value, so developers typically use references or pointers to return additional results:
int divide(int a, int b, bool &ok)
{
if (b == 0) {
ok = false;
return 0;
}
ok = true;
return a / b;
}
Turbine follows this C/C++ style approach, but with a much simpler, Markdown-like syntax.
Writing an Out Parameter in Turbine
In Turbine, you declare an out parameter by prefixing it with &.
# divide(a int, b int, &ok bool) int
if b == 0
ok = false
return 0
ok = true
return a / b
The function above performs integer division and sets ok to indicate success.
On the caller side, it looks like this:
# main(args vec{string}) int
- ok bool
- res = divide(10, 2, &ok)
if ok
print("result =", res)
else
print("divide by zero")
return 0
Here, &ok means the variable ok is passed by reference, and the function writes its result back to it.
Design Philosophy
Turbine’s out parameter system is not just nostalgic imitation of C —
it’s designed to clearly separate the “main result” from auxiliary information.
Take the following example:
# parse_int(s string, &ok bool) int
If Turbine used tuple-style multiple returns (like (int, bool)), the caller would need to unpack both values every time, even if they only cared about one.
Instead, Turbine encourages a clear distinction:
- Return value → the primary result
- Out parameter → state, flag, or secondary information
This makes the code both cleaner and semantically clearer.
Explicitly Ignoring Outputs with discard
Out parameters cannot simply be omitted.
If you call a function with an out parameter but never use the variable afterward, Turbine will raise an error, it assumes you forgot to handle the result.
To intentionally ignore the output, you can use the special keyword discard:
# main(args vec{string}) int
- result int = parse_int("123", &discard)
print(result)
return 0
The discard keyword lets you:
- Skip creating an unnecessary variable
- Avoid “unused output” errors
- Clearly express that the result is intentionally ignored
This is especially convenient in lightweight scripts where you don’t need every auxiliary output.
Rules and Limitations
There are a few simple rules for out parameters in Turbine:
- Only primitive types (
bool,int,float) can be used with& - Reference types such as strings, containers (
vec,map, etc.), and structs cannot be out parameters - At call time, you must pass either an existing variable or
&discard
Because reference types are already passed by reference, you can modify them directly inside functions without &.
Summary
Turbine’s out parameter design is all about clarity and intent:
- Use
&to return extra results from a function - Callers must explicitly mark out arguments with
& - Keeps the main return value semantically distinct
- Detects unused out arguments at compile time
-
discardmakes intentional ignoring explicit - Limited to primitive types for simplicity and safety
When you need to return just one extra piece of information, such as a success flag or minor result, Turbine’s out parameter is a clean and practical solution.
Learn More
Turbine is still in active development, and its syntax and semantics are evolving gradually.
You can check the progress and documentation here:
👉 GitHub (source)
👉 Project Docs
For Those Interested
If you’re into:
- Language design and compiler implementation
- Embeddable scripting languages that pair well with C/C++
- Minimal, Markdown-inspired syntax
I’d love to hear your thoughts and feedback!
I’ll continue sharing updates and implementation notes as Turbine evolves.
This content originally appeared on DEV Community and was authored by Hiroshi Tsubokawa
Hiroshi Tsubokawa | Sciencx (2025-10-23T12:26:21+00:00) The out Parameter in Turbine: A Markdown-like Scripting Language. Retrieved from https://www.scien.cx/2025/10/23/the-out-parameter-in-turbine-a-markdown-like-scripting-language/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.