Minky scripting language
Tags: programming, rust, coding, showdev
Published: 2023-11-15 12:38:29

*Edit*: It has been rebranded to Blinklet, here is the [repo](https://github.com/RechieKho/blinklet)

So I have written a simple scripting language in Rust, the obscure language for a lot of devs. It is called "Minky".

Here is the [link](https://github.com/RechieKho/minky)

The whole idea of this language stems from this thought:
> What if we remove parentheses from LISP?

Essentially, Minky is my version of WISP.

## Syntax
Let's jump into the syntax:
In a typical C-derived language, a function call usually look like this:
```
function(arg1, arg2, arg3)
```

In Minky, since we disdain parentheses, we replace all the separating symbols with whitespace
```
function arg1 arg2 arg3
```

But... what if I want to inline a function call as an argument like this?
```
function(arg1, arg2, another_function())
```

Well, in Minky, you just indent it!
```
function arg1 arg2
    another_function # This will call
```

If you don't indent it, `another_function` will be passed as value. 

But! What if I want to pass value after some indents?
```
function arg1
    another_function 
    arg3 # I don't want this to get call!
```

Well, you just prefix it with `|` to cancel out the call
```
function arg1
    another_function
    | arg3 # Pass as value!
```

## Some features

- String interpolation
- Closure
- Loose Object-Oriented Programming

### String interpolation
To do string interpolation:
```
some-command 'Text `identifier`'
```
The `identifier` is the variable name, it will substitute with the variable's string representation.

### Closure
All the user-defined functions are closure. It has access to the lexically scoped variable. In simple term, the scope that the closure is declared in lives with the closure until the closure itself dies, and the closure can access the scope.

Here is an example:
```
var make-counter
    closure
        var counter 0 # counter will live with the returned closure even after `make-counter` complete execution.
        return
            closure
                set counter # access parent counter.
                    add counter 1
                println 'counter: `counter`'

var counter
    make-counter

counter # 1
counter # 2
counter # 3
```

### Loose Object-Oriented Programming
In normal class-based object-oriented programming, we have class and object, in which the object's structure is based on the class. In Minky, all of the classes and objects are table. Tables are *not* linked together in anyway, but you can make a copy of a table (instancing) and extends on top of it (inheritance). Table is also act as scope, too!

To make a person class:
```
var Person
    table
        var name 'Bazinga'
        var age 25
        var say-hi
            closure # aka. function but has access to parent scope.
                println 'Hi! I am `name`. Nice to meet you!'
```

To make an instance:
```
var peter
    Person
        set name 'Peterson'
        set age 90

# Call the method
peter
    say-hi

# Access values
var peter-age
    peter
        return age
```

To extend:

```
var Police
    Person
        set name 'Policeman'
        set age 15
        var gun 'AK15'
```

## Conclusion
It is my attempt on making a scripting language. There are more feature to be discussed, and to be added. You can fetch the code at [my GitHub repo](https://github.com/RechieKho/minky). Thank you for reading and have a nice day.