-
Notifications
You must be signed in to change notification settings - Fork 1
Cheat Sheet
TvoozMagnificent edited this page Aug 25, 2022
·
5 revisions
Syntax (separated with newlines) | What it does |
---|---|
Comments | |
comment [comment] |
Coment |
Any unrecognized line | Comment with warning |
Setting Variables | |
set [varname=last] to [varvalue=last] |
Set Var |
Available Values | |
^-?[0-9]+$ |
Int Val |
^-?[0-9]*\.[0-9]*$ |
Float Val |
^-?[0-9]+e[0-9]+$ |
Sci Nota Int Val |
^-?[0-9]*\.*[0-9]*E-?[0-9]*\.*[0-9]*$ |
Sci Nota Float Val |
^".*"?$ |
Str Val |
^\'.\'?$ |
Char Val |
[] |
Emp List Val |
{} |
Emp Set Val |
<> |
Emp Stack Val, equivalent to list |
I/O | |
in [varname=last] |
In with query |
out [varname=last] |
Out with newline |
line [varname=last] |
Out without newline |
Control Flow | |
skip [varname=last] |
Skip lines |
back [varname=last] |
Go back lines |
goto [varname=last] |
Go to line (1-index) |
exit |
Exit. What did you expect? |
Calculations | |
calc function arguments (usually default to last) |
Calculate and store result to variable last
|
Check out the References |
def implied_type_conversion(value, to_type, implied=True):
from_type = type_(value)
if type(to_type) == dict: to_type = to_type[from_type]
if from_type == to_type: return value
if implied: warn(f'IMPL TYPE CONV AT LINE {current_line+1}')
if from_type == 'int' and to_type == 'float': return float(value)
if from_type == 'float' and to_type == 'int': return int(value//1)
if from_type == 'string' and to_type == 'character': return value[0]
if from_type == 'array' and to_type == 'set': return set(value)
if from_type == 'set' and to_type == 'array': return sorted(list(value))
if from_type == 'set' and to_type == 'stack':
stack = list(value)
random.shuffle(stack)
return stack
if from_type == 'int' and to_type == 'bool': return value!=0
if from_type == 'float' and to_type == 'bool': return value>0
if from_type == 'bool' and to_type == 'int': return int(value)
if from_type == 'bool' and to_type == 'float': return float(int(value))
if from_type == 'string' and to_type == 'array': return list(value)
if from_type == 'string' and to_type == 'set': return set(value)
if from_type == 'string' and to_type == 'stack': return list(value)
if to_type == 'string': return string(value)
if from_type == 'array' and to_type == 'character': return '['
if from_type == 'set' and to_type == 'character': return '{'
if from_type == 'float' and to_type == 'character':
if value > 0: return '+'
if value < 0: return '-'
return '0'
if from_type == 'int' and to_type == 'character':
if value > 0: return '+'
if value < 0: return '-'
return '0'
if from_type == 'bool' and to_type == 'character':
if value: return 'y'
return 'n'
if from_type == 'array' and to_type == 'bool': return value==[]
if from_type == 'set' and to_type == 'bool': return value==set()
if from_type == 'stack' and to_type == 'bool': return value==[]
if from_type == 'bool' and to_type == 'array': return []
if from_type == 'bool' and to_type == 'set': return set()
if from_type == 'bool' and to_type == 'stack': return []
if from_type == 'string' and to_type == 'bool': return value==''
if from_type == 'string' and to_type == 'int': return len(value)
if from_type == 'string' and to_type == 'float': return float(len(value))
if from_type == 'int' and to_type == 'array': return [*range(1,value+1)]
if from_type == 'int' and to_type == 'set': return set(range(1,value+1))
if from_type == 'int' and to_type == 'stack': return [*range(1,value+1)]
if from_type == 'float' and to_type == 'array': return [*range(1,(value//1)+1)]
if from_type == 'float' and to_type == 'set': return set(range(1,(value//1)+1))
if from_type == 'float' and to_type == 'stack': return [*range(1,(value//1)+1)]
if from_type == 'array' and to_type == 'int': return len(value)
if from_type == 'set' and to_type == 'int': return len(value)
if from_type == 'array' and to_type == 'float': return float(len(value))
if from_type == 'set' and to_type == 'float': return float(len(value))
warn(f'UNEXP ERR AT LINE {current_line+1}')
def string(value):
value_type = type_(value)
if value_type == 'int': return str(value)
if value_type == 'float': return str(value)
if value_type == 'string': return "'"+value if len(value)==1 else '"'+value+'"'
if value_type == 'bool':
if value: return 'y'
return 'n'
if value_type == 'list': return '['+','.join(string(i) for i in value)+']'
if value_type == 'set': return '{'+','.join(string(i) for i in value)+'}'
warn(f'{value} STR NOT RECOG AT LINE {current_line+1}'); return '0'
def less(a, b):
if type_(a) == 'int': return a < implied_type_conversion(b, 'int')
if type_(a) == 'float': return a < implied_type_conversion(b, 'float')
if type_(a) == 'string': return a < implied_type_conversion(b, 'string')
if type_(a) == 'bool': return a < implied_type_conversion(b, 'bool')
if type_(a) == 'array':
b = implied_type_conversion(b, 'array')
for i in range(min(len(a), len(b))):
if less(a[i], b[i]): return True
if less(b[i], a[i]): return False
return len(a) < len(b)
if type_(a) == 'set':
b = implied_type_conversion(b, 'set')
if len(a) >= len(b): return False
for i in a:
if i not in b: return False
return True
def greater(a, b): return less(b, a)
def equal(a, b):
if type_(a) == 'int': return a == implied_type_conversion(b, 'int')
if type_(a) == 'float': return a == implied_type_conversion(b, 'float')
if type_(a) == 'string': return a == implied_type_conversion(b, 'string')
if type_(a) == 'bool': return a == implied_type_conversion(b, 'bool')
if type_(a) == 'array':
b = implied_type_conversion(b, 'array')
return a==b
if type_(a) == 'set':
b = implied_type_conversion(b, 'set')
return implied_type_conversion(a, 'array', implied=False) == \
implied_type_conversion(b, 'array', implied=False)
elif instruction == 'calc':
function, *arguments = parameters.split(' ')
arguments = [*arguments]
if False: pass
elif function == 'addition':
if all([type_(argument,1)=='int' for argument in arguments]):
sum = 0
for argument in arguments:
if argument not in variables:
warn(f'UNDEF VAR {argument} IN LINE {current_line+1}')
variables[argument] = 0
sum += implied_type_conversion(variables[argument], 'int')
variables['last'] = sum
else:
sum = 0.0
for argument in arguments:
if argument not in variables:
warn(f'UNDEF VAR {argument} IN LINE {current_line+1}')
variables[argument] = 0
sum += implied_type_conversion(variables[argument], 'float')
variables['last'] = sum
elif function == 'subtraction':
if all([type_(argument,1)=='int' for argument in arguments]):
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
sum = implied_type_conversion(variables[arguments[0]], 'int')
for argument in arguments[1:]:
if argument not in variables:
warn(f'UNDEF VAR {argument} IN LINE {current_line+1}')
variables[argument] = 0
sum -= implied_type_conversion(variables[argument], 'int')
variables['last'] = sum
else:
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
sum = implied_type_conversion(variables[arguments[0]], 'float')
for argument in arguments[1:]:
if argument not in variables:
warn(f'UNDEF VAR {argument} IN LINE {current_line+1}')
variables[argument] = 0
sum -= implied_type_conversion(variables[argument], 'float')
variables['last'] = sum
elif function == 'multiplication':
if all([type_(argument,1)=='int' for argument in arguments]):
sum = 1
for argument in arguments:
if argument not in variables:
warn(f'UNDEF VAR {argument} IN LINE {current_line+1}')
variables[argument] = 0
sum *= implied_type_conversion(variables[argument], 'int')
variables['last'] = sum
else:
sum = 1.0
for argument in arguments:
if argument not in variables:
warn(f'UNDEF VAR {argument} IN LINE {current_line+1}')
variables[argument] = 0
sum *= implied_type_conversion(variables[argument], 'float')
variables['last'] = sum
elif function == 'division':
if any([argument not in variables or
variables[argument]==0 for argument in arguments[1:]]):
warn(f'DIV BY ZERO IN LINE {current_line+1}')
variables['last'] = 0
elif all([type_(argument,1)=='int' for argument in arguments]):
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
sum = implied_type_conversion(variables[arguments[0]], 'int')
for argument in arguments[1:]:
if argument not in variables:
warn(f'UNDEF VAR {argument} IN LINE {current_line+1}')
variables[argument] = 0
sum /= implied_type_conversion(variables[argument], 'int')
variables['last'] = sum
else:
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
sum = implied_type_conversion(variables[arguments[0]], 'float')
for argument in arguments[1:]:
if argument not in variables:
warn(f'UNDEF VAR {argument} IN LINE {current_line+1}')
variables[argument] = 0
sum /= implied_type_conversion(variables[argument], 'float')
variables['last'] = sum
elif function == 'modulo':
if any([argument in variables or
variables[argument]==0 for argument in arguments]):
warn(f'DIV BY ZERO IN LINE {current_line+1}')
variables['last'] = 0
elif all([type_(argument,1)=='int' for argument in arguments]):
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
sum = implied_type_conversion(variables[arguments[0]], 'int')
for argument in arguments[1:]:
if argument not in variables:
warn(f'UNDEF VAR {argument} IN LINE {current_line+1}')
variables[argument] = 0
sum %= implied_type_conversion(variables[argument], 'int')
variables['last'] = sum
else:
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
sum = implied_type_conversion(variables[arguments[0]], 'float')
for argument in arguments[1:]:
if argument not in variables:
warn(f'UNDEF VAR {argument} IN LINE {current_line+1}')
variables[argument] = 0
sum %= implied_type_conversion(variables[argument], 'float')
variables['last'] = sum
elif function == 'power':
if all([type_(argument,1)=='int' for argument in arguments]):
if arguments[-1] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[-1]] = 0
sum = implied_type_conversion(variables[arguments[-1]], 'int')
for argument in arguments[-1:0:-1]:
if argument not in variables:
warn(f'UNDEF VAR {argument} IN LINE {current_line+1}')
variables[argument] = 0
if sum==implied_type_conversion(variables[argument], 'int')==0:
warn(f'ZERO POW ZERO IN LINE {current_line+1}')
sum=1
continue
try: sum = implied_type_conversion(variables[argument], 'int') ** sum
except ZeroDivisionError:
warn(f'DIV BY ZERO IN LINE {current_line+1}')
sum = 0
variables['last'] = sum
else:
if arguments[-1] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[-1]] = 0
sum = implied_type_conversion(variables[arguments[-1]], 'float')
for argument in arguments[:-1]:
if argument not in variables:
warn(f'UNDEF VAR {argument} IN LINE {current_line+1}')
variables[argument] = 0
if sum==implied_type_conversion(variables[argument], 'float')==0:
warn(f'ZERO POW ZERO IN LINE {current_line+1}')
variables['last'] = 1
try: sum = implied_type_conversion(variables[argument], 'float') ** sum
except ZeroDivisionError:
warn(f'DIV BY ZERO IN LINE {current_line+1}')
sum = 0
variables['last'] = sum
elif function == 'less':
true = True
for i in range(len(arguments)-1):
if arguments[i] not in variables:
warn(f'UNDEF VAR {arguments[i]} IN LINE {current_line+1}')
variables[arguments[i]] = 0
if arguments[i+1] not in variables:
warn(f'UNDEF VAR {arguments[i+1]} IN LINE {current_line+1}')
variables[arguments[i+1]] = 0
true = true and less(variables[arguments[i]], variables[arguments[i+1]])
variables['last'] = true
elif function == 'greater':
true = True
for i in range(len(arguments)-1):
if arguments[i] not in variables:
warn(f'UNDEF VAR {arguments[i]} IN LINE {current_line+1}')
variables[arguments[i]] = 0
if arguments[i+1] not in variables:
warn(f'UNDEF VAR {arguments[i+1]} IN LINE {current_line+1}')
variables[arguments[i+1]] = 0
true = true and greater(variables[arguments[i]], variables[arguments[i+1]])
variables['last'] = true
elif function == 'equal':
true = True
for i in range(len(arguments)-1):
if arguments[i] not in variables:
warn(f'UNDEF VAR {arguments[i]} IN LINE {current_line+1}')
variables[arguments[i]] = 0
if arguments[i+1] not in variables:
warn(f'UNDEF VAR {arguments[i+1]} IN LINE {current_line+1}')
variables[arguments[i+1]] = 0
true = true and equal(variables[arguments[i]], variables[arguments[i+1]])
variables['last'] = true
elif function == 'pop':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
try: variables['last'] = implied_type_conversion(variables[arguments[0]],
'array')[1:]
except IndexError:
warn(f'POP FROM EMPT ARR IN LINE {current_line+1}')
variables['last'] = 0
elif function == 'reverse':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
variables['last'] = implied_type_conversion(variables[arguments[0]],
'array')[::-1]
elif function == 'index':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
if arguments[1] not in variables:
warn(f'UNDEF VAR {arguments[1]} IN LINE {current_line+1}')
variables[arguments[1]] = 0
try: variables['last'] = implied_type_conversion(variables[arguments[0]],
'array')[implied_type_conversion(
variables[arguments[1]],
'int')]
except IndexError:
warn(f'INDEX OUT OF RANGE IN LINE {current_line+1}')
variables['last'] = 0
elif function == 'push':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
if arguments[1] not in variables:
warn(f'UNDEF VAR {arguments[1]} IN LINE {current_line+1}')
variables[arguments[1]] = 0
variables['last'] = implied_type_conversion(variables[arguments[0]],
'array') + [variables[arguments[1]]]
elif function == 'join':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
if arguments[1] not in variables:
warn(f'UNDEF VAR {arguments[1]} IN LINE {current_line+1}')
variables[arguments[1]] = 0
variables['last'] = \
implied_type_conversion(variables[arguments[1]],
'string').join([implied_type_conversion(i,
'string') for i in implied_type_conversion(
variables[arguments[0]], 'array')])
elif function == 'split':
arguments += ['last']*5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
if arguments[1] not in variables:
warn(f'UNDEF VAR {arguments[1]} IN LINE {current_line+1}')
variables[arguments[1]] = 0
variables['last'] = implied_type_conversion(variables[arguments[0]],
'string').split(implied_type_conversion(variables[arguments[1]],
'string'))
elif function == 'range':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
if arguments[1] not in variables:
warn(f'UNDEF VAR {arguments[1]} IN LINE {current_line+1}')
variables[arguments[1]] = 0
if arguments[2] not in variables:
warn(f'UNDEF VAR {arguments[2]} IN LINE {current_line+1}')
variables[arguments[2]] = 0
range_ = []
_1, _2, _3 = implied_type_conversion(variables[arguments[0]],
'float'), \
implied_type_conversion(variables[arguments[1]],
'float'), \
implied_type_conversion(variables[arguments[2]],
'float')
while True:
if _1 > _3:
break
range_.append(_1)
_1 += _2
variables['last'] = range_
elif function == 'type':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
if arguments[1] not in variables:
warn(f'UNDEF VAR {arguments[1]} IN LINE {current_line+1}')
variables[arguments[1]] = 0
variables['last'] = implied_type_conversion(variables[arguments[0]],
type_(variables[arguments[1]]), implied=False)
elif function == 'verbatimtype':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
if arguments[1] not in variables:
warn(f'UNDEF VAR {arguments[1]} IN LINE {current_line+1}')
variables[arguments[1]] = 0
variables['last'] = implied_type_conversion(variables[arguments[0]],
variables[arguments[1]], implied=False)
elif function == 'int':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
variables['last'] = int(implied_type_conversion(
variables[arguments[0]],
'string'))
elif function == 'float':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
variables['last'] = float(implied_type_conversion(
variables[arguments[0]],
'string'))
# math functions
elif function == 'sine':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
variables['last'] = math.sin(implied_type_conversion(
variables[arguments[0]],
'float'))
elif function == 'cosine':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
variables['last'] = math.cos(implied_type_conversion(
variables[arguments[0]],
'float'))
elif function == 'tangent':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
variables['last'] = math.tan(implied_type_conversion(
variables[arguments[0]],
'float'))
elif function == 'arcsine':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
variables['last'] = math.asin(implied_type_conversion(
variables[arguments[0]],
'float'))
elif function == 'arccosine':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
variables['last'] = math.acos(implied_type_conversion(
variables[arguments[0]],
'float'))
elif function == 'arctangent':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
variables['last'] = math.atan(implied_type_conversion(
variables[arguments[0]],
'float'))
elif function == 'phi': variables['last'] = (5**0.5+1)/2
elif function == 'pi': variables['last'] = math.pi
elif function == 'e': variables['last'] = math.e
elif function == 'factorial':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
variables['last'] = math.factorial(implied_type_conversion(
variables[arguments[0]],
'int'))
elif function == 'log':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
if arguments[1] not in variables:
warn(f'UNDEF VAR {arguments[1]} IN LINE {current_line+1}')
variables[arguments[1]] = 0
variables['last'] = math.log(implied_type_conversion(
variables[arguments[0]],
'float'), implied_type_conversion(variables[arguments[1]],
'float'))
# set functions
elif function == 'union':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
if arguments[1] not in variables:
warn(f'UNDEF VAR {arguments[1]} IN LINE {current_line+1}')
variables[arguments[1]] = 0
variables['last'] = set(implied_type_conversion(
variables[arguments[0]],
'list')) | set(implied_type_conversion(
variables[arguments[1]],
'list'))
elif function == 'intersection':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
if arguments[1] not in variables:
warn(f'UNDEF VAR {arguments[1]} IN LINE {current_line+1}')
variables[arguments[1]] = 0
variables['last'] = set(implied_type_conversion(
variables[arguments[0]],
'list')) & set(implied_type_conversion(
variables[arguments[1]],
'list'))
elif function == 'difference':
arguments += ['last'] * 5
if arguments[0] not in variables:
warn(f'UNDEF VAR {arguments[0]} IN LINE {current_line+1}')
variables[arguments[0]] = 0
if arguments[1] not in variables:
warn(f'UNDEF VAR {arguments[1]} IN LINE {current_line+1}')
variables[arguments[1]] = 0
variables['last'] = set(implied_type_conversion(
variables[arguments[0]],
'list')) - set(implied_type_conversion(
variables[arguments[1]],
'list'))
Yo, who needs a custom sidebar?
Not me!