Pico programming language

From ArticleWorld


Pico is a high-level programming language designed for beginners at the Vrije Universiteit in Brussels. It was heavily influenced by Structure and Implementation of Computer Programs, a book written by Abelson and Sussman. It is an adaptation of Scheme's syntax and semantics, meant to be as elegant and expressive as possible. Various implementations exist, for Unix, Unix-like systems and Windows.

The language

The simplest statement in the Pico language is the comment, surrounded by backquotes.

"like this"

Pico supports four data types: string, integer, real and table, with support for dynamic typing. Although there is not support for a native char type, 1-character strings can be used instead. It is a completely object-oriented language, supporting functions as first-class objects.

Examples

The QuickSort implementation in Pico is short and mostly self-explaining, as the functions are defined in a manner quite similar to elementary calculus:

QuickSort(V,Low,High)::
     begin(Left:Low,
           Right:High,
           Pivot:V[(Left+Right)//2],
           until(Left>Right,
             begin(while(V[Left]&ltPivot,Left:=Left+1),
                   while(V[Right]>Pivot,Right:=Right-1),
                   if(not(Left>Right),
                      begin(Save:V[Left],
                            V[Left]:=V[Right],
                            V[Right]:=Save,
                            Left:=Left+1,
                            Right:=Right-1),
                      false))),
           if(Low<Right,QuickSort(V,Low,Right),false),
           if(High>Left,QuickSort(V,Left,High),false))

An implementation of the insertion sort is equally simple:

{ insertionsort(t,l << r)::{
    for(k:size(t), k> 0, k:=k-1, {
      j:k+1;
      save:t[k];
      while((j<size(t)+1) & (t[j]<<save) , {
        t[j-1]:=t[j];
        j:=j+1 });
      t[j-1]:=save });
    t };
}