StormLang
StormLang is collaboratively designed by PSTF, None1, and islptng.
Language Overview
StormLang is turing-complete, supports to make gorgeous program and access the Internet, and may also construct artifical intelligences, high-level, strong like the fire, efficient like storm(thus it get the name "StormLang"), fast as tigers pounce on food.
Basic Syntax
I/O
read() write(a, ascii = false) input() print(a, end = '\n') getchar() putchar(a)
- Resolves the input string to the type of the transfer destination.
- Parse everything into numbers and output. If the ascii method is enabled, for a string of length equal to one, its Unicode value is output; For a string greater than one in length, the Unicode value for each character is output, in array.
- Parse everything you enter into a string.
- Directly outputs the value of a, ending with the end variable (line break by default).
- Only one character can be entered.
- Only one string of length 1 can be output. If you try to output a boolean, false corresponds to "F" and true corresponds to "T". Try to output a number, if it is an integer, convert it to characters according to the encoding and output, otherwise it will be rounded and processed as an integer.
Identifier
StormLang uses every identifier that:
- Doesn't not started with number.
- Does not include special symbols.
- Is not a keyword.
It is important to note that StormLang supports all kinds of Latin, Greek, Cyrillic, even Japanese, Chinese, Korean, and all left-to-right scripts, but not historical scripts, such as Rune, Gothic, cuneiform, or right-to-left scripts such as Arabic, Hebrew, Syriac, etc.
Thus, a, _i, my_name, PRYSIGNETOFRY, number_2, 我的名字, 私の名前, _i_s_l_p_t_n_g_, are legal identifier, and while, $money, 42dk, false, are illegal identifier.
At the same time, we stipulate that if a variable starts with two underscores and is all uppercase, then the variable is protected by StormLang.
Variable
By default, all variables are global (unless you've declared them local) and can be accessed casually, even to a non-existent variable, without compilation errors or resulting in traceback output, but with a null value - None.
Of course, if you have declared its type, its value will be the default.
Use this code to define an variable:
var (var_type) var_name (= var_value)
Constants
Constants are the variable that unchangable.
Use this code to define a constant:
constant const (const_type) const_name = const_value
Data types
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 "". Use parseInt(), parseFloat() and parseLogic() to convert string to int, float or bool.
- 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. When they converted to string, they becomes "啊?".
- 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. They converts to 0, but they can used to be false. When they converted to string, they becomes 99 bottles of beer.
- Thread. It can fork a process out to do another program.
Special Assignment
StormLang also can assign many values to many variables.
When encountering an assignment statement, StormLang will evaluate all the values on the right before performing the assignment operation, so we can swap the values of the variables like this:
x = 6 y = 9 x, y = y, x
Index
StormLang uses subscript to index. However, -1 returns the first-to-last element, -2 is the second-to-last element, -3 is the third-to-last element, and so on. Float index are rounded down. Arrays are indexed from 0.
Function
func [function_type] function_name(*args, **kwargs) { code [return return_value] }
Statement Block
Statement blocks are enclosed by braces, and every commands seperates with semicolons.
Iterative loop
for iterator in iter_containers: { code }
In an iteration loop, the same code is executed for every element (e.g., a number in a sequence) in an iteration container (e.g., a sequence). Sequences can be generated using range(a, b, c)
.
The range() function actually generates a semi-open interval that contains a but not b, in steps of c. If you need an open interval, use the seq() function. If you need a closed interval, use the interval() function.
Comment
# Single Line #* Multi Line *# """Document comment, or Document string(needn't escaped)"""
Conditional jump and loop
Bracketed means you can omit.
if(condition) { code } [ else if(condition2) { code2 } ... else { last_code } ]
B?A:C
while(condition) { code }
Number Represent Type
Fractions
a/b
Fractions are most basic type of number. Slash can be used for fraction or division.
Real Number
m.n0n1n2n3...nn(...)
You can also represent a number by decimal point.
If a number ends with three dots at the end, it means that it is an infinite decimal (if it is preceded by at least three cyclic sections, it is an infinite cyclic decimal, otherwise it is an infinite non-cyclic decimal).
Integer
Simply an integer. If n is an integer, then it is equal to the fraction n/1.
Other base
0x for hexadecimal 0o for octal 0b for binary 0p for quatile 0i for vigintal 0t for ternary 1t for balanced ternary 0x0.19999999999999999... # Should return 0.1
Complex number
Complex numbers are represented by the form a+bi. Note that 1i cannot be represented as i. When you try to "flip" a complex number, it will return the conjugate complex number (a-bi) of that complex number. Taking an absolute value for a+bi will return the distance from the point with coordinates (a, b) to the origin, i.e., the complex modulus.
Built-in constants
- pi = 3.1415926535897932384626433832795
- e = 2.7182818284590452353602874713527
- sqrt2 = 1.4142135623730950488016887242097
- sqrt3 = 1.7320508075688772935274463415059
- sqrt10 = 3.1622776601683793319988935444327
- phi = 1.6180339887498948482045868343656
- lge = 0.43429448190325182765112891891661[1]
- ln10 = 2.3025850929940456840179914546844
Object oriented programming
obj name[(superclass)]: func __init__(self): # TODO end func function_name(self, *args, **kwargs): # TODO end end
For example, we uses a class to generate a boy in binary flow:
obj person: string name = None int age = None bool gender = None func __init__(self): this.name = name this.age = age this.gender = gender end func string intro(self): return age <= 18?f"Hi! I'm {this.name}. I'm {this.age} years old, and I'm a {this.gender?"girl":"boy"}.":"Error" end end # It's worth noting that in general I'm used to using "false" for male and "true" for female. x = person("Kelly", 15, false) # Both "false" and "False" are work, also same as "true" and "True", or "none" and "None". print(x.intro())
Override, and Super-class
First, we defines a class that means a reectangle.
obj rect: int a = None int b = None func __init__(self): this.a = a this.b = b end func int area(self): return a * b end end
Then is a square.
obj sq(rect): func __init__(self): super(a) this.b = a end override func int area(self): return a ^ 2 end end var square = sq(5) print(square.area()) # Should output 25.
Advanced Syntax
Numeric inputs
When use read() to input a number, if slash detected, then treat it as fractions, if point detected, then treat it as float, if prefix of other base detected then treat as another base.
Example
Hello, world!
print("Hello, world!")
A+B
var int a = read() var int b = read() print(a + b)
Categories and References
- ↑ Because 彁 is lge in Shidinn, so PrySigneToFry also call it 彁 constant.