owned this note
owned this note
Published
Linked with GitHub
# Versatile Scripting Language
**Note**: Currently used items are starred (`★`), unimplemented ones have a white star (`☆`) (TODO)
## Goals
- Fast
- Easy to use
- Readable if used as intended
## Types
### Must-have
- `byte`
- `short`
- `char`
- `int` (for LLVM: i32)
- `long`
- `longer`
- `float`
- `double`
- `enum`
- `integer`(jo -> to use GMP/MPFR?)
- `rational`
- `char`
- `character` (Multibyte character e.g. Unicode)
- `string`
- `regex`
- `list`
- `list<t>`
- `dictionary`
- `dictionary<k, v>`
### Optional (for/against)
- `☆` `decimal` (5/0) (stored as `integer` with exponent)
- `☆` `complex` (2/0)
- `☆` `quaternion` (1/2)
- `defaultdict` (1/1) (default values) <!-- what -->
### Numeric instance checking (1/0)
**Note:** This is for `object is class`, for true subclass checking use `object isinstance class` or `object issub class`
```
number (abstract)
/
/
rational (abstract)
/ \
/ \
/ \
integer(abs) decimal
/ | \ / \
int | long float double
|
short
```
## Textual instance checking (0/0)
Text is the superclass of `string`, `char`, and `character`.
- Name for the parent "text" class (for/against)
- `text` (0/1)
## Literals
### Must-have
- `nil` (0/0)
- `null` (1/0)
- `none` (1/0)
- `undefined` (**Note:** This is different from `null`) (0/1)
- `true`/`false`
- Number
- `NaN`
- `Infinity`
- String (e.g. `"@$1 @variable @{expression}"` for variable substitution)
- List
- Dictionary
- Range (taken from Pytek) `[a..b]`, if one is excluded the other is taken as the start point, if `a` is excluded the range becomes `[b..-Infinity]`
- Like Python, slice modifies the range, not creating a list
- [Interval notation](https://en.wikipedia.org/wiki/Interval_(mathematics)#Including_or_excluding_endpoints), e.g. `[a, b)`
- Lazy (i.e. generator)
### Optional (for/against)
- Set (5/0)
- Tuple (3/0)
- List builder (3/0) (inspired by Pytek, e.g. `[$1 * 2 : [1..5]]`, `[$1 * 2 for [1..5]]`, `[i + j : i, j : x, y]`,, `[n * 2 : n : [1..5]]` and `[n * 2 for n in [1..5]]`)
- Set builder (3/0) (similar to above)
- Complex (3/1) (`1 + 1i`, `1 + 1j`)
- This and quarternion should be postponed.
- Quarternion (2/2) (`1 + 1i + 0j`, `1 + 1i + 2j + 3k`, needs either `i` and `j` or `k` to be recognized as a quarternion)
- Ellipsis `...` (3/0) (like Python's) (note: this isn't for destructuring, this is a literal that may be useful for some arithmetic functions)
## Operators
### Must-have
#### Infix
- `+`
- `"abc" + 1` =>
- `"abc1"` (0)
- `NaN` (0)
- Error (1)
- `[1,2] + [3,4]` =>
- `[1,2,3,4]` (1)
- `"1,23,4"` (0)
- Error (0)
- `-`
- `*`
- `/`
- `//`
- `**`
- `&`
- `|`
- `~`
- `^`
- `&&`
- `||`
- `!`
- `==`
- `>=`
- `<=`
- `>`
- `<`
- `=`
- `:=` (strict type assignment, meaning the variable can't change type)
- Change to...
- `-=` (0/0)
- This won't work, this is subtraction assignment
- `is`
- `issub`
- `isinstance`
### Optional (for/against)
- `::` (cast) (1/0)
- **Note:** We need to be careful on the precedence for this, we don't want multiple casts to make VSL look like Lisp
- To me, `::` has always seemed ugly.
- Cheddar also has `as`. e.g. `123 as String`
<!-- - `=>` (cast) (1/0) -->
<!-- But this is lambda syntax -->
- `->` (map) (1/0)
- `:>` (chain) (1/0) <!-- - `~>` (pass arguments to chain) --> <!-- this can be implicit as the left argument, right? -->
- `and`, `not`, `or` (alias for `&&`, `!`, `||`) (2/0)
- `++` and `--`, both prefix and postfix (0/2)
## Result types for basic operations
- `string`, `char` -> `string`
- `char`, `char` or `number`, `number` -> `number`
- `char`, `number` -> `char`
<!-- This is multiplication or what? -->
<!--Pls pls pls no implicit typecasting. its slow and error-prone -->
- `string`, `number` -> `string`
## Special variables
### Must-have
<!-- I thought we changed it to %-->
<!-- That won't work, it's modulo, this is fine even with shell syntax -->
- `$` (arguments)
- `$<n>` (`n`th argument)
- `$_` (for loop arguments)
- `$_<n>` (`n`th for loop argument)
## Syntax
### Function (for)
- JavaScript (3)
```
function <name>(<arguments>){ // this returns nothing
<body>
}
function <name>(<arguments>) -> <type>{
<body>
}
<name>(<arguments>)
```
- Pytek (0)
```
func:<name>[<opts>](<parameters>){
<body>
}
\<name>[<opts>](<arguments>)
```
- Java (1)
```
<type> <name>(<args>){
<body>
}
<name>(<args>)
```
#### Possible function keywords (for)
- JavaScript (1) `function`/`fn`
- Python (1) `def`
- Cheddar (1) `func`
- Perl `sub`
- `fn`
### Lambda
```
=>3
n=>n*2
(n : integer) : integer => n * 2
=>$1+$2
=>{return $1+$2}
```
Feel free to comment on/edit the lambda syntax if you have anything to add/there's anything you don't like
- New lambda syntax proposal (1/1)
```
func n => n*2
```
- This is unnecessary, lambdas are meant to be inline anyway
<!--yes, func n=> n*2 would be an expression-->
### Class
```
// also class foo extends baseclass implements interfaces with traits
class foo(bar : string, baz) : baseclass : interfaces : traits {
constructor () {
//
}
init {
//called after construction
}
static foo () {
//
}
get foo () {
//causes error, foo is already defined or something like that
}
get bar () {
//
}
set bar () {
//
}
}
```
#### Constructor
JavaScript
```
constructor () {
//
}
```
C#
```
MyType () {
//
}
```
#### Accessors and mutators
JavaScript
```
get property (name: string) {
//
}
set property (name: string, value: object) {
//
}
```
C#
```
<type> <name> {
get {
//
}
set {
//
}
}
```
### Class keywords
- `class`
- `interface`
- `enumerable`/`enum`
## Argument/variable definitions (for)
- Cheddar (2)
```
<name>[ : <type>][ = value]
```
- C-derived (1)
```
[<type> ]<name>[ = value]
```
## For loops
### Must-have
```
for (initial; condition; modification) {
//
}
for var in iterable {
//do we need parens?
//they should be optional (1/0)
}
for <type?> var : iterable { ... } //Java
for a, b, c in i1, i2, i3 {
//
}
```
## Pattern-matching
<!-- I think this is good idea -->
```
func fib :: Number => Number;
fib(n < 2) => 1
fib(n) => fib(n - 1) + fib(n - 2)
```
if multiple variables used in condition:
```
f(param where cond) => expr
```
With codeblock:
```
f(cond) {
code
}
```
## Switch-case (for)
- Ruby (0)
```
case <expression>: {
when <regex>/<range>/<multiple range>
}
```
- Cheddar-derived (1)
```
switch <expression> {
case <equality>:
case <anotherequality>:
foo()
break
when <match>:
bar()
break
case 1 {
// no break needed
}
}
```
- Cheddar (1)
```
switch <expression> {
case <expr>: a();
case <expr> {
b()
}
when <match>: c();
}
```
## Class things
### Constructor
- JavaScript (0)
```
class Foo {
constructor () {}
}
```
- C# (0)
```
class Foo {
Foo () {}
}
```
## Miscellaneous syntax
### Must-have
- Destructuring/unpacking syntax `{asdf, ghjk} = {asdf:1, ghjk:2}`, `foo, bar = 1, 2`, `foo, *bar = 1, 2, *baz`
- Access operator `.` (no `->` and `::`, partly to free them up)
## Possible syntax (for/against)
- Function flags (1)
```
function fib(n : int) : integer -m -f {
return fib(n - 1) + fib(n-2)
}
function fib(n : int) : integer --memoize --foo {
return fib(n - 1) + fib(n-2)
}
```
- Function flags with `@` (0)
- Or decorators? (0)
```
@memoize
@foo
function fib(n : int) : integer {
return fib(n - 1) + fib(n-2)
}
@m @f
function fib(n : int) : integer {
return fib(n - 1) + fib(n-2)
}
```
- Both? (2/1)
- More complicated slice (1/0)
```
<variable>[<start>:<end>;<step>:<chunk>;<overlap>]
e.g. array[;;3]
```
- A simple and short way to execute terminal commands, this is indeed a scripting language.
- `$ command` executes `command`. (0/0)
- `@{var_name}` in a terminal command will be replaced with the variable in VSL. (1/0)
<!-- IMO When using `$`, to execute, the command should be asynchronous idk how 2 spell -->
<!-- many build scripts depend on order - maybe async routines?-->
<!-- Okay that is true. i guess it should be sync -->
<!-- Idea: use `@{}` syntax in these to reference a VSL variable
why? your cursor is mad! oh right you are vim user-->
<!-- example usage: -->
<!--
let myvar: string = "goat";
$ echo @{myvar}
f**kin' beautiful, mate!
:D
Maybe `$` should be async and ` ... `should be sync?
imo there should be some difference between the two
what do you mean '...'? like:
... echo "hi i iz goat"
?
Connection to downgaot lost. Over and out.
i think he means backtick shell syntax
-->
<!-- also btw, parrelism in build scripts might be nice - like dependency-based, do async ASAP
like a graph/network -->
- `` `command` ``, ``async `command` ``, ``a = `command` `` (0/0)
- Both? (2/0)
- List comprehension synax
- `[i+1 for i in x]`
- `[i+1 for every i in x]` (0)
- `[i + 1 : i : x]` (0)
- `[i + 1 : i <- x]` (0)
- `[for a in b: a + 1]` (3)
- `[for(a in b) a + 1]` (0)
- Easy syntax for parsing command line arguments (it's a scripting language!)
- Like `argparse`? Or just argv implicitly amd make it a `dictionary` and reserve `argparse` for just the help dialog?
- Something simple, like `if '-x' in flags`
- IMO we should do it like argparse, `flags.x`
- I think argument parsing class is best idea. e.g. `ArgParse { $.argv }` for example returns ArgParse object
- argparse module (1/0)
- Optional semicolons (3/0)
## Conventions (for/against)
- `CamelCase` for classes (2/0)
- `lowercase_with_underscores` for other items (2/1)
- `UPPER_SNEK_CASE` for constants (1/0)
- `CamelCase` for public variables (1/3)
- A public var could be confused for a class
- `pascalCase` for private variables (1/0)
- `issub` (0/0)
- `isinstance` (0/0)
- space between `//` and line comment (1/2) [`// foo` not `//foo`]
- getters and setters outside of classes (1/0)
- for the standard library
- `<=` as an equivalent to `=` (1/1)
- Rationale for above two:
```
sys.workdir <= `~/`
```
<!--
- Why not?
- this is not python
- it's uglier....
- but why is it uglier in VSL?
- because // is not #
- C++ style guides say to use `// foo` too
-->
- space between function name and argument list (0/1)
- remove `for (initial; condition; afterthought) {}` syntax (1/2)
- how we do it then
- range(), like python
- optional parens if (222222222/0)
- C++ integration - this should not be hard
- Compilation to JS (1/0)
- JS is... uh... not *the* best. This lang could replace it.
- JS is slow, we can just use this <s>when</s> if we integrate with Chromium
- JS Compilation is rather easy for reference.
## Definitely not
- Python's whitespace sensitivity
## Definitely
- Braces