Pike (language)

Pike is a dynamic programming language high level interpreted generic, cross-platform with a syntax similar to C . Unlike other dynamic languages, Pike is typed both statically and dynamically, and requires explicit type definitions. It offers a flexible system of typing and a speed of development that allows dynamically typed languages, while offering some of the advantages of statically typed languages.

Pike has a garbage collector , advanced data types and anonymous functions , which allows to program according to several paradigms, at the choice of the developer: object oriented programming , functional or imperative programming . Pike is free software licensed under the GNU General Public License (GPL), the GNU General Public License (LGPL), and the Mozilla Public License (MPL).


Pike has its roots in the LPC language , a language originally designed to develop MUD . Programmers gathered within the Lysator, Linköping ‘ s Swedish university computer club , in particular Fredrik Hübinette and Per Hedbor, separated the language and the virtual machine from the rest of the MUD driver, baptizing the result obtained LPC4, and used it As a fast prototyping language for various applications.

LPC’s license prohibited the use of the language for commercial purposes, prompting developers to completely rewrite the interpreter and publish it in 1994 under a GNU General Public License under the name μLPC.

In 1996, μLPC was renamed Pike, a name deemed more commercially sold. Although its name has often changed over time, the company today known as Roxen Internet Software 1 has used many Pike developers and provided resources to support the development of Pike. Roxen is also the name of a web server developed by the company in Pike. In 2002, the University of Linköping resumed the maintenance and evolution of Pike in Roxen. Several Pike developers were then hired at Opera Software , which has offices in Linköping; Pike plays a central role in the server / gateway part of the Opera Mini 2 software .

Language Syntax

Hello World

For a discussion of the place and role of “Hello World” in programming, see the related article: Hello world .
Int main () {
 write ( "Hello world! \ N " );
 Return 0 ;

The syntax above is explained in the following way:

  • The first line announces the main function . This is the first function executed at the start of a program; Main means “principal” in English. The preceding int indicates that an integer number will be returned at the end of the function.
  • The write function sends a string to the standard output, which is often a command-line interface .
  • The third line returns a number to the caller of the function, in this case the command line interface, for which zero means by convention that the program has run without error.
  • The braces enclose the function and the semicolon separates the instructions (which implies that the function could have fit on one line int main () {write ( "Hello world! \ N"); return 0;} )
  • The \ n after the “Hello world! “Is the character symbolizing an end of line .

Data Types

The following list shows all the types accepted by Pike. More complex data types such as sequences, queues , heaps , stacks , and so on. Are available in the ADT module included with Pike.

Basic data types:

  • Integer ( int )
  • Floating ( float )
  • String ( string )

Types of assemblies:

  • array ( array )
  • Mapping
  • Multi-set ( multiset )

Other types:

  • Program ( program , the compiled representation of a class)
  • Object ( object , the instance of a class)
  • Function ( function )

Pike requires all variables to be declared explicitly. It uses this information to warn about possible type errors when interpreting the code. The code below will cause an error because the value of the variable “number” must be an integer but the code tries to assign a floating number and then a string to it.

Int number ; // variable integer, only accepts integers
number = 5.5 ; // 5.5 is a floating number, which leads to an error
number = "5" ; // "5" is a string, not the integer 5, from which error

This type of behavior is usually considered restrictive and limiting by the supporters of dynamically typed languages . However, unlike C, C ++ or Java, to name a few, Pike uses a specific typing system that allows the programmer to declare variables as possibly containing a value of different types. Most of the time impossible or dangerous in most languages ​​related to C.

The following code shows how a variable can be declared of two different types, that is, one or the other of these types can be declared during program execution.

Int | Float number ; // variable of type integer OR floating
number = 5 ; // this is valid
number = 5.5 ; // ... and this too.

Since a variable can be declared to be of more than one type, functions are provided to determine what type of data such a variable stores at a time t . These functions follow a naming convention: the name of the type attached to the letter p; So we find intp , floatp , stringp , and so on.

Int | Float number ;
Number = 5 ;
Intp ( number ); // returns true because number stores an integer
floatp ( number ); // returns false
number = 5.5 ;
Floatp ( number ); // returns true because number now stores a floating number

In addition, there is a special mixed data type . Its definition allows a variable to contain any type of data.

Mixed anything ;
Anything = 5 ; // anything is now the integer 5
anything = 5.5 ; // anything is now the float 5.5
anything = "5" ; // anything is now the string "5"

To convert a value from one type to another, Pike uses an explicit type conversion:

Mixed anything ;
Anything = ( int ) 5.5 ; // anything is now a value integer 5
anything = ( string ) anything ; // anything is now a string that is "5"

Notes and references

( In ) This article is partially or entirely from the article in English entitled ” Pike (programming language) ” ( see the list of authors ) .

  1. ↑ Official Website of Roxen Internet Software  [ archive ]
  2. ↑ ( en ) Vincent Lextrait, ” The Programming Languages ​​Beacon, v10.0 [ archive ] , (Accessed 14 March 2010 )