RedCode is a Python-based programming language where all commands start with "red" and require semicolons after each statement.
python redcode.py demo.red- All files must have
.redextension - Every statement must end with a semicolon
; - All functions start with
red - Comments start with
#
RedCode can import Python modules and automatically creates "red"-prefixed wrappers:
# HTTP Requests
redexternal requests;
response = redget("https://httpbin.org/json");
redprint("Status:", response["status_code"]);
redprint("Data:", response["text"]);
# JSON processing
redexternal json;
data = redloads('{"name": "RedCode", "version": 1.0}');
redprint("Name:", data["name"]);
json_string = reddumps(data);
# Time functions
redexternal time;
redprint("Waiting 2 seconds...");
redsleep(2);
redprint("Current time:", redtime());
# Random numbers
redexternal random;
number = redrandint(1, 100);
choices = redlist("apple", "banana", "cherry");
choice = redchoice(choices);
redprint("Random choice:", choice);
- requests:
redget(),redpost(),redput(),reddelete(),redpatch() - json:
redloads(),reddumps(),redload(),reddump() - time:
redsleep(),redtime(),redstrftime(),redstrptime() - random:
redrandint(),redchoice(),redshuffle(),redrandom() - datetime:
rednow(),redtoday(),redstrftime() - base64:
redb64encode(),redb64decode() - hashlib:
redmd5(),redsha1(),redsha256()
redprint(...)- Print to consoleredinput(prompt)- Get user input
redtype(obj)- Get object typeredint(value)- Convert to integerredstr(value)- Convert to stringredfloat(value)- Convert to floatredlen(obj)- Get object length
redabs(x)- Absolute valueredmax(...)- Maximum valueredmin(...)- Minimum valueredsum(iterable)- Sum of valuesredround(number, digits)- Round numberredpow(base, exp)- Power functionredsqrt(x)- Square root
redupper(s)- Convert to uppercaseredlower(s)- Convert to lowercaseredstrip(s)- Remove whitespaceredsplit(s, delimiter)- Split stringredjoin(delimiter, iterable)- Join stringsredreplace(s, old, new)- Replace substring
redlist(...)- Create listredappendlist(lst, item)- Append itemredpop(lst, index)- Remove itemredsort(lst, reverse)- Sort listredsorted(lst, reverse)- Get sorted copy
redread(filename)- Read fileredwrite(filename, content)- Write fileredappend(filename, content)- Append to fileredexists(path)- Check if existsredlistdir(path)- List directory
# Define variables
name = "RedCode";
version = 1.0;
# Output
redprint("Welcome to", name, version);
# Create list
numbers = redlist(5, 2, 8, 1, 9);
sorted_nums = redsorted(numbers);
redprint("Sorted:", sorted_nums);
# API Request
redexternal requests;
redexternal json;
response = redget("https://jsonplaceholder.typicode.com/posts/1");
redprint("Status:", response["status_code"]);
if response["status_code"] == 200:
data = redloads(response["text"]);
redprint("Title:", data["title"]);
For better syntax highlighting in Kiro:
- Open a
.redfile - Click "Plain Text" in the bottom right
- Select "Python" for similar highlighting
Or use the build script:
python build-syntax.pyRun the demo:
python redcode.py demo.redThe demo.red file showcases all RedCode features including external modules with automatic red-wrappers.