Update page 'Aer v1.0 Specification'
@@ -1,22 +1,22 @@
|
||||
## 1. Introduction
|
||||
The P# language specification is the definitive source for P# syntax and usage. This specification contains detailed information about all aspects of the language.
|
||||
The __AerScript__ language specification is the definitive source for __Aer__ syntax and usage. This specification contains detailed information about all aspects of the language.
|
||||
|
||||
As the definition of P# evolved, the goals used in its design are as follows:
|
||||
* P# is intended to be a simple, modern, general-purpose, object-oriented scripting language.
|
||||
As the definition of Aer evolved, the goals used in its design are as follows:
|
||||
* Aer is intended to be a simple, modern, general-purpose, object-oriented scripting language.
|
||||
* The language, and implementations thereof, should provide support for software engineering
|
||||
principles such as strong type checking, detection of attempts to use uninitialized variables, and automatic garbage collection.
|
||||
* The language is intended for use in developing web sites and and scripts< suitable for deployment in any, including embedded environments.
|
||||
* P# is intended to be suitable also for writing scripts for embedded systems.
|
||||
* Aer is intended to be suitable also for writing scripts for embedded systems.
|
||||
* Source code portability is very important, especially for those programmers already familiar with PHP and/or C++.
|
||||
|
||||
## 2. Scope
|
||||
This specification describes the form and establishes the interpretation of programs written in the P# scripting language. It describes:
|
||||
* The representation of P# programs;
|
||||
* The syntax and constraints of the P# language;
|
||||
* The semantic rules for interpreting P# programs;
|
||||
This specification describes the form and establishes the interpretation of programs written in the Aer scripting language. It describes:
|
||||
* The representation of Aer programs;
|
||||
* The syntax and constraints of the Aer language;
|
||||
* The semantic rules for interpreting Aer programs;
|
||||
|
||||
## 3. Lexical structure
|
||||
A P# script consists of one or more source files. A source file is an ordered sequence of UTF-8 characters, what means that any UTF-8 encoded natural language (i.e: Japanese, Chinese, Arabic, etc.) can be used for writing scripts. Source files typically have a one-to-one correspondence with files in a file system.
|
||||
A Aer script consists of one or more source files. A source file is an ordered sequence of UTF-8 characters, what means that any UTF-8 encoded natural language (i.e: Japanese, Chinese, Arabic, etc.) can be used for writing scripts. Source files typically have a one-to-one correspondence with files in a file system.
|
||||
|
||||
### 3.1. Comments
|
||||
Two forms of comments are supported: delimited comments and single-line comments. A delimited comment begins with the characters /* and ends with the characters */. Delimited comments can occupy a portion of a line, a single line, or multiple lines. A single-line comment begins with the character # or characters // and extends to the end of the line.
|
||||
@@ -29,13 +29,13 @@ Example:
|
||||
multi-line comment block */
|
||||
|
||||
### 3.2. White space
|
||||
White space is defined as any character with Unicode class Zs (which includes the space character) as well as the horizontal tab character, the vertical tab character, and the form feed character. White space in P# is used to separate tokens in P# source file. It is used to improve the readability of the source code. The amount of space put between tokens is irrelevant for the P# interpreter. It is based on the preferences and the style of a programmer. Two statements can be put into one line, as well as one statement into several lines. Source code should be readable for humans and makes no difference to the Interpreter.
|
||||
White space is defined as any character with Unicode class Zs (which includes the space character) as well as the horizontal tab character, the vertical tab character, and the form feed character. White space in Aer is used to separate tokens in Aer source file. It is used to improve the readability of the source code. The amount of space put between tokens is irrelevant for the Aer interpreter. It is based on the preferences and the style of a programmer. Two statements can be put into one line, as well as one statement into several lines. Source code should be readable for humans and makes no difference to the Interpreter.
|
||||
|
||||
### 3.3. Tokens
|
||||
There are several kinds of tokens: identifiers, keywords, literals, operators, and punctuators. White space and comments are not tokens, though they act as separators for tokens.
|
||||
|
||||
#### 3.3.1 Literals
|
||||
A literal is any notation for representing a value within the PHP source code. Technically, a literal is assigned a value at compile time, while a variable is assigned at runtime. P# supports:
|
||||
A literal is any notation for representing a value within the PHP source code. Technically, a literal is assigned a value at compile time, while a variable is assigned at runtime. Aer supports:
|
||||
* boolean literal (can be true or false),
|
||||
* integer literal (can be decimal and hexadecimal),
|
||||
* real literal (used to write values of float type),
|
||||
@@ -55,24 +55,24 @@ There are several kinds of operators and punctuators. Operators are used in expr
|
||||
? =>
|
||||
|
||||
#### 3.3.3 Keywords
|
||||
A keyword is a reserved word in the P# language. Keywords are used to perform a specific task in a computer program; for example, print a value, do repetitive tasks, or perform logical operations. A programmer cannot use a keyword as an ordinary variable.
|
||||
A keyword is a reserved word in the Aer language. Keywords are used to perform a specific task in a computer program; for example, print a value, do repetitive tasks, or perform logical operations. A programmer cannot use a keyword as an ordinary variable.
|
||||
|
||||
Available keywords: as, break, case, catch, class, clone, const, continue, default, do, else, elseif, extends, final, for, foreach, if, implements, interface, instanceof, namespace, new, private, protected, public, static, switch, throw, try, using, virtual, while
|
||||
|
||||
Next we have other language constructs: define() empty(), exit(), eval(), include(), include_once(), isset(), list(), require(), require_once(), return(), print(), unset()
|
||||
|
||||
#### 3.3.4 Semicolon
|
||||
A semicolon is used to mark the end of a statement in P# language. It is mandatory.
|
||||
A semicolon is used to mark the end of a statement in Aer language. It is mandatory.
|
||||
|
||||
#### 3.3.5 P# Variables
|
||||
A variable is an identifier, which holds a value. In programming we say that we assign a value to a variable. Technically speaking, a variable is a reference to a computer memory, where the value is stored. In P# language, a variable can hold a string, a number, or various objects like a function or a class. Variables can be assigned different values over time. Variables in P# consist of the $ character, called a sigil, and a label. A label can be created from alphanumeric characters and an underscore _ character. A variable cannot begin with a number.
|
||||
#### 3.3.5 Aer Variables
|
||||
A variable is an identifier, which holds a value. In programming we say that we assign a value to a variable. Technically speaking, a variable is a reference to a computer memory, where the value is stored. In Aer language, a variable can hold a string, a number, or various objects like a function or a class. Variables can be assigned different values over time. Variables in Aer consist of the $ character, called a sigil, and a label. A label can be created from alphanumeric characters and an underscore _ character. A variable cannot begin with a number.
|
||||
|
||||
#### 3.3.6 P# Constants
|
||||
#### 3.3.6 Aer Constants
|
||||
A constant is an identifier for a value which cannot change during the execution of the script. Constants are created with the define() function. Constants differ from variables; is is impossible to assign a different value to an existing constant.
|
||||
|
||||
## 4. Basic concept
|
||||
### 4.1. Script startup
|
||||
P# is an interpreted language, thus a program or script does not have to be compiled as an application that may be started. An interpreted program shall contain exactly one method qualifying as an entry point by satisfying the following requirements:
|
||||
Aer is an interpreted language, thus a program or script does not have to be compiled as an application that may be started. An interpreted program shall contain exactly one method qualifying as an entry point by satisfying the following requirements:
|
||||
* It has to be a constructor of class named *Main*,
|
||||
* The return type shall be void or int,
|
||||
* It shall not be a partial method without an implementation,
|
||||
@@ -82,23 +82,23 @@ P# is an interpreted language, thus a program or script does not have to be comp
|
||||
If the return type of the script's entry point method is int, the value returned serves as the scripts's termination status code. The purpose of this code is to allow communication of success or failure to the execution environment. If the return type of the entry point method is void, reaching the right brace (}) that terminates that method, or executing a return statement that has no expression, results in a termination status code of 0.
|
||||
|
||||
### 4.3. Console Output
|
||||
Output from P# scripts is sent to the console is CLI SAPI is being used. If same script is launched when using CGI or FastCGI SAPIs, the output will be sent to the browser.
|
||||
Output from Aer scripts is sent to the console is CLI SAPI is being used. If same script is launched when using CGI or FastCGI SAPIs, the output will be sent to the browser.
|
||||
|
||||
print('Hello world from P#');
|
||||
print('Hello world from Aer');
|
||||
|
||||
The print keyword does not add a new line to the output, script author has to put it manually.
|
||||
|
||||
### 4.4. Command-line Arguments
|
||||
P# scripts can receive command line arguments. They follow the name of the program. To access them, the main class constructor has to take a string[] argument. It is an array holding all arguments of a script to provide the program some values at the moment of execution. To check the number of parameters passed, sizeof() builtin function should be used.
|
||||
Aer scripts can receive command line arguments. They follow the name of the program. To access them, the main class constructor has to take a string[] argument. It is an array holding all arguments of a script to provide the program some values at the moment of execution. To check the number of parameters passed, sizeof() builtin function should be used.
|
||||
|
||||
### 4.5. Declarations
|
||||
Declarations in a P# script define the constituent elements of the program. Type declarations are used to define classes, structs, interfaces and enums. The kinds of members permitted in a type declaration depend on the form of the type declaration. For instance, class declarations can contain declarations for constants, properties, methods, instance constructors and destructors.
|
||||
Declarations in a Aer script define the constituent elements of the program. Type declarations are used to define classes, structs, interfaces and enums. The kinds of members permitted in a type declaration depend on the form of the type declaration. For instance, class declarations can contain declarations for constants, properties, methods, instance constructors and destructors.
|
||||
A declaration defines a name in the declaration space to which the declaration belongs. It is a compile-time error to have two or more declarations that introduce members with the same name in a declaration space, except in the following cases:
|
||||
* Two or more namespace declarations with the same name are allowed in the same declaration space. Such namespace declarations are aggregated to form a single logical namespace and share a single declaration space.
|
||||
* Two or more methods with the same name but distinct signatures are allowed in the same declaration space.
|
||||
|
||||
### 4.6. P# Types
|
||||
P# provides a set of predefined types called the simple types. The simple types are identified through keywords:
|
||||
### 4.6. Aer Types
|
||||
Aer provides a set of predefined types called the simple types. The simple types are identified through keywords:
|
||||
* bool
|
||||
* callback
|
||||
* char
|
||||
@@ -119,7 +119,7 @@ Variable interpolation is replacing variables with their values inside string li
|
||||
In above example, the $age variable is replaced with the value 20 in the string enclosed by double quotes. However, this does not work if single quotes are used. In this case, no interpolation happens and no special characters are working.
|
||||
|
||||
### 4.8. Including Files
|
||||
P# code can be split in multiple files for bigger scripts. There are four statements in P#, which allows to join various P# files:
|
||||
Aer code can be split in multiple files for bigger scripts. There are four statements in Aer, which allows to join various Aer files:
|
||||
* include
|
||||
* include_once
|
||||
* require
|
||||
@@ -129,17 +129,17 @@ All of above listed builtin functions can be used from any place, even outside o
|
||||
|
||||
## 5. Data Types & Pseudo Types
|
||||
### 5.1. Boolean Values
|
||||
The bool type represents Boolean logical quantities. The possible values of type bool are TRUE and FALSE. In P#, a zero integral or floating-point value, or a null pointer can be converted to the Boolean value FALSE, and a non-zero integral or floating-point value, or a non-null pointer can be converted to the Boolean value TRUE.
|
||||
The bool type represents Boolean logical quantities. The possible values of type bool are TRUE and FALSE. In Aer, a zero integral or floating-point value, or a null pointer can be converted to the Boolean value FALSE, and a non-zero integral or floating-point value, or a non-null pointer can be converted to the Boolean value TRUE.
|
||||
|
||||
### 5.2. Callback Values
|
||||
Callbacks can be denoted in P# language by callback type hint. This pseudo-type is used mostly for anonymous functions.
|
||||
Callbacks can be denoted in Aer language by callback type hint. This pseudo-type is used mostly for anonymous functions.
|
||||
|
||||
callback $callme = int() {
|
||||
return 7;
|
||||
}
|
||||
int $var = $callme(); // value is 7
|
||||
|
||||
What is more, P# allows a language constructs in the context of a function call:
|
||||
What is more, Aer allows a language constructs in the context of a function call:
|
||||
|
||||
callback $echo = 'print';
|
||||
$echo('Hello world'); // Calls the print function on the fly
|
||||
@@ -148,10 +148,10 @@ What is more, P# allows a language constructs in the context of a function call:
|
||||
The char type holds a single character. The first 128 code points (0–127) of Unicode correspond to the letters and symbols on a standard U.S. keyboard. These first 128 code points are the same as those the ASCII character set defines. The second 128 code points (128–255) represent special characters, such as Latin-based alphabet letters, accents, currency symbols, and fractions.
|
||||
|
||||
### 5.4. Floating-point Values
|
||||
P#supports one floating-point type. The float type is represented using the 64-bit double-precision. It can represent values ranging from approximately 5.0 × 10−324 to 1.7 × 10308 with a precision of 15–16 digits.
|
||||
Aer supports one floating-point type. The float type is represented using the 64-bit double-precision. It can represent values ranging from approximately 5.0 × 10−324 to 1.7 × 10308 with a precision of 15–16 digits.
|
||||
|
||||
### 5.5. Integer Values
|
||||
P# have standardized integers, which are stored in 8 bytes (64 bits) regardless of the host environment. Because there is no cross-platform way to specify 64-bit integer types P# includes typedefs for 64-bit signed integers. In P#, the int type can store integer values between -9223372036854775808 and +9223372036854775807 inclusive.
|
||||
Aer have standardized integers, which are stored in 8 bytes (64 bits) regardless of the host environment. Because there is no cross-platform way to specify 64-bit integer types Aer includes typedefs for 64-bit signed integers. In Aer, the int type can store integer values between -9223372036854775808 and +9223372036854775807 inclusive.
|
||||
|
||||
### 5.6. Mixed Values
|
||||
Mixed pseudo-type indicates that a variable might accept multiple (but not necessarily all) types. It is not a primitive, and thus it cannot be used as typehints.
|
||||
@@ -175,7 +175,7 @@ A resource is a special variable, holding a reference to an external resource, l
|
||||
|
||||
### 5.9. String Values
|
||||
A string is series of characters. The simplest way to specify a string is to enclose it in single quotes. To specify a literal single quote, escape it with a backslash. To specify a literal backslash, double it. All other instances of backslash will be treated as a literal backslash: this means that the other escape sequences you might be used to, such as \r or \n, will be output literally as specified rather than having any special meaning.
|
||||
If the string is enclosed in double-quotes, P# will interpret the following escape sequences for special characters:
|
||||
If the string is enclosed in double-quotes, Aer will interpret the following escape sequences for special characters:
|
||||
* \' - single quote
|
||||
* \" - double quote
|
||||
* \\ - backslash
|
||||
@@ -198,13 +198,13 @@ When a string is specified in double quotes, variables are also parsed within it
|
||||
Void is an empty data type and it is used as a return type of functions and methods that return no value. It is possible to declare a variable of void type, but it cannot store any value.
|
||||
|
||||
### 5.11. Null Values
|
||||
Null is a special data type. Basically, the data type means non existent, not known or empty. In P#, a variable is NULL in three cases:
|
||||
Null is a special data type. Basically, the data type means non existent, not known or empty. In Aer, a variable is NULL in three cases:
|
||||
* it was not assigned a value
|
||||
* it was assigned a special NULL constant
|
||||
* it was unset with the unset() function
|
||||
|
||||
### 5.12. Arrays
|
||||
Array is a complex data type which handles a collection of elements. Each of the elements can be accessed by an index. In P#, just like in PHP, arrays are more complex. An array in P# is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more.
|
||||
Array is a complex data type which handles a collection of elements. Each of the elements can be accessed by an index. In Aer, just like in PHP, arrays are more complex. An array in Aer is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more.
|
||||
|
||||
int $arr1[];
|
||||
int $arr2[] = {0, 0}
|
||||
@@ -233,7 +233,7 @@ Above example will create a multi-dimensional associative array containing integ
|
||||
}
|
||||
|
||||
### 5.13. Type Casting
|
||||
Type casting in P# works much as it does in C/C++ - the name of the desired type is written in parentheses before the variable which is to be cast:
|
||||
Type casting in Aer works much as it does in C/C++ - the name of the desired type is written in parentheses before the variable which is to be cast:
|
||||
* (bool) - casts to Boolean
|
||||
* (float) casts to Float
|
||||
* (int) - casts to Integer
|
||||
@@ -247,10 +247,10 @@ An example:
|
||||
int $integer = 7 + (int) $str; // contains value: 52
|
||||
|
||||
### 5.14. References
|
||||
References in P# are a means to access the same variable content by different names. They are not like C pointers; for instance, they does not allow to perform pointer arithmetic using them, they are not actual memory addresses, and so on. Instead, they are symbol table aliases. There are three basic operations performed using references: assigning by reference, passing by reference, and returning by reference.
|
||||
References in Aer are a means to access the same variable content by different names. They are not like C pointers; for instance, they does not allow to perform pointer arithmetic using them, they are not actual memory addresses, and so on. Instead, they are symbol table aliases. There are three basic operations performed using references: assigning by reference, passing by reference, and returning by reference.
|
||||
|
||||
#### 5.14.1. Assign By Reference
|
||||
In the first of these, P# references allow to make two variables refer to the same content.
|
||||
In the first of these, Aer references allow to make two variables refer to the same content.
|
||||
|
||||
int &$a, $b;
|
||||
$a = $b;
|
||||
@@ -320,12 +320,12 @@ Sometimes the precedence is not satisfactory to determine the outcome of an expr
|
||||
What is the outcome of this expression, 9 or 1? The multiplication, deletion, and the modulo operator are left to right associated. So the expression is evaluated this way: (9 / 3) * 3 and the result is 9. Arithmetic, boolean, relational, and bitwise operators are all left to right associated. On the other hand, the assignment operator is right associated.
|
||||
|
||||
### 6.3. Assignment Operator
|
||||
The assignment operator = assigns a value to a variable. A variable is a placeholder for a value. In P#, like in PHP or Perl, a variable begins with a $ character.
|
||||
The assignment operator = assigns a value to a variable. A variable is a placeholder for a value. In Aer, like in PHP or Perl, a variable begins with a $ character.
|
||||
|
||||
$x = 1;
|
||||
|
||||
### 6.4. Arithmetic Operators
|
||||
P# offers the following arithmetic operators:
|
||||
Aer offers the following arithmetic operators:
|
||||
* Addition: +
|
||||
* Subtraction: -
|
||||
* Multiplication: *
|
||||
@@ -333,15 +333,15 @@ P# offers the following arithmetic operators:
|
||||
* Modulo: %
|
||||
|
||||
### 6.5. Concatenating Strings
|
||||
In P# concatenating strings is nothing more than adding strings to each other with the addition operator.
|
||||
In Aer concatenating strings is nothing more than adding strings to each other with the addition operator.
|
||||
|
||||
string $str = "Hello" + ' ' + 'World!';
|
||||
|
||||
### 6.6. Boolean Operators
|
||||
In P#, there are and (&&), or (||), xor (^^) and negation (!) boolean operators. With boolean operators logical operations are performed. These are often used with if and while keywords.
|
||||
In Aer, there are and (&&), or (||), xor (^^) and negation (!) boolean operators. With boolean operators logical operations are performed. These are often used with if and while keywords.
|
||||
|
||||
### 6.7. Relational Operators
|
||||
Relational operators are used to compare values. These operators always result in boolean value. P# implements the following ones:
|
||||
Relational operators are used to compare values. These operators always result in boolean value. Aer implements the following ones:
|
||||
* strictly less than: <
|
||||
* less than or equal to: <=
|
||||
* strictly greater than: >
|
||||
@@ -352,7 +352,7 @@ Relational operators are used to compare values. These operators always result i
|
||||
* not identical: !==
|
||||
|
||||
### 6.8. Bitwise Operators
|
||||
Decimal numbers are natural to humans. Binary numbers are native to computers. Binary, octal, decimal or hexadecimal symbols are only notations of a number. Bitwise operators work with bits of a binary number. P# also have binary logical operators and shift operators:
|
||||
Decimal numbers are natural to humans. Binary numbers are native to computers. Binary, octal, decimal or hexadecimal symbols are only notations of a number. Bitwise operators work with bits of a binary number. Aer also have binary logical operators and shift operators:
|
||||
* bitwise negation: ~
|
||||
* bitwise exclusive or (xor): ^
|
||||
* bitwise and: &
|
||||
@@ -364,12 +364,12 @@ Decimal numbers are natural to humans. Binary numbers are native to computers. B
|
||||
The compound assignment operators consist of two operators. They are shorthand operators. The ccompound operators are: += -= *= /= %= &= |= ^= >>= <<=
|
||||
|
||||
### 6.10. Ternary Operator
|
||||
Unlike the standard PHP engine, the ternary operator under P# evaluates left-to-right, associates right-to-left. That is, there is no need for parenthesis for nested ternary operators.
|
||||
Unlike the standard PHP engine, the ternary operator under Aer evaluates left-to-right, associates right-to-left. That is, there is no need for parenthesis for nested ternary operators.
|
||||
|
||||
string $var = true ? 'true' : false? 't' : 'f';
|
||||
print($var);
|
||||
|
||||
The above expression in PHP will output 't' and this is an unexpected result, but if the same code run using the P# will output 'true' as expected.
|
||||
The above expression in PHP will output 't' and this is an unexpected result, but if the same code run using the Aer will output 'true' as expected.
|
||||
|
||||
## 7. Flow Control
|
||||
### 7.1. If Statement
|
||||
@@ -388,7 +388,7 @@ Often there is a need to execute a statement if a certain condition is met, and
|
||||
print("a is NOT greater than b");
|
||||
}
|
||||
|
||||
Additionally, P# implements known from PHP, the elseif statement. as its name suggests, is a combination of if and else. Like else, it extends an if statement to execute a different statement in case the original if expression evaluates to FALSE. However, unlike else, it will execute that alternative expression only if the elseif conditional expression evaluates to TRUE. For example, the following code would display a is bigger than b, a equal to b or a is smaller than b:
|
||||
Additionally, Aer implements known from PHP, the elseif statement. as its name suggests, is a combination of if and else. Like else, it extends an if statement to execute a different statement in case the original if expression evaluates to FALSE. However, unlike else, it will execute that alternative expression only if the elseif conditional expression evaluates to TRUE. For example, the following code would display a is bigger than b, a equal to b or a is smaller than b:
|
||||
|
||||
if ($a > $b) {
|
||||
print("a is bigger than b");
|
||||
@@ -430,7 +430,7 @@ The while loop executes the statement when the expression is evaluated to true.
|
||||
|
||||
int $i = 0;
|
||||
while ($i < 5) {
|
||||
print("P# Language\n");
|
||||
print("Aer Language\n");
|
||||
$i++;
|
||||
}
|
||||
|
||||
@@ -458,7 +458,7 @@ The for loop does the same thing as the while loop. Only it puts all three phase
|
||||
The three phases are divided by semicolons. First, the $i counter is initiated. The initiation part takes place only once. Next, the test is conducted. If the result of the test is true, the statement is executed. Finally, the counter is incremented. This is one cycle. The for loop iterates until the test expression is false.
|
||||
|
||||
### 7.6. Foreach Loop
|
||||
The foreach construct simplifies traversing over collections of data. It has no explicit counter. The foreach statement goes through the array one by one and the current value is copied to a variable defined in the construct. In P#, it can be used to traverse over an array.
|
||||
The foreach construct simplifies traversing over collections of data. It has no explicit counter. The foreach statement goes through the array one by one and the current value is copied to a variable defined in the construct. In Aer, it can be used to traverse over an array.
|
||||
|
||||
string $days[] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
|
||||
"Saturday", "Sunday" };
|
||||
@@ -477,7 +477,7 @@ There is another syntax of the foreach statement. Below form will additionally a
|
||||
print("$key is $value\n");
|
||||
}
|
||||
|
||||
Casting a $key to string in above example can be useful, because P# supports arrays with both numeric and associative indexes. This means that if above array contained additional row with integer-based key, it would be casted to string automatically.
|
||||
Casting a $key to string in above example can be useful, because Aer supports arrays with both numeric and associative indexes. This means that if above array contained additional row with integer-based key, it would be casted to string automatically.
|
||||
|
||||
### 7.7. Break & Continue Statements
|
||||
The break statement is used to terminate the loop. The continue statement is used to skip a part of the loop and continue with the next iteration of the loop.
|
||||
@@ -504,10 +504,10 @@ In above example, endless loop has been defined. There is only one way to jump o
|
||||
Above example prints a list of numbers that cannot be divided by 2 without a remainder, during a while loop, which iterates through numbers from 1 to 999.
|
||||
|
||||
## 8. Functions
|
||||
P# is fully object-oriented programming language. However, it has a support for built-in functions. The built-in functions are part of the P# language.
|
||||
Aer is fully object-oriented programming language. However, it has a support for built-in functions. The built-in functions are part of the Aer language.
|
||||
|
||||
### 8.1. Anonymous Functions
|
||||
Anonymous functions, also known as closures, allow the creation of functions which have no specified name. In P#, anonymous function arguments can take a default value exactly like standard function arguments. The default value associated with the function argument can be any complex expression including function calls.
|
||||
Anonymous functions, also known as closures, allow the creation of functions which have no specified name. In Aer, anonymous function arguments can take a default value exactly like standard function arguments. The default value associated with the function argument can be any complex expression including function calls.
|
||||
|
||||
callback $anon = void(string $msg = 'Hello' + ' ' + 'World!' /* Complex expression */){
|
||||
print($msg + PS_EOL);
|
||||
@@ -518,7 +518,7 @@ Anonymous functions, also known as closures, allow the creation of functions whi
|
||||
Anonymous function can be defined in a method body.
|
||||
|
||||
## 9. Static Variables & Constant
|
||||
P# lets use any complex expressions including method calls as an initialization values for your static variables and constants.
|
||||
Aer lets use any complex expressions including method calls as an initialization values for your static variables and constants.
|
||||
|
||||
public void test() {
|
||||
/* Random number between 0 and 1023 as the initialization value for the static variable */
|
||||
@@ -539,14 +539,14 @@ P# lets use any complex expressions including method calls as an initialization
|
||||
In above example, the static variable $salt takes as its initialization value a random number between 0 and 1023 inclusive generated by the built-in rand() function while the constant MY_CONST takes at its initialization value a random string generated by the built-in rand_str() function. Also note that the 'const' construct can be used outside a class definition.
|
||||
|
||||
## 10. Object-Oriented Programming
|
||||
There are three widely used programming paradigms there: procedural programming, functional programming, and object-oriented programming. P# supports only object-oriented programming (OOP). This is a programming paradigm that uses objects and their interactions to design applications and computer programs. The basic programming concepts in OOP are:
|
||||
There are three widely used programming paradigms there: procedural programming, functional programming, and object-oriented programming. Aer supports only object-oriented programming (OOP). This is a programming paradigm that uses objects and their interactions to design applications and computer programs. The basic programming concepts in OOP are:
|
||||
* Abstraction
|
||||
* Polymorphism
|
||||
* Encapsulation
|
||||
* Inheritance
|
||||
|
||||
### 10.1. Objects in P\#
|
||||
Objects are basic building blocks of a P# script. An object is a combination of data and methods. In a OOP program, we create objects. These objects communicate together through methods. Each object can receive messages, send messages, and process data. There are two steps in creating an object. First, a class needs to be defined. A class is a template for an object. It is a blueprint which describes the state and behavior that the objects of the class all share. A class can be used to create many objects. Objects created at runtime from a class are called instances of that particular class.
|
||||
Objects are basic building blocks of a Aer script. An object is a combination of data and methods. In a OOP program, we create objects. These objects communicate together through methods. Each object can receive messages, send messages, and process data. There are two steps in creating an object. First, a class needs to be defined. A class is a template for an object. It is a blueprint which describes the state and behavior that the objects of the class all share. A class can be used to create many objects. Objects created at runtime from a class are called instances of that particular class.
|
||||
|
||||
class Demo { }
|
||||
object $demo_object = new Demo();
|
||||
@@ -609,15 +609,15 @@ Most methods accept arguments. Arguments are values that are sent to the method.
|
||||
}
|
||||
|
||||
#### 10.3.3 Implicit Values
|
||||
The arguments in P# methods may have implicit values. An implicit value is used if no value is provided. P# lets use any complex expressions including built-in function or method calls, math or string expressions and so on as a default values for function arguments.
|
||||
The arguments in Aer methods may have implicit values. An implicit value is used if no value is provided. Aer lets use any complex expressions including built-in function or method calls, math or string expressions and so on as a default values for function arguments.
|
||||
|
||||
void test(string $name = 'P# ' + rand_str(4), int $age = 10 * 2 + 5) {
|
||||
void test(string $name = 'Aer ' + rand_str(4), int $age = 10 * 2 + 5) {
|
||||
print("Name = $name\n");
|
||||
print("Age = $age\n");
|
||||
}
|
||||
|
||||
### 10.4. Access Modifiers
|
||||
Access modifiers set the visibility of methods and member fields. P# implements three access modifiers: public, protected, and private. The public members can be accessed from anywhere. The protected members can be accessed only within the class itself and by inherited and parent classes. The private members may only be accessed by the class that defines the member. Access modifiers protect data against accidental modifications. They make the programs more robust.
|
||||
Access modifiers set the visibility of methods and member fields. Aer implements three access modifiers: public, protected, and private. The public members can be accessed from anywhere. The protected members can be accessed only within the class itself and by inherited and parent classes. The private members may only be accessed by the class that defines the member. Access modifiers protect data against accidental modifications. They make the programs more robust.
|
||||
|
||||
class DemoClass {
|
||||
public float $real;
|
||||
@@ -631,7 +631,7 @@ In the above script, there are three member fields; one is declared public, seco
|
||||
If there is no access modifier specified, public is assumed.
|
||||
|
||||
### 10.5. Method Overloading
|
||||
Method overloading allows the creation of several methods with the same name which differ from each other in the type of the input. P# implements a method overloading, well-known from languages like C#, Java or C++.
|
||||
Method overloading allows the creation of several methods with the same name which differ from each other in the type of the input. Aer implements a method overloading, well-known from languages like C#, Java or C++.
|
||||
|
||||
virtual class Test {
|
||||
virtual void function test();
|
||||
@@ -661,10 +661,10 @@ Both constructor and destructor methods cannot return any value. Declaring a con
|
||||
}
|
||||
|
||||
### 10.7. Constructor Overloading
|
||||
P# supports constructor overloading like any other method.
|
||||
Aer supports constructor overloading like any other method.
|
||||
|
||||
### 10.8. Scope Resolution Operator
|
||||
In computer programming, scope is an enclosing context where values and expressions are associated. The scope resolution operator helps to identify and specify the context to which an identifier refers, particularly by specifying a namespace. The specific uses vary across different programming languages with the notions of scoping. In P# language the scope resolution operator is written "::".
|
||||
In computer programming, scope is an enclosing context where values and expressions are associated. The scope resolution operator helps to identify and specify the context to which an identifier refers, particularly by specifying a namespace. The specific uses vary across different programming languages with the notions of scoping. In Aer language the scope resolution operator is written "::".
|
||||
|
||||
### 10.9. Inheritance
|
||||
The inheritance is a way to form new classes using classes that have already been defined. The newly formed classes are called derived classes, the classes that we derive from are called base classes. Important benefits of inheritance are code reuse and reduction of complexity of a program. The derived classes (descendants) override or extend the functionality of base classes (ancestors).
|
||||
@@ -682,7 +682,7 @@ The inheritance is a way to form new classes using classes that have already bee
|
||||
}
|
||||
}
|
||||
|
||||
In this script, there are two classes: a Base class and a Derived class. The Derived class inherits from the Base class. In P#, the extends keyword is used to create inheritance relations. In the constructor of the Derived class, we call the parent constructor. We use the parent keyword, followed by two colons and a method name. The constructors of the parent classes must be called explicitly. Output od the above example is "Hello World!'.
|
||||
In this script, there are two classes: a Base class and a Derived class. The Derived class inherits from the Base class. In Aer, the extends keyword is used to create inheritance relations. In the constructor of the Derived class, we call the parent constructor. We use the parent keyword, followed by two colons and a method name. The constructors of the parent classes must be called explicitly. Output od the above example is "Hello World!'.
|
||||
|
||||
### 10.10. Multiple inheritance
|
||||
When one class extends more than one classes then this is called multiple inheritance. For example if class Derived extends classes Base1 and Base2 then this type of inheritance is known as multiple inheritance:
|
||||
@@ -691,7 +691,7 @@ When one class extends more than one classes then this is called multiple inheri
|
||||
class Base2 {}
|
||||
class Derived extends Base1, Base2 {}
|
||||
|
||||
Multiple inheritance can lead to ambiguity. One of the example of such problem is the diamond problem that occurs in multiple inheritance. P# tries to address this problem, thus supporting multiple inheritance only partially.
|
||||
Multiple inheritance can lead to ambiguity. One of the example of such problem is the diamond problem that occurs in multiple inheritance. Aer tries to address this problem, thus supporting multiple inheritance only partially.
|
||||
|
||||
class Base1 {
|
||||
void funcA() {
|
||||
@@ -774,7 +774,7 @@ Unlike interfaces, virtual classes may have methods with full implementation and
|
||||
When the print keyword is used with the object instance, the \__toString() magic method is called.
|
||||
|
||||
### 10.13. Class Constants
|
||||
P# enables to create class constants. These constants do not belong to a concrete object. They belong to the class.
|
||||
Aer enables to create class constants. These constants do not belong to a concrete object. They belong to the class.
|
||||
|
||||
class Math {
|
||||
public const float PI = 3.14159265359;
|
||||
@@ -787,7 +787,7 @@ P# enables to create class constants. These constants do not belong to a concret
|
||||
In above example, the const keyword is used to define a constant. Class constants are accessed from within methods using the self keyword followed by two colons.
|
||||
|
||||
### 10.14. Static Keyword
|
||||
P# allows to declare class properties and methods to be static. The static properties and methods do not belong to the instance of the class. They belong to the class itself. They are accessible through the scope resolution operator.
|
||||
Aer allows to declare class properties and methods to be static. The static properties and methods do not belong to the instance of the class. They belong to the class itself. They are accessible through the scope resolution operator.
|
||||
|
||||
### 10.15. Final Keyword
|
||||
Final methods cannot be overridden and final classes cannot be extended. The final keyword is a matter of design of the application. Some classes should not be extended and some methods should not be overridden. This behaviour is enforced by the final keyword.
|
||||
Reference in New Issue
Block a user