Snakel

From Esolang
(Redirected from Snakel/Syntax)
Jump to navigation Jump to search
Official logo since 2005

Snakel is an alternative universe version of Python created in 1989 by Tolly Edd in the Gaia universe

Syntax

Every program starts with a definition of a "main" function. To define one, you can do this:

­ 1: def name[arguments]; !Used for argumented functions
­ 2: ­ ­ ­ ­ ignore !"ignore" will exit the function
­ 3: def name:none; !Used for argumentless functions
­ 4: ­ ­ ­ ­ ignore

translated into python:

def name(arguments):...
def name():...

You can also do output (with tell[]) and input (with user):

­ 1: def main:none;
­ 2: ­ ­ ­ ­ tell["anything here"]
­ 3: ­ ­ ­ ­ user !This command has no arguments at all

translated into python:

print("""anything here""")
input()

And also, the strings in Snakel are really just multi-liners:

­ 1: def main:none;
­ 2: ­ ­ ­ ­ tell["multi
­ 3: line"]

translated into python:

print("""multi
line""")

We already know that "ignore" goes to the end of the function's body.

But did you know that you can catch errors by also using test?

­ ­ 1: test:1/0 !Emit's a ArithmeticError
­ 2: ignore ArithmeticError:tell["inf"] !Ignores the error and executes the ignore statement
­ 3: end

translated into python:

try:1/0
except:print("""inf""")
exit()

The Snakel conditionals are built almost the same as the rust's case statements

­ 1: num i=0
­ 2: if i=0(tell[0]) | i=1(end) | tell[3]

translated into python:

i:int=0
if i==0:print(0)
elif i==1:exit()
else:print(3)

Errors

This is still a work in progress. It may be changed in the future.

If you make an error in the code (for example putting an undefined variable into the code) in a Snakel interpreter. Then the Terminal (or Emiter as it's called in the Gaia universe) will emit an error and will explain and show where you made a mistake

TypeError

Using a wrong type in a variable

code:

­ 1: !for example
­ 2: num a="eso"

emiter:

­ Current operation stopped
­ Error type:TypeError
­ At what line: 2
­ Explanation:
­ 2: num a="eso"
­ ­ ­ ­ ­ ­ ­ ­ ­ ­ -----
­ Wrong value type. Cannot assign num to str

Specifying an undefined type to a variable

code:

­ 1: int i=user

emiter:

­ Current operation stopped
­ Error type:TypeError
­ At what line: 1
­ Explanation:
­ 1: int i=user
­ ­ ­ ­ ---
­ Invalid type. "int" is not a Type


Removing an entry that is not on the list

code:

­ 1: l=["H","I"]
­ 2: pop(l,"!")

emiter:

­ Current operation stopped
­­ Error type:TypeError
­­ At what line: 2
­­ Explanation:
­­­ 2: pop(l,"!")
­­­ ­­ ­­ ­­ ­­ ­­ ­­ ­­ ­­ ­­ ­­---
­­ Pop non-related entry from list. "!" is not an element on list "l"

SyntaxError

Using anything that is not a tab or a space as indentation

code:

­ 1: def main:none;
­ 2: ;tell["how"]

emiter:

­ Current operation stopped
­­ Error type:SyntaxError
­­ At what line: 2
­­ Explanation:
­ 2: ;tell["how"]
­­­ ­­ ­­ ­ ­­^
­­ Invalid indentation. A tab or spaces must be used as the indentation, ";" was used instead

Use a not-defined varible

code:

­ 1: def main:none;
­ 2: ­ tell[code]

emiter:

­ Current operation stopped
­­ Error type:SyntaxError
­­ At what line: 2
­­ Explanation:
­ 2: ­ tell[code]
­­­ ­­ ­­ ­­ ­­ ­­ ­­ ­­ ­­ ­­ ­­----
­­ Invalid variable. No variable by the name of "code" was mentioned


Examples

Hello, world!

­ 1: def main:none;tell["Hello, world!\n"]

translated into python:

print("Hello, world!")

Cat program

­ 1: def main:none;tell[user]

translated into python:

print(input())

Truth-machine

­ 1: def truth[num[i]];
­ 2: ­ ­ ­ ­ if i>0;ignore | tell[0];end
­ 3: def main:none;
­ 4: ­ ­ ­ ­ truth[user]
­ 5: ­ ­ ­ ­ while 1:tell[1]

translated into python:

def truth(i:int):
    if int(i)>0:return
    else:print(0);exit()
truth(input())
while 1:print(1,end="")

A+B Problem

­ 1: def APB [num[a,b]];tell[a+b]
­ 2: def main:none;APB[7,4]

translated into python:

def APB (a:int,b:int):print(a+b)
APB(7,4)