Pike (programming language): Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Phil Howard
(Remove infobox)
imported>Phil Howard
(Various editorial cleanups and remove non-English references)
Line 1: Line 1:
'''Pike''' is an [[Interpreter (computer software)|interpreted]], [[General-purpose programming language|general-purpose]], [[High level programming language|high-level]], [[cross-platform]], [[dynamic programming language]], with a syntax similar to that of [[C (programming language)|C]].  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''' is an [[Interpreter (computer software)|interpreted]], [[General-purpose programming language|general-purpose]], [[High level programming language|high-level]], [[cross-platform]], [[dynamic programming language]], with a syntax similar to that of [[C (programming language)|C]].  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 (computer science)|garbage collection]], advanced data types, and first-class anonymous functions, and supports many programming paradigms, including [[object-oriented programming|object-oriented]], [[functional programming|functional]] and [[imperative programming]]. Pike is [[free software]], released under the [[GNU General Public License|GPL]], [[LGPL]] and [[Mozilla Public License|MPL]] licenses.
Pike features [[garbage collection (computer science)|garbage collection]], advanced data types, and first-class anonymous functions. It supports many programming paradigms, including [[object-oriented programming|object-oriented]], [[functional programming|functional]] and [[imperative programming]]. Pike is [[free software]], released under the [[GNU General Public License|GPL]], [[LGPL]] and [[Mozilla Public License|MPL]] licenses.


== History ==
== History ==
Pike has its roots in [[LPC programming language|LPC]], which was a language developed for [[MUD]]s. Programmers at [[Lysator]] in Linköping, 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. 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.  In 2002, the programming environment laboratory at [[Linköping University]] took over maintenance of Pike from Roxen. Several Pike programmers have found their way to the Linköping office of [[Opera Software]], where the language plays a central role in the server/gateway parts of the [[Opera Mini]] application.
Pike has its roots in [[LPC programming language|LPC]], a language developed for [[MUD]]s. Programmers at [[Lysator]] in Linköping, 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. 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.  In 2002, the programming environment laboratory at [[Linköping University]] took over maintenance of Pike from Roxen. Several Pike programmers have found their way to the Linköping office of [[Opera Software]], where the language plays a central role in the server/gateway parts of the [[Opera Mini]] application.


== Syntax highlights ==
== Syntax highlights ==
Line 16: Line 16:
The syntax above requires some explanations for some.  Those who are familiar with [[C programing language|C]] or [[C++]] should pick it up right away.
The syntax above requires some explanations for some.  Those who are familiar with [[C programing language|C]] or [[C++]] should pick it up right away.


* The first line contains the [[main function]], that line tells the interpreter where to start executing program commands
* The first line contains the [[main function]]. That line tells the interpreter where to start executing program commands.
* The write function sends a [[string literal]] to the standard output buffer, which in most cases is a [[command line interface]]
* The write function sends a [[string literal]] to the standard output buffer, which in most cases is a [[command line interface]].
* The third line tells the program in what state the main function exited
* The third line returns a status of zero, indicating that the main function completed without an error.
* The last line lets the interpreter know that it has reached the end of the main [[function (programming)|function]]
* The last line lets the interpreter know that it has reached the end of the main [[function (programming)|function]].


=== Data types ===
=== Data types ===
Line 39: Line 39:
* function
* function


Pike requires explicit type definitions for all variables. Being a statically typed language, it uses this information to report type errors at compile time.  In the following example, a compile time error is produced.  The message indicates that the variable, "MyNumber", is mistakenly being used in the assignment of incorrect data types (floating point value and string values).
Pike requires explicit type definitions for all variables. Being a statically typed language, it uses this information to report type errors at compile time.  In the following example, a compile time error is produced.


  int number;    // integer variable, it only accepts integers
  int number;    // integer variable, it only accepts integers
Line 45: Line 45:
  number = "5";  // "5" is a string, not the integer value 5, error
  number = "5";  // "5" is a string, not the integer value 5, error


That kind of behaviour is traditionally considered restrictive and limiting by proponents of dynamically typed language.  However unlike C, C++, and Java, Pike uses a more flexible type system.  The system allows programmers to declare variables that may contain values of multiple types.  The following demonstrates a variable that can hold either an integer or a floating point number.
This kind of behaviour is traditionally considered restrictive and limiting by proponents of dynamically typed language.  Unlike C, C++, and Java, Pike uses a more flexible type system which allows programmers to declare variables that may contain values of multiple types.  The following demonstrates a variable that can hold either an integer or a floating point number.


  int|float number; // integer OR float variable
  int|float number; // integer OR float variable
Line 51: Line 51:
  number = 5.5;    // this is legal also
  number = 5.5;    // this is legal also


Because a variable can be declared has holding many different data types, functions are provided to determine what type of data is currently stored.  These functions are all typenamep, as in intp, floatp, stringp, etc.
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 typenamep, as in intp, floatp, stringp, etc.


  int|float number;
  int|float number;
Line 83: Line 83:
[[Category:Scripting languages]]
[[Category:Scripting languages]]
[[Category:Free compilers and interpreters]]
[[Category:Free compilers and interpreters]]
[[ca:Pike]]
[[de:Pike (Programmiersprache)]]
[[id:Pike]]
[[pl:Pike]]
[[ru:Pike]]
[[sv:Pike]]
[[zh:Pike]]

Revision as of 22:50, 23 February 2007

Pike is an interpreted, general-purpose, high-level, cross-platform, dynamic programming language, with a syntax similar to that of C. 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, advanced data types, and first-class anonymous functions. It supports many programming paradigms, including object-oriented, functional and imperative programming. Pike is free software, released under the GPL, LGPL and MPL licenses.

History

Pike has its roots in LPC, a language developed for MUDs. Programmers at Lysator in Linköping, 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. 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. In 2002, the programming environment laboratory at Linköping University took over maintenance of Pike from Roxen. Several Pike programmers have found their way to the Linköping office of Opera Software, where the language plays a central role in the server/gateway parts of the Opera Mini application.

Syntax highlights

Hello World

For an explanation of the tradition of programming "Hello World", see Hello world program.
int main() {
    write("Hello world!\n");
    return 0;
}

The syntax above requires some explanations for some. Those who are familiar with C or C++ should pick it up right away.

  • The first line contains the main function. That line tells the interpreter where to start executing program commands.
  • The write function sends a string literal to the standard output buffer, which in most cases is a command line interface.
  • The third line returns a status of zero, indicating that the main function completed without an error.
  • The last line lets the interpreter know that it has reached the end of the main function.

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

Other types:

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

Pike requires explicit type definitions for all variables. Being a statically typed language, it uses this information to report type errors at compile time. In the following example, a compile time error is produced.

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

This kind of behaviour is traditionally considered restrictive and limiting by proponents of dynamically typed language. Unlike C, C++, and Java, Pike uses a more flexible type system which allows programmers to declare variables that may contain values of multiple types. 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 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;    // number is now the integer value 5
anything = 5.5;  // number is now the float value 5.5
anything = "5";  // number 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;         // number is now the integer value 5
anything = (string)anything; // number is now the string value "5"

External links