lesl
v1.1.1
Published
LESL - The simple and fun 'programming language'
Downloads
2
Maintainers
Readme
LESL 'programming language'
The LESL is current in beta, and have some bugs:
- Console highlighting is too buggy Minuses:
- LESL not have functions
- Not standart syntax
The syntax
Variables
Grammar:
name -> value
Example:
x -> 1
y -> 5
a -> 3
b -> 2
String functions
Variables has 'prototype' of string functions.
Math with variables
Variables may used in equations.
Example:
x -> 5
y -> 6
x + y * x
=> 35
Comments
# Comment
IF
a (is|not|less|more) b (and c (is|not|less|more) d)...? [ true ] : [ false ]
Example:
a not b?
=> true
x is y? [ "OK" ]:["NOK"]
=> NOK
Marks
name [ source ]
Call mark
name!
Example:
greeting [
"Hello, World"
]
greeting!
=> Hello, World
from-to loop
Returns list from x to y, separated by ','
Standart
Grammar:
from x to y
Example:
from 1 to 12
=> 1,2,3,4,5,6,7,8,9,10,11
Short
Grammar:
x..y
Example:
1..12
=> 1,2,3,4,5,6,7,8,9,10,11
Math with lists
You may do math only(!) with short lists. If we look at this example:
1..5 + 1
That outputs
=> 2,3,4,5
That pluses 1 to EACH list element. If we look at another example:
1..5 ^ 4
That outputs
=> 1,16,81,256
That makes pow of EACH list element.
Numbers
Dollars
LESL have built-in dollar translation. To select course, create in root of LESL file options.json, and write content like this:
{
dollar: 56.9
}
After this simple operation, you may do dollar translation:
200$
=> 11611
And do with this dollars mathematical operations:
200$ + 12000 - 5000
=> 18611
Floats
Float is number with floating point.
Example:
12.5
1.3
0.6
19.4
3.14
Integers
Example:
1
53
12
75
666
999
512
Strings
String is all inside double quotes, besides newlines, and double quotes.
Example:
"Hello, World"
"Hi"
"Hi, NPM"
String methods
String also has functions for operate with it.
str.slice s, e
Slices from start(s) position to end (e) position.
Example:
"Hello".slice 2, "Hello".len => llo
str.len
Get length of str string.
Example:
"Hi".len => 2
str.uppercase
Convert string to uppercase.
Example:
"Alexey".uppercase => ALEXEY
str.lowercase
Convert string to lowercase.
Example:
"Alexey".lowercase => alexey
str.capitalize
Make first letter in string uppercase.
Example:
"i am here".capitalize => I am here
str.reverse
Reverses the string.
Example:
"Hello, World!".reverse => !dlroW ,olleH
str.char i
Get char on i index in str.
Example:
"Hellow".char "Hello".len => w
Include other files
To include other files, you also may use 'use' command. That imports all variables and marks from including files.
use name - String
Example:
use "core/booleans"
$> true
=> 1
$> false
=> 2
$> LESLBooleans!
=> LESLBooleans library by Alexey Yurchenko
true / false / yes / no / ok / nok
Examples
Hello, World!
"Hello, World!"
=> Hello, World!
Math
12 * 2^4
=> 192
2 + 2
=> 4
Math constants library
./math_const.lesl
PI -> 3.14
E -> 2.71
./example.lesl
use "math_const"
PI
=> 3.14
E
=> 2.71
PI + E
=> 5.85
(C) Alexey Yurchenko.