DEV Community

Cover image for Minky scripting language
Techie Kho
Techie Kho

Posted on • Edited on

Minky scripting language

Edit: It has been rebranded to Blinklet, here is the repo

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

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)
Enter fullscreen mode Exit fullscreen mode

In Minky, since we disdain parentheses, we replace all the separating symbols with whitespace

function arg1 arg2 arg3
Enter fullscreen mode Exit fullscreen mode

But... what if I want to inline a function call as an argument like this?

function(arg1, arg2, another_function())
Enter fullscreen mode Exit fullscreen mode

Well, in Minky, you just indent it!

function arg1 arg2
    another_function # This will call
Enter fullscreen mode Exit fullscreen mode

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!
Enter fullscreen mode Exit fullscreen mode

Well, you just prefix it with | to cancel out the call

function arg1
    another_function
    | arg3 # Pass as value!
Enter fullscreen mode Exit fullscreen mode

Some features

  • String interpolation
  • Closure
  • Loose Object-Oriented Programming

String interpolation

To do string interpolation:

some-command 'Text `identifier`'
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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!'
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

To extend:

var Police
    Person
        set name 'Policeman'
        set age 15
        var gun 'AK15'
Enter fullscreen mode Exit fullscreen mode

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. Thank you for reading and have a nice day.

Top comments (2)

Collapse
 
hady_eslam profile image
Hady Eslam

Are you interested in helping me with a new programming language?

Collapse
 
rechie_kho profile image
Techie Kho

No, sorry. Making a language is quite time consuming and I already have couple projects on my hand.