Pike programming language
Encyclopedia
Pike is an interpreted, general-purpose
General-purpose programming language
In computer software a general-purpose programming language is a programming language designed to be used for writing software in a wide variety of application domains...

, high-level, cross-platform
Cross-platform
In computing, cross-platform, or multi-platform, is an attribute conferred to computer software or computing methods and concepts that are implemented and inter-operate on multiple computer platforms...

, dynamic programming language
Dynamic programming language
Dynamic programming language is a term used broadly in computer science to describe a class of high-level programming languages that execute at runtime many common behaviors that other languages might perform during compilation, if at all...

, with a syntax similar to that of C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

. Unlike many other dynamic languages, Pike is both statically and dynamically typed, and requires explicit type definitions. It features a flexible type system that allows the rapid development and flexible code of dynamically typed languages, while still providing some of the benefits of a statically typed language.

Pike features garbage collection
Garbage collection (computer science)
In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program...

, advanced data types, and first-class anonymous functions, with support for many programming paradigms, including object-oriented
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...

, functional
Functional programming
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...

 and imperative programming
Imperative programming
In computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state...

. Pike is free software
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

, released under the GPL
GNU General Public License
The GNU General Public License is the most widely used free software license, originally written by Richard Stallman for the GNU Project....

, LGPL and MPL
Mozilla Public License
The Mozilla Public License is a free and open source software license. Version 1.0 was developed by Mitchell Baker when she worked as a lawyer at Netscape Communications Corporation and version 1.1 at the Mozilla Foundation...

 licenses.

History

Pike has its roots in LPC, which was a language developed for MUD
MUD
A MUD , pronounced , is a multiplayer real-time virtual world, with the term usually referring to text-based instances of these. MUDs combine elements of role-playing games, hack and slash, player versus player, interactive fiction, and online chat...

s. Programmers at Lysator
Lysator
Lysator is an academic computer club at Linköping University, Sweden with almost 600 members. It is an independent non-profit society, separate from the students' union and the faculties of the university.- History :...

 in Linköping
Linköping
Linköping is a city in southern middle Sweden, with 104 232 inhabitants in 2010. It is the seat of Linköping Municipality with 146 736 inhabitants and the capital of Östergötland County...

, Sweden, most notably Fredrik Hübinette and Per Hedbor, separated the language and virtual machine from the rest of the MUD driver, and used it as a rapid prototyping language for various applications, calling it LPC4.

LPC's license did not allow use for commercial purposes, and so a new GPL implementation was written in 1994, called µLPC (micro LPC).

In 1996, µLPC was renamed to Pike in order to provide a more commercially viable name. Although the name of the company has changed over the years, the company now known as Roxen Internet Software employed many Pike developers, and provided resources for Pike's development. Roxen
Roxen (web server)
Roxen is a free software web server produced by Roxen Internet Software, a company based in Linköping, Sweden and named after the nearby lake Roxen. It is released under the GNU General Public License. Roxen originally appeared as Spinner in the mid-1990s and was written in a C-like language called...

 is also the name of a web server developed by the company in Pike. In 2002, the programming environment laboratory at Linköping University
Linköping University
Linköping University is a state university in Linköping, Sweden. Linköping University was granted full university status in 1975 and is now one of Sweden's larger academic institutions. Education, research and PhD training are the mission of four faculties: Arts and Sciences, Educational...

 took over maintenance of Pike from Roxen. Several Pike programmers have found their way to the Linköping office of Opera Software
Opera Software
Opera Software ASA is a Norwegian software company, primarily known for its Opera family of web browsers with over 220 million users worldwide. Opera Software is also involved in promoting Web standards through participation in the W3C. The company has its headquarters in Oslo, Norway and is...

, where the language plays a central role in the server/gateway parts of the Opera Mini
Opera Mini
Opera Mini is a web browser designed primarily for mobile phones, smartphones and personal digital assistants. Until version 4 it used the Java ME platform, requiring the mobile device to run Java ME applications. From version 5 it is also available as a native application for Android, iOS, Symbian...

 application.

