I need your feedback about a new programming language idea to improve its design.
Tags: discuss, opensource, scriptinglanguage
Published: 2019-05-29 15:41:36

Hello, I want to create a new programming language named `codescript`. It will be open source and free. [This repository][3] is where I started.

I need your feedback about it. So I can improve the design of the language.

It will be a [scripting language][1] and will be compiled into its own byte code.

*DISCLAIMER: I'm not very well at speaking the english language, but I am an experienced programmer, so I can do a better explanation of it by code examples.*


ok, let's start.

imagine you opened a file named `main.code` for writing `codescript`.

At the first you start writing a file, there is no variable or function defined, and there is no `if`, `else`, `else if`, `for` or `while` token that can be understood by compiler. program flow and other stuff will be written just by symbols. Also, there is no `print` or `puts` function for writing text to `stdout`. (they can be accessed by `[# system]` module). So there's no limit for your variable names except that they should match the [Regex][2] pattern `[_a-zA-Z][_a-zA-Z0-9]*` and also they can't be `T`, `F` or `N` constants.

Now, data types that can be stored in the variables:

    // comments start with two slashes.

    char = 'a'
    int = 10
    float = 2.3

    bool = T                 // or F
    none = N

    // `;` can be used to separate statements, but aren't mandatory.

    array = [1, 'a', T];
    string = "abcd";
    code = #(a = 10);

    object =
    {
        name = "jack"
        age = 10
    };

    function num => 10 * num;

    // `function` is not a keyword. you are defining a function named `function`.

#### char, int, float

`char`,` int`, `float` are simple data types that you may know.

    english_first_letter = 'a'
    seconds_in_a_year = 60 * 60 * 24 * 365
    pi_number = 3.14159265

#### bool, none

`bool` and `none` are for boolean, and none, respectively. you can't and (`&&`), or (`||`) between `bool` and `none` data types:

    boolean = T || N            // error: `bool` and `none` can't be Or-ed.

also between other data types:

    boolean = "Hello" && 5      // error: `string` and `int` can't be And-ed.

They were allowed only between `bool` data types:

    true = F || T
    false = true && F

    // we can also xor between booleans

    var = T ^^ F            // var = T

#### array, string

`array` and `string` data types just exist because of the computer memory data model. I want to design codescript as simple as possible. And let the developer do the extra work with his own creativity. the only difference between `string` and `array` is that `string` data type can only store `char`.

    name = "John"
    name_len = name.len            // name_len == 4

    numbers = [2, 4, 6]
    numbers_len = numbers.len      // numbers_len == 3

#### code

`code` data type is just a piece of code. that means when you type:

    code = #(a = 10)

you are storing a `variable definition statement` into another variable.

Ok, let me give you examples:

    define_var = #(var = "Hello");

    define_var;                      // it's the same as: var = "Hello"

    hello_world = var + " World";    // hello_world == "Hello World"

We can also store calculation statements:

    var1 = #(2 * 3);
    var2 = 2 * 3;
    // type of var1 is `code`, but var2 contains `6`, which is an `int`.

    a = var1;
    b = var2;
    // now, `a` and `b`, both are of the type `int`.

or store multiple statements:

    code_object = #(name = "Jack"; age = 20;);

    code_object;
    // now, `name` and `age` are defined.

Or defining a variable based on previous definitions:

    define_b = #(b = a * 10);
    a = 3;

    define_b;
    // now, b == 30

It's worth that we can store code statements into a variable, and I will show you the advantages of this later.

#### object

`object` data types are just like namespaces, or maybe classes. you can define variables inside them, and you can access them or assign them by `.` member access.

    object = 
    {
        name = "Jack"
        age = 20
    }

    // object.name == "Jack"
    // object.age == 20

    // assign color member of object, not previosly defined:
    object.color = "white"

objects can be used for a block of code, for example:

    array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

    ten_times_array_len = 
    {
        result = 10 * array.len;
    }.result;

    // you might have guessed that ten_times_array_len is equal to 100.
    // and there is no variable defined named `result`.

#### function

`function` data types are just functions. They can be called, and return any type of data.

I'm not very sure about the function definition style, I'm thinking of some styles:

    // --- style 1 ---

    // function declaration:
    sum a b => a + b;

    // anonymous declaration:
    sum = (a b) => a + b;

    // --- style 2 ---

    // function declaration:
    sum a b = a + b;

    // anonymous declaration:     
    sum = (a b) = a + b;

    // or anything else...

if you want to create a new programming language, which style you prefer? In my opinion, the lack of use of semicolons between arguments is less costly. they can be separated by spaces.



> This post is not over and I try to complete it over time.

[1]: https://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Scripting_languages
[2]: https://www.google.com/search?q=regular+expression+definition
[3]: https://github.com/mak12776/codescript