Racist Lua
Racist Lua
Racist Lua, also known as Lambda Lua or the Function Supremacy Challenge, is a programming challenge primarily meant for the programming language Lua. The challenge involves engaging in function exclusive programming also known as "function supremacy." This idea derives itself from Lambda calculus, where everything can be computed purely from functions.
Origins
Racist Lua originated as a joke prompt for a poll asking, "which language would you rather program in?" The answer, "Racist Lua," immediately sparked intrigue with many asking what it meant. After some questioning, the basic concept was born and expanded on, where it formed to become an actual, serious programming challenge.
Rules
The Racist Lua rules, or "constitution," go loosely as follows (as it's still being discussed):
- Only functions can be used: This means no computation using any other datatypes such as tables, strings, numbers etc. Including any operations or standard functions used to mutate said values (with few, later exceptions).
- Boolean evaluations in teranary expressions and Nullish Coalescing are permitted, so long as they always return a function.
- Limits of Boolean evaluations include the operations "not," "and," "or," "==," and "~=." These must be used to evaluate permitted datatypes like functions and enumerations, including the global constant "nil."
- Enumeration is accepted but not recommended, meaning you may use other datatypes like strings to represent a function and be treated almost as such, so long as it obeys the previous rules and is never mutated beyond its original state during runtime (These are also known as "enslaved values").
- The only permitted usage of library functions with other datatypes is within IO such as printing and input. This is under the strict guidelines that output is only to display data and not mutate any runtime values, and input must find a way to convert any values recieved into functions or permitted values with very slight leeway in the manner of conversion.
- Comments are allowed, or any syntax that doesn't have any direct impact to code execution or program memory.
- These rules are based on common sense and interpretation is only as strict or loose as the people participating wish to allow.
Example Functions
A simple implementation of Church numerals in Racist Lua:
--Base Unit for Church Numerals (Zero)
base_unit = function() return base_unit end
function f(x)
--Wrap A Value In An Empty Function
return function()
return x
end
end
function suc(x)
--Get Succesion
return x == nil and base_unit or f(x)
end
function dec(x)
--Get Descendent
return (x == nil or x == base_unit) and base_unit or x()
end
function add(a, b)
--Add 2 Church Numerals
return (a == nil or a == base_unit) and b or add(dec(a),suc(b))
end
function subt(a, b)
--Subtract Church Numeral From Church Numeral
return (b == nil or b == base_unit) and a or subt(dec(a),dec(b))
end
function mult(a, b, c)
--Multiply 2 Church Numerals
local c = c or base_unit
return (a == nil or a == base_unit) and c or mult(dec(a),b, add(c, b))
end
Given previous functions, a way to print out Church Numerals:
--Null Unit for Return Functions
null_fn = function() return null_fn end
function outVal(x, fn)
--Output Church Numeral as x+1 number of dots
io.write(".")
return (x == nil or x == base_unit) and null_fn or outVal(dec(x), fn)
end