Getting Started

Panini's Goals

A central goal of capsule-oriented programming and the Panini language is to help programmers deal with the challenges of concurrent program design.

The value proposition of the programming paradigm and the programming language is to enable greater program modularity and in doing so automatically enable greater program concurrency. In fact, Panini does not use explicit concurrency features. Instead, the programmer modularizes a program using capsules, which implicitly specify boundaries outside of which concurrency can occur. The Panini runtime will automatically enable concurrency in between the boundaries of capsules when safe to do so.

Hello World!

A Panini program is a collection of zero or more capsules. For example, a simple "hello world" program in Panini can be written as follows:

capsule HelloWorld {
  void run(){
    System.out.println("Panini: Hello World!");
    long time = System.currentTimeMillis();
    System.out.println("Time is now: " + time);    
  }
}

This program has a capsule called Greeter. The capsule Greeter contains only one procedure, run, which does a simple print. The name run has special meaning within capsules, but for now do not worry about it.

This is a complete Panini program that can be compiled and run from the command-line. See below for more on that.

Decomposing a Program into Capsules

For illustration, we can decompose this program into two parts: a Greeter capsule that knows about the method of proper greeting, e.g. "Hello" in English, "Namaste" in Hindi, and a Console capsule that knows about the medium that will be used to convey the greeting, e.g. standard output, a file.

capsule Console () {
  void write(String s) { System.out.println(s); }
}

capsule Greeter (Console c){
  void run(){
    c.write("Panini: Hello World, Decomposed!"); 
    long time = System.currentTimeMillis();
    c.write("Time is now: " + time);    
  }
}

capsule HelloWorld {
 design {
  Console c; Greeter g;
  g(c);
 }
}

The Greeter capsule definition now contains a specification of what other capsules it requires. On line 5, it says that a Greeter requires a Console to work properly.

Once a capsule definition declares such requirements, procedures of the required capsules can be called. For example, one procedure of the Console capsule is write. This procedure is called on lines 7 and 9 in the Greeter capsule.

As you might notice the Console capsule does not have a run procedure, but the Greeter does. The run procedure is optional and signals that the capsule can start computation without external stimuli (i.e. if said capsule is instantiated in a program, then the run procedure of that capsule will be executed as soon as program initialization finishes).

On lines 14-17, this program has a design declaration, a new feature in Panini. The design declaration on lines 14-17 simply states that the topology of our program consists of one instance of the Greeter capsule g, one instance of the Console capsule c on line 15. On line 16, the design declaration states that the greeter instance is connected to the capsule instance.

Implicit Concurrency in Capsule-oriented Programs

As mentioned previously, Panini does not use explicit concurrency features. Instead, the programmer modularizes a program using capsules, which implicitly specify boundaries outside of which concurrency can occur. The Panini runtime will automatically enable concurrency in between the boundaries of capsules when safe to do so.

When a procedure is called on an external capsule, e.g. call to write procedure on line 7, and if it is safe to do so, the call immediately returns allowing the caller capsule and the callee capsule to work independently. Here, the Greeter capsule can immediately continue to obtain the current system time, while the Console capsule prints first line of the greeting.

This is the main benefit of capsule-oriented programming and the Panini language. Implicit concurrency is achieved without having to introduce explicit concurrency features like threads, task pools, etc. This simplifies programming tasks. Not having to worry about concurrency is the main promise of capsule-oriented programming.

Compiling and running Hello World!

If you haven't installed the Panini compiler yet then please go to section on installing and running the compiler.

Copy or download either versions of the Hello World program and save it, say, to the file paniniHelloWorld.java. To compile the program simply run:

panc paniniHelloWorld.java

And then you can run the panini program with:

panini HelloWorld

Where HelloWorld is the name of the capsule that you wish to run.

Now that you've written your first Panini program it is time to familiarize yourself with more complex features of the language. Please continue to the section on language semantics.

Page last modified on $Date: 2013/08/03 14:04:23 $