We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

C flat --

From Esolang
Jump to navigation Jump to search

C flat --, or C♭--, is an esolang created by User:Coder07 that is entirely composed of functions and values (e.g. "Hello world", 12345). It has nothing to do with C Flat.

Syntax

Values are strings and numbers. There are also other value types that can be created through functions. Functions work how you'd expect, the function name followed by the arguments in parentheses, separated by commas. Parameters surrounded by parentheses are optional, and ones ending in an asterisk (*) accept multiple inputs, or a list. There is no statement separator, but rather functions next to eachother are run sequentally.

Function name Parameters Description
add, sub, mul, div a, b Adds/subtracts/multiplies/divides a and b
if condition, true, (false) Returns true (or calls it if it is a function) if condition is not 0, otherwise returns/calls else
input (prompt) Prompts the user for text input
output value Adds value to the output
key (character) Returns if key character is held, or the list of all held keys (as strings)
list items* Creates a list with items
index index, list Gets item index of list (0 being the first item)
find value, list Finds the first occurrence of value in list (0 being the first item)
setindex index, value, list Returns list with item index replaced with value (0 being the first item)
setvar var, value Sets var to value (If the variable is set to a function, it can be called like you'd expect)
getvar var Returns the value stored in var
function parameters, code Creates an anonymous function (parameters should be a list and can be accessed using getvar(), and code should be a string)
less, equal, greater a, b Returns 1 if a is less than/equal to/greater than b, otherwise returns 0
and, or a, b Returns if a and/or b are equal to 1
number, string value Coverts value to a number/string
char value Converts a number to its Unicode character. If value is a list of numbers, it returns a string with every item in value converted to its Unicode character.
charnum value If value only has one character, then it returns the number of it in Unicode. If it has multiple characters, it returns a list of each character as a number.

Additional Functions

These functions were not in the original version of the language but were added later.

Function name Parameters Description
exp, log a, b Returns ab or loga(b) respectively.
eval code Runs a string as code directly without needing to create a function first
substring string, start, (end) Returns a section of string, ranging from from start to end, inclusively, with 0 being the first character in the string. If end is not specified, then only one character is returned.
concat strings* Returns a string consisting of all the specified strings concatenated together.
split string, (separator) Returns a list made from splitting string at every separator. Empty sections are included. If separator is not specified or is empty, then splits the string at every character.
push list, value Returns list with value added to the end. If you want to push multiple values, use append instead.
append lists* Returns a list containing all the items of all the specified lists.
nop anything* Does nothing, and ignores its inputs, so it can be used for comments and such.

Graphics Functions

These functions involve graphics and windows. Anything drawn outside the bounds of a canvas is discarded.

Function name Parameters Description
window width, height, (title) Opens a window for drawing.
canvas width, height Like a window, but doesn't get drawn to the screen unless copy()ed to a window.
copy destination, source, (x, y), (width, height) Copies the contents of the source canvas to the destination canvas, optionally moving and/or stretching the source canvas.
mouse window, (button) If button is not specified, returns a list with the mouse coordinates relative to the window. Otherwise, returns 1 if the specified mouse button is down or 0 if it is not down.
linewidth pixels Sets the width of any future lines drawn.
color red, green, blue Sets the color of any future drawings. r, g, and b range from 0 to 255.
fill canvas Fills the entire canvas with the current color().
rect, ellipse canvas, x, y, width, height Draws a rectangle or ellipse onto canvas with the specified top-left corner and dimensions.
fillpoly, linepoly canvas, points* Accepts a set of points (x, y) to draw a polygon onto canvas with.
line canvas, x1, y1, x2, y2 Draws a line from (x1, y1) to (x2, y2) on canvas.
text canvas, x, y, text, (font) Draws text onto canvas, with the baseline starting at (x, y), using the specified font or the default system font if left unspecified. linewidth() is used as the font size.

Examples

Note: none of these have been tested.

Hello world

output("Hello world!")

Cat

output(input())

Truth-machine

setvar("iftrue",function(list(),"output(1)iftrue()"))
if(number(input()),getvar("iftrue"),function(list(),"output(0)"))

99 bottles of beer

setvar("beer",function(list("bottles"), "output(concat(getvar('bottles'), ' bottle', if(equal(getvar('bottles'),1),'\','s')', ' of beer on the wall,\n', getvar('bottles'), 'bottle', if(equal(getvar('bottles'),1),'\','s')', 'of beer.\nTake one down, pass it around,\n', if(equal(getvar('bottles'),1),'No',sub(getvar('bottles'),1))', 'bottle', if(equal(getvar('bottles),2),'\','s')', 'of beer on the wall.\n\n'))if(equal(getvar('bottles'),1),function(list(),'nop()'),function(list(),'beer(sub(getvar('bottles'),1))))"))
beer(99)

Interpreter

No interpreter is available yet, but I'm working on one.