Say
say is Goblin's built-in output action.
It displays a value as text and is commonly used for:
- debugging
- logging
- inspecting variables
- displaying results to users
If you're coming from another language, say serves a role similar to:
print()in Pythonprintln!()in Rustputsin Rubyconsole.log()in JavaScript
Basic Usage
Preferred Style
The recommended convention is to use the intrinsic prefix : when calling built-in actions:
x | "Hello World!" :say(x)
x | "Hello World!" :say(x)
Output:
Hello World!
Hello World!
Supported Call Styles
Goblin allows several equivalent ways to invoke say.
All of the following produce identical output:
x | "Hello World!" say x :say x say(x) :say(x)
x | "Hello World!" say x :say x say(x) :say(x)
Output:
Hello World!
Hello World!
Why Use :
The : prefix is called the intrinsic operator.
It indicates that an action is provided by Goblin itself rather than by user code.
Example:
:say("Hello")
:say("Hello")
Many built-in actions can be written without the prefix:
say("Hello")
say("Hello")
However, the preferred documentation style is:
:say("Hello")
:say("Hello")
because it makes it immediately obvious that the action is an intrinsic.
Printing Variables
Variables can be passed directly to say.
name | "Goblin" :say(name)
name | "Goblin" :say(name)
Output:
Goblin
Goblin
Printing Expressions
The value of an expression is printed.
x | 5 :say(x + 10)
x | 5 :say(x + 10)
Output:
15
15
Printing Collections
Arrays and other values are formatted automatically.
items | ["sword", "shield", "potion"] :say(items)
items | ["sword", "shield", "potion"] :say(items)
Example output:
["sword", "shield", "potion"]
["sword", "shield", "potion"]
Printing Objects
Objects can also be printed.
rome <> Kingdom | name: "Rome", age: 400 :say(rome)
rome <> Kingdom | name: "Rome", age: 400 :say(rome)
Example output:
Kingdom{id: b3e56711-e9ef-426e-a37e-0000816adf7b, name: Rome, age: 400}
Kingdom{id: b3e56711-e9ef-426e-a37e-0000816adf7b, name: Rome, age: 400}
Exact formatting may vary depending on the object's fields.
Not a Method
Unlike some languages, say is not called on a value.
This does not work:
x.say
x.say
or
x.say()
x.say()
Instead, pass the value to say:
:say(x)
:say(x)
No Value Returned
say exists for its side effect: displaying output.
It does not produce a useful value for further computation.
:say("Hello")
:say("Hello")
The text is displayed and execution continues.
Why This Exists
Goblin treats output as an action rather than a special language construct.
This keeps output consistent with the rest of the language:
:save(...) :load(...) :say(...)
:save(...) :load(...) :say(...)
The intrinsic prefix also makes it easy to distinguish built-in actions from user-defined actions.