This is a mirror of official site: http://jasper-net.blogspot.com/

anic - Faster than C, Safer than Java, Simpler than *sh

| Sunday, November 14, 2010
Tutorial  
This article is here to answer one key question: How do ANI programs work?

Let's forget about the other programming paradigms out there for a second and take a look at the approach that ANI takes. ANI programs are clean and simple to understand (and even easier to write!), but work quite differently from those in other languages; for example, there is no exlicit sequential ordering to your code -- the compiler sequences the contol flow automatically, and usually in parallel! This friendly tutorial is designed to help get you acquainted with these new concepts and get started with programming in ANI. So, let's jump right in!

Pipes
ANI programs are made up of pipes though which data flows. The data in question is encapsulated in objects; ANI is a pure object-oriented language in that everything, without any exceptions, is an object. Computation involves objects flowing forward through a pipe, and along the way, interacting with other objects. Objects can come to a rest at certain points, and be flushed down the drain at others. And most importantly, objects flow through pipes in parallel.

All of this seems complicated, I know. But it's actually much, much more intuitive than any traditional imperative programming language you know! I'll prove it. This is Hello, World:

"Hello, World!" ->std.out
What's happening here? Well, the string object, "Hello, World!", is sent using the -> operator to the standard output, std.out. Thus, you see "Hello, World!" on your screen.

Note, we could put a ; at the end of this line, like in other languages, but we don't need to. In ANI, ; is the pipe termination operator, which throws away whatever is currently in a pipe, and thus whatever comes after this is the beginning of a new pipe.

"Whoa, whoa, whoa", you might say... "when did the notion "pipes" come into play? I see no "pipes" here! What is a "pipe", anyway?"

Well, that Hello, World program above is actually a program consisting of a single pipe. To illustrate pipes better, let's write a program using several of them:

s = [string\];
\s ->std.out;
"Hello, World!" ->s;
Let's try to ignore the novel-looking syntax for a moment. This program will print the same thing as the first one, but it does it using three pipes. To a programmer coming from an imperative language, the above program might not make a whole lot of sense; we seem to be sending (->) something (\s) to std.out (like we did before), but what is this \s? Surely it's not the "Hello, World!" that's written in the following "statement"? Indeed, it is, even though it seems to appear after the place where we use it!

This shows an important difference between ANI and a lot of other languages. The reason that writing the program like this works is that pipes are not statements, and pipes have no specific ordering. In fact, the way pipes work, all of them flow at the same time. What this means for ANI programs is that if you write:

A;
B;
then A and B happen at the same time, not one after the other! Further, if a pipe isn't ready to continue just yet (in this case, the second line), then it automatically waits until the time is right to do so. The language handles all of this for you, which gives it a lot of power and makes programming much simpler, but it might require re-thinking your notion of how programs run if you're used to a strictly top-down paradigm like that of most imperative languages.

With these insights, let's look at the program above once again, this time trying to understand what exactly is going on.

Latches
The first line in out above program is a special kind of pipe called a latch pipe, which is a little like (but not the same as) a variable in other languages. How can we tell that it's a latch pipe? Because of the [string\].

Read more: Google Code

Posted via email from .NET Info

0 comments: