The XP language's type system

at 2010-10-10 in Language by friebe (0 comments)

As promised in the first article of our XP language series, we will have a look at the type system. The XP language knows about the following types:

  • Primitives - The following primitives exist: int, float, string and bool
  • Reference types - Classes, interfaces and enums, e.g. lang.Object, util.log.Traceable and util.DateInterval
  • Arrays - An array is a zero-based and continuously numbered list of any type, e.g. string[] or util.Date[].
  • Maps - A map is a hashtable mapping string keys to any type, e.g. [:string] or [:lang.XPClass]
  • The variable type - Marks a type that may either be a primitive or any reference type, declared with the keyword "var". The compiler will not be able to verify type correctness in this case and will warn about this - checks will be deferred until runtime.
Member variables, method parameters and return types need to be typed, while local variables don't - their type will be inferred on initialization.


Example

  public class Person {
public string $name; // Member variable

public void setName(string $name) { // Method parameter
$this.name= $name;
}

public string getName() { // Return type
return $this.name;
}

public string toString() {
$s= $this.getClassName(); // Type inference, typeof($s) = string
$s~= '(' ~ $this.name ~ ')';
return $s;
}
}
As you can see, a method not returning any value is decorated with the void type, which may be used only in this place.



Subscribe

You can subscribe to the XP framework's news by using RSS syndication.


Categories

News
General
PHP5
Announcements
RFCs
Further reading
Examples
Editorial
EASC
Experiments
Unittests
Databases
5.8-SERIES
Unicode
Language
5.9-SERIES

Related

Find related articles by a search for «The».