Thursday, July 25, 2013

Frost! v.0.1.2

Added "for each" loop! :-)

New echo example.

"Database" example.

EDIT: Pseudo Object-Oriented example:

// ...

main:args {

   var polygons = {
      [newTriangle pointA:{0, 0} pointB:{5, 0} pointC:{0, 5}],
      [newTriangle pointA:{0, 0} pointB:{2, 0} pointC:{0, 2}],
      [newCircle centre:{0, 0} radius:10.0],
      [newTriangle pointA:{0, 0} pointB:{3, 0} pointC:{0, 4}],
      [newCircle centre:{2, 2} radius:5.0],
      [newSquare pointA:{0, 0} pointB:{2, 0} pointC:{2, 2} pointD:{0, 2}]

   foreach(p in polygons) {
      [print string:"Perimeter: %v\n" format:{[polygonPerimeter polygon:p]}];
      [print string:"Area: %v\n\n" format:{[polygonArea polygon:p]}];

Download complete example!

Tuesday, July 23, 2013

Frost! v.0.1.1

A new version of the Frost Programming Language interpreter is now available! Now it is possible to create function pointers (or function references), call a function referenced by a variable or an array, and it is possible to create Blocks (just like Objective-C Blocks but with a different syntax)!


This generic bubble-sort can receive an array of any type of data to sort, as long as you provide it with a "compare" function capable of comparing these types of data.

How to create a function pointer?

var printPointer = @print;

// OR

var someFunctions = {@print, @scanInt};
How to create a block?

var a = ^ { [print string:"I am a Block!\n" format:{}]; };

// OR

const b = ^:a {
    [print string:"I am another Block... \'a\' equals %v\n" format:{a}];

// OR

var arrayOfBlocks = {
    ^{ [print string:"First!\n" format:{}]; },
    ^{ [print string:"Second!\n" format:{}]; },
    ^{ [print string:"Third!\n" format:{}]; }

How to call a block or a function referenced by a variable?

[~printPointer string:"Hello!\n" format:{}];

[~someFunctions[0] string:"Hello again!\n" format:{}];

[~b a:5];

var i;
for(i = 0; i < arrayOfBlocks.length; i = i + 1) {

Thursday, July 18, 2013

Why not a new programming language?

Hello World!

In the past few days I've been programming (in my spare time) a new programming language interpreter! This new interpreter is a refactored and improved version of the Ceres programming language interpreter, though the programming language syntax is not the same as before and this new interpreter is written in C whereas the other one was written in C++ and used STL. This time I'm calling the programming language Frost, first because I like cold weather, and second because the name of my previous interpreted programming language (Ceres) was the name of the goddess of agriculture and, as you might know, frosts can destroy entire crops, so a good name for a stronger successor would be one that could totally replace (or eliminate) the previous one (just like the frost over the crops).

But then you are gonna ask: why are you doing this?

One reason is because I felt that my previous interpreter was a complete failure and I wanted to create something better that could have practical uses. Another reason is because I really liked some of the characteristics of Objective-C, so I wanted to create something with some of these characteristics (named function parameters especially).

Echo, echo, echo....

Now you ask: what's special about this new programming language of yours?

Well, nothing yet. Theoretically you can write any program that you could write in C, but using my language. This language is very different from C, but it has the same basic functionalities (i.e. you can: define structs, use arrays, use control flow statements, ...), and some extra functionalities (implicit memory allocation, garbage collection through automatic reference counting, dynamically typed variables, attributes, ...). As any other major interpreted language, you can create bindings of your C functions to the interpreted program.

Here you can see a "generic" stack. This stack can receive any type of data.
In this case, it has received some matrices.

One advantage of this new programming language is that it makes it easy to define some data structures such as graphs, sets, trees, stacks, and matrices. You don't even need to specify your structure, all you need to do is create a hierarchy of arrays (you don't even need to specify the length of these arrays, though it is much more efficient if you do so). You also don't need to worry about memory allocation and deallocation, as it is done automatically for you (I still need to test it for memory leaks and "segmentation faults", but it should work well, especially if you don't have "reference loops" in your data topology).

Creating a simple binary tree...

const left = 0, right = 1;


main:args {


var root = {nil, nil}; // Root node
var childNodeLeft = {nil, nil}, childNodeRight = {nil, nil};

root[left] = childNodeLeft;
root[right] = childNodeRight;

root[left][left] = 0;
root[left][right] = 1;
root[right][left] = 2;
root[right][right] = 3;


Or, if you prefer...
var root = {{0, 1}, {2, 3}}; // Root node

You can add more levels...
var root = {{{0, 1},{2, 3}}, {{4, 5}, {6, 7}}};

Those leaf-nodes could have different types of variables...
var root = {{{'a', "Hello"},{2.5, 3}}, {{nil, {'H','E','L','L','O'}}, {-6, 7}}};

This possibility of having any type of variable in your leaf-node can be very useful because once you have programmed your own "binary-tree" library, you can use it with any type of data.

Interesting, where can I download it?

This project is available for download on SourceForge. Before downloading, note that this new language is still very young (it is almost two-weeks old) and it hasn't been properly tested nor it has some useful libraries (as of version 0.1, there is only one library: libIO that has some very simple functions for input/output).

This interpreter should compile on any POSIX system (I only used libc and posix system calls), but I only tested it on Mac OS X 10.8.4 (Darwin 12.4.0), and on Ubuntu 12.10 (Linux 3.5) and the included Makefile will only work on these systems.

Also note that I don't use efficient data structures for the internal variable and function handling (I only use linked lists), so this interpreter can run potentially slow if you have too many variables or functions in your program. I am about to improve these data structures as soon as I have time to do it...

If you plan to use this new language, note that its grammar is right-recursive (I know, it shouldn't be, but it is... I did not use Yacc to create a left-recursive grammar, I created my own recursive descent parser instead).


 - New interpreted programming language!
 - Interpreter written in C.
 - Structured programming language (Object-Oriented in the future)
 - Dynamically typed variables, garbage collection, attributes, named parameters, easy to create graphs and trees, ...
 - Still beta, might run slow, compiles on Linux and OS X.


Monday, July 1, 2013

RayTracer for iOS! [5th version]

This new version has some performance improvements, I recommend you to download it instead of the others (it will run much faster than the previous version).

I am about to publish this app on the official Apple App Store, so I would like to hear some feedback from you before I do that. Thank you!

 + HUGE performance improvements!
 + Bug fixes.