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 statically 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 the benefits of a statically typed language. Pike features garbage collection, advanced data types, and first-class anonymous functions, and supports many programming paradigms, including object-oriented, functional, aspect-oriented and imperative programming. Pike is free software, released under the GPL, LGPL and MPL licenses.
int main() { write("Hello world!"); return 0; }
The syntax above requires some explanations for some. Those who are familiar with C or C++ should pick it up right away.
Basic data types:
Container types:
Reference types:
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).
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 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.
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 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.
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"
Programming languages | Curly bracket programming languages | Object-oriented programming languages | Class-based programming languages | Scripting languages
Pike | Pike (Programmiersprache) | Pike | Pike | Pike | Pike | Pike
This article is licensed under the GNU Free Documentation License.
It uses material from the
"Pike programming language".
Home Page • arts • business • computers • games • health • hospitals • home • kids & teens • news • physicians • recreation• reference • regional • science • shopping • society • sports • world