Laktano
Laktano is an alternative version of Python in PsiLine universe, which is designed and developed by Mike Traussicha.
In OTL universe, it is designed by PSTF.
Overview
Laktano is Turing-complete, High-level and easy language, it supports on a lot of operating systems. Currently, popular OS's in PsiLine are Fraug, Verfan, Windowzie, Brandig, SL-droid.
Basic Syntax
Comment
In Laktano, comment starts with flipped apostrophe.
` This is single line comment. `` This is a comment block. ``
Procedural framework
Procedural framework in Laktano is nothing, and the main function is <main>.
I/O
In Laktano, I/O can be done like this:
Output
print(*args, filename = 'CON', end = '\n')
This output function accepts an unlimited number of values, with filename as the output medium and end as the terminator. By default, filename is directed to standard output and ends with a line break.
Input
In Laktano, there are two types of input, one is evaluation input and the other is normal input.
Eval-input
Evaluation input uses this:
input(__prompt)
It returns the value of the entered expression. If the entered expression is incorrect, it will simply return an error. This function was deprecated after Laktano 2.5.
Std-inpnut
Normal input uses this:
read(__prompt)
It returns a string no matter what is entered. Of the two input functions, __prompt is used to prompt the user for input. The value of the __prompt is output before the user inputs. This function was merged with input() after Laktano 2.5.
Data structure
Identifier
Laktano's identifier works like Python in OTL universe(the universe which we live in). That is, every identifier valid in Python may also valid in Laktano.
Variable
To define a variable, you need to specify its type or value, or both. You can also omit them all, but var mustn't be omitted. when you omit type and value, it means create a NULL variable.
var (variable_type) variable_name (= variable_value)
Leave variable_value blank means to delete it.
Type
Currently, we have these types:
- Numbers, such as 3, 7, 3.14, -2, 114514, 1e20, 3.683E-34, 3.130582375184619046479671967486, etc. Initial value is 0 for int, 0/1 for frac, and 0.0 for float.
- Strings, such as 'Hello' (or "Hello"). Strings can be enclosed in double quotes or single quotes, just like work in Python. Initial value is "".
- Booleans. It can only be True, or False. Initial value is False.
- Arrays. This is the most important data type in StormLang, it can express a list or a dictionary, such as [1, 2, 3], or [key = value]. Initial value is [].
- Tuples. It is just a "unchangable array", such as (5, 2), (4, 8, 3, 8, 9), but (1, ) instead of (1). Initial value is (,).
- Functions. They're 1st-class citizens, which can be passed and returned as arguments.
- Empty types. They has only a value, None. They converts to 0, but they can used to be true.
- User-defined types. They're defined by "data" command.
- Undefined behaviour. This often occurs when you trying to do something incorrect, such as 5/0.
- Documents. They have same type of string, but they quoted by three double-quotes or single-quotes. initial value is """""".
Integer | Fraction/Float | Boolean | String | Array | Nil | Undefined | |
---|---|---|---|---|---|---|---|
Integer | floor(x) | x ? 1 : 0 | parseInt(x) or 0 | length(x) | 0 | 0 | |
Fraction/Float | x/1 | x ? 1.0 : 0.0 | parseFloat(x) or 0.0 | length(x) / 1 | 0.0 | 0.0 | |
Boolean | x != 0 | x != 0.0 | x != "" | x != [] | true | false | |
String | toString(x) | toString(x) | x ? "true" : "false" | "[" + ", ".join(x) + "]" | "" | 99 bottles of beer on the wall | |
Array | [x] | [x] | [x] | [x] | [] | [Undefined] |
Forced and persistent type conversions
To cast the type of one expression to another, simply enclose parentheses around the expression and add the corresponding type. To permanently convert the type of one variable to another, you need to assign the corresponding type directly to the variable. For example, n = int
means converting n to an integer.
Conditional Jump
Conditional jump often show as if-elif-else statement.
There must be an if statement block in the conditional judgment statement. A conditional statement can have a large number of elif blocks or no of it, but it can have and at most one else block.
if condition: code elif condition2: code2 else code3 endif
Trinocular operator
Conditional judgement also supports trinocular operator.
B?A:C
It means, if B is true, then return A, otherwise return C.
Loops
Currently, Laktano supports three kinds of loop.
Iterative loops
for variable in sequence_or_iteration_objects code endloop
Now that we're talking about this iteration loop, we have to mention how to generate a number sequence.
Number sequence
range(start, stop, step, haveend = false, havestart = true)
This function generates an interval with start point, end point, step-length, and didn't include end point.
At the same time, the actual arguments are passed in according to the order of the parameters, so it is possible to include only one true to generate an open interval, or two false to generate a closed interval.
Conditional loops
Check-first
while condition: code endloop
Do-first
do code while condition endloop
Functions
Functions are the most important program structure, and they can make your code much shorter. Here's the definition of a function:
function function_name(*args, **kwargs): code return return_values endfunc
Since the function is mentioned, let's talk about the lambda expression by the way.
Lambda expression
lambda(*args: expression)(*your_args)
Such as:
lambda(a, b: a + b)(int(read()), int(read()))
This should be works like an A+B Problem.
Object oriented
Definition of a class
class YourClassName: attributes function __init__(self): my.attr = attr endfunc more_functions endclass
Interihance and Override
class Rect: var a = None var b = None function __init__(self): my.a = a my.b = b endfunc function circumference(self): return 2 * (my.a + my.b) endfunc function area(self): return my.a * my.b endfunc endclass ` Squares are special rectangular shapes. class Square(Rect): function __init__(self): super(Rect.a) my.b = endfunc override function area(self): return a ^ 2 ` One ^ sign refers to a power operation, and two is a bit XOR. Logical operators and bitwise operators are reversed. endfunc override function circumference(self): return 4 * a endfunc endclass
Examples
Greatest common divisor with no STL
function gcd_euclid(x, y): var int r = x % y while r != 0: x = y y = r r = x % y endloop return y endfunc function gcd_jiuzhang(x, y): var int d = x - y while y != d: x = y y = d d - x - y endloop return d endfunc var int a = int(read()) var int b = int(read()) print(gcd_euclid(a, b)) print(gcd_jiuzhang(a, b))
Fibonacci sequence
function fibonacci(x): if x < 0: return undefined elif x == 0: return 0 else: return (x + fibonacci(x - 1)) endif endfunc var int a = int(read()) print(fibonacci(a))