User:PrySigneToFry/Sandbox/StormLang discussion

From Esolang
Jump to navigation Jump to search

Here is a discussion page for the programming language that will be designed collaboratively by PrySigneToFry, None-One and islptng.

Discussion area

Should we make some standard library for StormLang? --北国风光,千里冰封,万里雪飘。望长城内外,惟余莽莽;大河上下,顿失滔滔。山舞银蛇,原驰蜡象,欲与天公试比高。须晴日,看红装素裹,分外妖娆。江山如此多娇,引无数英雄竞折腰。惜秦皇汉武,略输文采;唐宗宋祖,稍逊风骚。一代天骄,成吉思汗,只识弯弓射大雕。俱往矣,数风流人物,还看今朝。 2025年2月15日(星期六),14:27 农历正月十八 (CHN)

PSTF's Design

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").

I/O

read(a)
getchar(a)
write(a, ascii)
putchar(a)
puts(a) # Put string
gets(a) # Get string

Variable

type name = value # Initialization
name = value # Assignment, e. g. a = 0
# Also can omit the space
# Set to None to create blank variable

Number represent type

# The slash symbol can represent a division or a fraction.
1/5 # Equal to 0.2
# When it can be expressed as a fraction of a finite decimal, and it can be expressed directly as a decimal. 
# The same is true for irrational numbers.
0.03 # This is equal to 3/100.
# A fraction with a denominator of 1 can be directly expressed as an integer.
1145141919810
# Other decimal numbers are also supported.
0x0A # Equal to 10
0xC.8 * 0x08 # Should return 100, because 0.5 in hexadecimal is 0.8
0o10 # Equal to 8
0b1010 # Equal to 10
0t112 # Equal to 14
1t1001T # Equal to 83
0q13 # Equal to 7
0p114 # Equal to 34

1/3 # 0.3333333333333333...
0.333333333333 # 333333333333/1000000000000

# If a number ends with three dots at the end, it means that it is an infinite decimal (if it is preceded by three cyclic sections, it is an infinite cyclic decimal, otherwise it is an infinite non-cyclic decimal).
0.142857142857142857... # 1/7
0.142857142857142857 # 142857142857142857/1000000000000

String VS Character

StormLang uses string, and treat character is 1-lengthed string.

If you print a string of two lengths greater than or equal to two as characters, only the first character is printed. If a string is output as a number, the number output is parsed directly from it, unless the encoding to be output has been specified, in which case only the encoding of the first character is output.

putchar("Hello, world!") # Outputs "H"
write("114514") # Outputs 114514
write("114514", true) # Outputs 49

Array? Table?

islptng gives the design of array, but I also like LUA so I thinks for "Table". But finally Array wins because I'm more learned C++ than LUA.

array my_list = [1, 2, 3, 4, 5] # Normal array declare
array another_list = [1, 2, "Hello, world!", true, [2, 3, 5, 7], (1, ), "\n\n\n\n\n"]
# My most learned and skilled language is Python, so array can store everything.
tuple coordinate = (0, 0) # Tuple can't be modified, but can be re-assigned.
array dictionary = [name = "StormLang", level = "High level"]
# If you include an assignment statement in an array, the array is considered a "dictionary", and each element is a key-value pair.

Object

StormLang is OOP.

obj name[(superclass)]:
    func __init__(self):
        # TODO
    end
    
    func function_name(self, *args, **kwargs):
        # TODO
    end
end

Example:

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())

Function

func [function_type] function_name(*args, **kwargs)
    code
    [return return_value]
end

None1's Design

Variables:

a=0

I/O:

read (a)
cread (a)
write (a)
cwrite (a)

While loops:

while(condition)
...
end

Conditionals:

if(condition)
...
[else
...]
end

functions

func [function name] (args)
[code]
end

OOP

obj [type name]
func constructor (args)
[code]
end
func [function name] (args)
[code]
end
end

To be continued...

(Our designs should be merged together).

islptng's suggestions

I think you should make an interpreter. Once you add a command, you should implement it.

Comment:

# This is a one-liner
#* this is a multi-liner *#

Declaration:

decl a, b(1), f(2) # a is a variable, b is an array, c is a 2-argument function

Assignment:

a <- -2/3; # Numbers are fractions. = is used for equality, <- is assignment.
b <- [1,2,a]; # Arrays are 0-indexed.
f <- { # {} for code block
  decl addn1 <- :[0]; # : for argument
  decl addn2 <- :[1];
  decl res <- addn1 + addn2;
  : <- res; # : also for return
}; # Remember, everything needs a semicolon to stop!

For loop:

for(1,b/len(),1) # from, to, step
{ #* code *# };