Name: Rubber Duck Script
Extension: .rd
Philosophy: Simple and expressive
- Static typing with type inference using
autokeyword - Constants with
const autodeclaration (must be initialized) - Automatic memory management - no manual allocation/deallocation
- C-like syntax - familiar and easy to learn
- Performance benchmarking - built-in timing utilities
- Standard I/O support -
display()andgetin()for user interaction
Linux/macOS:
./rd.sh script.rdWindows:
./rd.bat script.rdTo build the project:
./rd.shTo run a script:
./rd.sh script.rdNote: The build scripts automatically handle build updates. You don't need to manually delete the
buildfolder before rebuilding - the script will detect changes and recompile only what's necessary.
auto name = "Rubber Duck";
auto age = 5;
auto price = 19.99;
auto is_active = true;Variables declared as const are immutable and MUST be initialized at declaration. Uninitialized constants will cause a compilation error:
const auto PI = 3.14159; // ✅ Valid - initialized with value
const auto APP_NAME = "Rubber Duck"; // ✅ Valid - initialized with string
const auto MAX_USERS = 1000; // ✅ Valid - initialized with integer
const auto UNINITIALIZED; // ❌ COMPILATION ERROR: constants must be initialized
const auto LATE_INIT; // ❌ COMPILATION ERROR: constants must be initialized
LATE_INIT = 10; // ❌ COMPILATION ERROR: cannot reassign constantsConstants can be used in expressions like regular variables, but cannot be modified:
const auto TAX_RATE = 0.07;
auto price = 100.0;
auto tax = price * TAX_RATE; // ✅ Valid - using constant in calculation
auto total = price + tax;
TAX_RATE = 0.08; // ❌ RUNTIME ERROR: cannot modify constant// Application configuration
const auto APP_NAME = "Rubber Duck Script";
const auto VERSION = "1.0.0";
const auto MAX_FILE_SIZE = 10485760; // 10 MB
const auto TIMEOUT_SECONDS = 30;
display($"Welcome to {APP_NAME} v{VERSION}");
display($"Max file size: {MAX_FILE_SIZE} bytes");
display($"Timeout: {TIMEOUT_SECONDS} seconds");// ❌ Common compilation errors with constants
const auto UNINIT; // COMPILATION ERROR: must be initialized
const auto VALUE = 10;
VALUE = 20; // RUNTIME ERROR: cannot reassign
// These will prevent the program from running:
const auto MISSING_VALUE; // Program won't compile or run
const auto EMPTY_CONST; // Program won't compile or runImportant Security Feature: The language enforces constant initialization at parse time. If you declare a constant without initialization, the parser will immediately fail with an error message like:
"Constant 'VARIABLE_NAME' must be initialized"and the program will not execute.
auto sum = 10 + 5; // Addition
auto diff = 10 - 5; // Subtraction
auto product = 10 * 5; // Multiplication
auto quotient = 10 / 5; // Divisionauto is_equal = (a == b);
auto not_equal = (a != b);
auto less_than = (a < b);
auto greater_than = (a > b);
auto less_or_equal = (a <= b);
auto greater_or_equal = (a >= b);auto and_result = (x > 5 && y < 10); // AND
auto or_result = (x == 0 || y == 0); // OR
auto not_result = !(x > 5); // NOTMethod 1: String interpolation with prefix
auto name = "Duck";
auto age = 5;
display($"Hello, my name is {name} and I am {age} years old!");
display($"Result: {10 + 20}");
display($"{name} says: 'Quack!'");Method 2: Comma-separated concatenation
display "Hello, World!";
display "Name:", name, "Age:", age;
display "Sum of ", a, " and ", b, " is: ", a + b;
display name, " is ", age, " years old";Method 3: Simple string literal
display("Simple message");auto user_input = "";
display("Enter your name:");
getin(user_input);
display ($"Hello {user_input}!");if (temperature > 30)
{
display("It's hot outside!");
}
else if (temperature > 20)
{
display("Nice weather!");
}
else
{
display("It's cold!");
}Standard for loop:
for (auto i = 0; i < 10; ++i)
{
display "Iteration:", i;
}Infinite for loop:
for (;;)
{
display("Running forever...");
if (some_condition)
{
break;
}
}Conditional for loop:
for (auto i = 0; i < 100; i++)
{
if (i == 50)
{
break; // Exit the loop
}
if (i % 2 == 0)
{
continue; // Skip even numbers
}
display "Odd number:", i;
}for (auto i = 0; i < 10; ++i)
{
if (i == 5)
{
break; // Exit loop when i equals 5
}
if (i % 2 == 0)
{
continue; // Skip to next iteration for even numbers
}
display(i); // Only displays odd numbers: 1, 3
}fun CalculateSum(auto a, auto b)
{
auto result = a + b;
return result;
}
auto total = CalculateSum(10, 20);
display "Total:", total;Measure execution time of code blocks with automatic formatting:
benchmark
{
auto sum = 0;
for (auto i = 0; i < 1000000; ++i)
{
sum = sum + i;
}
display "Sum:", sum;
}Output format:
- Nanoseconds (ns)
- Microseconds (μs)
- Milliseconds (ms)
- Seconds (s)
Example Benchmark Results:
Performance Test: Printing 1,000,000 numbers
Python Execution:
start_time = time.time()
for i in range(0, 1000000):
print(i)
end_time = time.time()
print(f"Time taken: {end_time - start_time}")Result: 348.94 seconds
Rubber Duck Script Execution:
benchmark
{
for(auto i = 0; i < 1000000; i++)
{
display(i);
}
}Result: 23.4382 seconds
Performance Improvement: 14.9x faster than Python!
Escape sequences:
display("Line 1\nLine 2"); // Newline
display("Column1\tColumn2"); // Tab
display("Quote: \"Hello\""); // Escaped quotes
display("Backslash: \\"); // Escaped backslashauto num1 = 0;
auto num2 = 0;
display("Enter first number:");
getin(num1);
display("Enter second number:");
getin(num2);
display($"Sum: {num1 + num2}");
display($"Difference: {num1 - num2}");
display($"Product: {num1 * num2}");
display($"Quotient: {num1 / num2}");for (auto i = 1; i <= 100; ++i)
{
if (i % 15 == 0)
{
display("FizzBuzz");
}
else if (i % 3 == 0)
{
display("Fizz");
}
else if (i % 5 == 0)
{
display("Buzz");
}
else
{
display(i);
}
}const auto PI = 3.141592653589793;
auto radius = 0;
display("Enter the radius of the circle:");
getin(radius);
auto area = PI * radius * radius;
auto circumference = 2 * PI * radius;
display($"Radius: {radius}");
display($"Area: {area}");
display($"Circumference: {circumference}");// This program will NOT run due to uninitialized constant
const auto APP_VERSION; // ❌ PARSING ERROR: Constant must be initialized
display("This line will never execute");- Variable declarations with
auto - Constant declarations with
const auto(must be initialized at declaration) - Strict constant enforcement (uninitialized constants prevent program execution)
- Arithmetic operators (
+,-,*,/,%) - Compound assignment operators (
+=,-=,*=,/=,%=) - Comparison operators (
==,!=,<,>,<=,>=) - Logical operators (
&&,||,!) - Increment/decrement operators (
++,--, prefix and postfix) - Control flow (
if,else if,else) - For loops (standard, infinite, conditional)
- While loops
- Loop control (
break,continue) - Functions with return values (
fun) - Input/output (
getin(),display()) - String literals with escape sequences
- String interpolation (
$"Hello {name}") - Type inspection (
typeof()) - Benchmark blocks for performance measurement
- Constant Safety: Uninitialized constants are caught at parse time
- Type Safety: Variables maintain their type after declaration
- Memory Safety: Automatic memory management prevents leaks
For detailed coding conventions and guidelines, see CODING_GUIDELINES.md.
Rubber Duck Script features automatic memory management. For implementation details, refer to MEMORY_MANAGEMENT.md
Contributions are welcome! Please follow the coding guidelines and ensure all tests pass before submitting a pull request.
Run the full test suite to verify all language features work correctly:
./run_tests.shThis runs all test files in the tests/ directory covering variables, constants, operators, control flow, functions, strings, expressions, benchmarks, nested structures, edge cases, and classic programs.

