// various types of comments
x = 10; # Inline comment
/* This is a
block comment */
10) and Floating-point (3.14)."Hello"), single-quoted ('Hello') text or multiline.true and false.[1, 2, 3]).map { "key" : value }).Variables are statically typed in Fahrenheit. You must specify a type (or multiple types) upon definition. Fahrenheit checks types at runtime and throws a ScriptException if an incompatible value is assigned. If you omit the type and assign a value on the first encounter, the type defaults to any.
# Mandatory typed variables
int count = 0;
String name = "Fahrenheit";
boolean isValid = true;
# Union types (allow multiple acceptable types)
String|int id = 5;
id = "five"; # Valid
# 'any' type (accepts any value)
any data = 10;
data = "hello"; # Valid
# Defaulting to 'any' by assigning on first use
x = 10; # x is of type 'any'
# Constants (immutable, must be typed)
constant double PI = 3.14159;
constant String VERSION = "0.4.0";
# PI = 3.14; # Error: Cannot assign to constant
Fahrenheit uses block scoping. Variables declared within { } are local to that block. Modifiers control where variables are stored and their visibility:
global: Stored in the global scope, accessible across script engines sharing context.local (default): Local to the current script execution.private, protected: For structure fields and methods (access control).
global String APP_NAME = "Fahrenheit App"; # Accessible everywhere
local int temp = 100; # Local to this script runner
structure Secure {
private String key = "123";
protected String secret = "abc";
function String getKey() { return this.key; }
}
Standard arithmetic (+, -, *, /, %), comparison (==, !=, >, <, >=, <=), and logical (&&, ||, !) operators are supported.
Compound Assignment: +=, -=, *=, /= (works on numbers, strings, array elements, and struct fields)
Ternary Operator: condition ? val1 : val2 (right-associative, nestable)
Bitwise Operators: &, |, ^, ~, <<, >>, >>>
( ) [ ] .! ~ - (unary)* / %+ -> >= < <= == !=&&||? : (Ternary)=Single and Double Quotes: Strings can be delimited with either double quotes ("...") or single quotes ('......'). Mixed nesting is supported (a single-quoted string can contain double quotes and vice versa).
Interpolation: Embed expressions using """ + "$" + """expression syntax inside any string.
Multiline: Use triple-double-quotes ("""...""") or triple-single-quotes ('''...'''). Preserves whitespace and newlines. Supports interpolation.
name = "World";
print("Hello ${name}!"); // Output: Hello World!
print('Hi ${name}!'); // Output: Hi World!
# Multiline string
html = """
<div>
<h1>Hello """ + "$" + """{name}</h1>
</div>
""";
Use the enumerated keyword for fixed sets of constants.
enumerated Status { PENDING, ACTIVE, INACTIVE }
global enumerated AppState { INIT, RUNNING, STOPPED }
status = Status.ACTIVE;
if (status == Status.ACTIVE) {
print("User is active");
}
if (x > 5) {
print("High");
} else {
print("Low");
}
# While
i = 0;
while (i < 5) { i = i + 1; }
# For
for (i = 0; i < 10; i = i + 1) { print(i); }
# Foreach (over arrays, strings, or maps)
foreach (item : list) { print(item); }
foreach (key : myMap) { print(key + " -> " + myMap[key]); }
Use break to exit a loop early, and continue to skip to the next iteration. Both work inside while, for, and foreach loops.
for (i = 0; i < 10; i = i + 1) {
if (i % 2 == 0) { continue; } # Skip even numbers
if (i > 7) { break; } # Stop early
print(i);
}
switch (val) {
case 1: print("One"); break;
default: print("Other");
}
try {
throw "Error";
} catch (e) {
print("Caught: " + e);
} finally {
print("Cleanup");
}