Hello World

For an explanation of the tradition of programming "Hello World", see Hello world program
Hello world program
A "Hello world" program is a computer program that outputs "Hello world" on a display device. Because it is typically one of the simplest programs possible in most programming languages, it is by tradition often used to illustrate to beginners the most basic syntax of a programming language, or to...

.


int main {
write("Hello world!\n");
return 0;
}

The syntax above requires some explanation. Those who are familiar with C or C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

 should pick it up right away.
  • The first line contains the main function. This is the first function executed when a program starts. The "int" in front of it tells that a number of type Integer
    Integer
    The integers are formed by the natural numbers together with the negatives of the non-zero natural numbers .They are known as Positive and Negative Integers respectively...

     will be returned when the function ends.
  • The write function sends a string literal
    String literal
    A string literal is the representation of a string value within the source code of a computer program. There are numerous alternate notations for specifying string literals, and the exact notation depends on the individual programming language in question...

     to the standard output buffer, which in most cases is a command line interface.
  • The third line returns a number to the caller of a function, in this case the command line interface where zero usually means the program executed without error.
  • The curly brackets enclose the function and the semicolon separates statements (meaning the function could have been written on a single line: int main{write("Hello world!\n");return 0;})
  • The "\n" after "Hello world!" is a newline
    Newline
    In computing, a newline, also known as a line break or end-of-line marker, is a special character or sequence of characters signifying the end of a line of text. The name comes from the fact that the next character after the newline will appear on a new line—that is, on the next line below the...

     character.

Data types

The following list shows all the standard data types that Pike provides. Advanced data types such as sequences, queues, heaps, stacks, etc. are available in the ADT module which is included with Pike.

Basic data types:
  • int
  • float
  • string


Container types:
  • array
  • mapping
  • multiset
    Multiset
    In mathematics, the notion of multiset is a generalization of the notion of set in which members are allowed to appear more than once...



Other types:
  • program (the compiled representation of a class)
  • object (an instance of a class)
  • function


Pike requires explicit type definitions for all variables. It uses this information to report type errors at compile time. The following code will cause a compile error because the value of the variable "number" must be an integer but the code is attempting to assign floating point and string values to it.

int number; // integer variable, it only accepts integers
number = 5.5; // 5.5 is a floating point value, error
number = "5"; // "5" is a string, not the integer value 5, error

That kind of behavior is traditionally considered restrictive and limiting by proponents of dynamically typed languages. However unlike C, C++, and Java, Pike uses a more flexible type system—specifically, a system of tagged union
Tagged union
In computer science, a tagged union, also called a variant, variant record, discriminated union, or disjoint union, is a data structure used to hold a value that could take on several different, but fixed types. Only one of the types can be in use at any one time, and a tag field explicitly...

s. The system allows programmers to declare variables that may contain values of multiple types, something impossible in most of the C-family languages without straying from the bounds of safe usage.

The following demonstrates a variable that can hold either an integer or a floating point number.

int|float number; // integer OR float variable
number = 5; // this is legal
number = 5.5; // this is legal also

Because a variable can be declared as holding many different data types, functions are provided to determine what type of data is currently stored. These functions are all of the form typenamep, as in intp, floatp, stringp, etc.

int|float number;
number = 5;
intp(number); // returns true because number holds an int
floatp(number); // returns false
number = 5.5;
floatp(number); // returns true because number now holds a float

Additionally, there is a special "mixed" data type. That definition allows a variable to hold any kind of data type.

mixed anything;
anything = 5; // anything is now the integer value 5
anything = 5.5; // anything is now the float value 5.5
anything = "5"; // anything is now the string value "5"

In order to convert a value from one type to another, Pike can use an explicit cast:

mixed anything;
anything = (int)5.5; // anything is now the integer value 5
anything = (string)anything; // anything is now the string value "5"

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK