Wednesday, November 16, 2011

The Variable Killer

You can remove a variable from the Joshtra environment using the keyword rip

Example
a : 5;    # Define a new variable
output a; # Print the new variable value
rip a;    # Destroy the variable
output a; # ERROR the variable does not exist anymore!!!

The rip command can  be applied to arrays as well.

Friday, October 28, 2011

function -> func -> fun -> fn. Ok, here we are

It is possible to define functions in your programs.
Arguments are positional.

Example:
fn square(x) {
    return x^2;
}

The last function argument can be a parameter name followed by "..."
In this case the function can take a variable number of arguments which are accesible through a list named as the last parameter.

Example:
fn compare_many(x, others...) {
  for (i : 0; i < len(others); i : i + 1) {
    if (x > [others,i]) {
       output str(x) + " is greater than " + str([others,i]);
    }
    if (x < [others,i]) {
       output str(x) + " is less than " + str([others,i]);
    }
    if (x == [others,i]) {
       output str(x) + " is equal to " + str([others,i]);
    }
  }
}

Wednesday, October 12, 2011

It is a matter of Fortune

The Joshtra language has got the "fortune" block which allows you to define a set of statements could be executed, but only one among the listed statements will be extracted and then executed.

By default all the case statements have got the same extraction probability.
You can alter the probability specifying an integer weight parameter greater than 1.
Where 1 is the default (implicit) weight for each case statement.

fortune {
    case [<weight1>]: {
        <statement block 1>
    }
    case [<weight2>]: {
        <statement block 2>
    }
    .....
    case [<weightN>]: {
        <statement block N>   
    }
}

Example:
fortune {
    case 3: {   # 75% of probability
        output 'Good Morning!';
    }
    case 1: {  # 25% of probability
        output 'Good Night!';
    }
}

Let me give credit to Massimiliano "TheDaemon" Cuzzoli for this language construction.

Monday, October 10, 2011

It is like cooking: slicing and dicing arrays

Let's start with an array of letters
v : ('a', 'b', 'c', 'd', 'e')

We can select just some of the elements within the array, using the following notation:
[<array variable>,<index sequence or interval>]

Examples:

[v,0]
It will return the string 'a'

[v,1,4]
It will return the array ('b','e')

[v,1..4]
It will return the array ('b', 'c', 'd', 'e')

Friday, October 7, 2011

Sweet variables are made of this


The variable assignment is a fundamental statement of any imperative language.


To assign scalars the syntax is:
a : 2;
b : a + 5;
pi : 3.14;

You can assign strings as well :
s : "Good Morning";


We can't miss arrays in our language of course:
v0 : ( );  # An empty array
v1 : (1, 2, 3, 9);
v2 : (100, "Good Night", 9.9);

Wednesday, October 5, 2011

How to "capture" the "fire": exceptions

The exceptions mechanism is supported by the Joshtra language.
To define a new exception type, you have just to add the following statement:

exception <newExceptionType>;

To raise an exception you have to use the fire keyword.
The "fire" term has been inspired by another guy whose crazy mind contributed to the design of this programming language. His name is Paolo "Hooligan" Raimondi.

To catch an exception you have to use the capture construction.

Example:

# Define a new exception type
exception Boom;

capture {
    fire Boom; # raise a Boom exception
} (Boom) {
    #exception handling here
}

Tuesday, October 4, 2011

Do not disturb, because I'm sleeping

It is possible to suspend the program execution for a limited number of seconds.
The sleep interval is proportional to the number of 'm' letters within the key regular expression m*h
In particular the program will sleep 10 seconds for each 'm' letter.

Example 1:
# sleep for 10 seconds
mh;

Example 2:
# sleep for 30 seconds
mmmh;

Monday, October 3, 2011

The "else" keyword is the Evil

The Joshtra language has got the if (<condition>) construction but it does not allow the else clause.
Whether the else keyword is present in your program, it raises the exception IllegalElseKeyword

Example 1:
if (<condition>) {
    <Do  Something>
}

The code above does not raise any exception.


Example 2:
if (<condition>) {
    <Do something>
}
else {
    <Do something else>
}

The code above never executes the else block. If the program flow enter the else path, it raises the exception IllegalElseKeyword


Sunday, October 2, 2011

Let's start talking a new language

This blog aims to define the specification of the Joshtra programming language.

The Joshtra language came out of an idea by Stefano "Guandalf" Guandalini.

  • Joshtra is NOT an object oriented language
  • Joshtra is a dynamically typed language
  • Joshtra has an imperative paradigm