exec
'exec, an esolang invented by User:None1, is similar to Python.
Type system
Unlike Python, there's only one type in exec: str
. This type is way more powerful than the one in Python in the following ways:
- Character codes: Character codes in Python strs must be within range(0x110000), but "character" codes in exec strs can be any signed integer.
- Subscript modification: Python strs don't support subscript modfication, but exec strs do. Simply modify a subscript of a str to another one-character str to modify that subscript.
- Methods: exec strs have way more methods than Python strs. It not only supports all the methods in Python strs, but also all the methods in Python lists.
Despite these differences, exec strs act just like Python strs. For example, character codes use UTF-8.
Syntax
exec syntax is just like that of Python's, except there's no control flow (e.g.: loops).
Built-in functions
Arithmetic
Since there are no integers in exec, these two built-in functions are available in exec for unary arithmetic:
- ord: Accepts a one-character string. Let n be its character code. If n is less than 0, returns an empty string, otherwise returns a string with n
1
's. - chr: Accepts a string, returns its length encoded in a one-character string.
The str operation *
is a non-commutative operation that returns n copies of its first operand, where n is the length of its second operand.
Output
There is one function for output in exec: print
. Unlike the one in Python, it accepts only one argument: the string to print.
Input
The function input
, which acts just like the one in Python, is used for input in exec.
The exec function
It is the most important function in exec. It executes its argument as exec code.
Examples
Hello, world!
print('Hello, world!')
Truth Machine
w=input() p=ord(w)[:'1'] a='exec(a)' a='print(w)\n'+a print(w) exec(a[:a*p])