QuackScript Documentation
Introduction
QuackScript is a whimsical, duck-themed programming language with dynamic execution behavior. The language features a "duck mood" system that affects how your code runs, random weather events, and playful built-in functions.
Basic Syntax
Variables
Declare variables using the VAR keyword:
VAR x = 10
VAR name = "Duck"
VAR myList = [1, 2, 3]
Data Types
- Numbers: Integers and floats (e.g., 42, 3.14)
- Strings: Text in double quotes, e.g., "Hello"
- Lists: Collections in square brackets, e.g., [1, 2, 3]
- Functions: Defined with
FUNkeyword - Eggs: Special values that hatch into functions
Comments
Use # for single-line comments:
# This is a comment
VAR x = 5
Operators
Arithmetic: +, -, *, /, ^ (power)
Comparison: ==, !=, <, >, <=, >=
Logical: AND, OR, NOT
List Operations:
list + item- Append item to listlist - index- Remove item at indexlist * otherList- Concatenate listslist / index- Get item at index
Control Flow
If Statements
Single-line:
IF x > 10 THEN PRINT("Big") ELSE PRINT("Small")
Multi-line:
IF x > 10 THEN
PRINT("Big number")
VAR y = x * 2
END
Loops
For Loop:
FOR i = 0 TO 10 THEN PRINT(i)
While Loop:
VAR x = 0
WHILE x < 10 THEN VAR x = x + 1
Loop Control:
CONTINUE- Skip to next iterationBREAK- Exit loop
Functions
Function Definition
Single-line (arrow syntax):
FUN add(a, b) -> a + b
Multi-line:
FUN greet(name)
VAR message = "Hello, " + name
PRINT(message)
RETURN message
END
Built-in Functions
I/O Functions
PRINT(value)- Print valuePRINT_RET(value)- Return value as stringINPUT()- Read string inputINPUT_INT()- Read integer inputCLEAR()/CLS()- Clear screen
Type Checking
IS_NUM(value)- Check if numberIS_STR(value)- Check if stringIS_LIST(value)- Check if listIS_FUN(value)- Check if function
List Functions
APPEND(list, value)- Add item to listPOP(list, index)- Remove and return itemEXTEND(listA, listB)- Add all items from listB to listALEN(list)- Get list length
Duck-Themed Functions
QUACK()- Animated duck walks across screen and quacksFLAP()- Print flapping messageMOOD()- Get current duck mood and weatherEGG(func, time)- Create egg that hatches aftertimesecondsHATCH(egg)- Hatch egg to get function inside
Constants
NULL- Null value (0)TRUE- Boolean true (1)FALSE- Boolean false (0)MATH_PI- Pi constant (3.14159...)
Examples
Factorial Function
FUN factorial(n)
IF n <= 1 THEN
RETURN 1
ELSE
RETURN n * factorial(n - 1)
END
END
PRINT(factorial(5))
List Processing
VAR numbers = [1, 2, 3, 4, 5]
VAR sum = 0
FOR i = 0 TO LEN(numbers) THEN
VAR sum = sum + (numbers / i)
END
PRINT(sum)