Advertisement
GenuineSounds

NXT programming Language.

Feb 10th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.57 KB | None | 0 0
  1. /**
  2.  * Multi-line NextDocs.
  3.  */
  4.  
  5. /**
  6.  * Multi-line comments.
  7.  */
  8.  
  9. // Single line comments
  10.  
  11. /**
  12.  * Next Programming Language, NXT or NPL for short.
  13.  * Null Pointer Language for jest.
  14.  *
  15.  * Every example will include the Java equivalent.
  16.  * JE:
  17.  */
  18.  
  19. // Packages are declared using a directory structure of some 'domain'.
  20. // Packages are also required, every file must be in a domain.
  21. // No default domains are allowed.
  22. // JE: package next.lang.test;
  23. domain next/lang/test
  24.  
  25. // Imports are the same as the package declarations in style.
  26. // JE: import next.lang.test.SomeClass;
  27. use next/lang/test/SomeClass
  28.  
  29. // Keyword 'also' is used since it's easier/faster to type than implements
  30. // JE: public abstract class Person implements Biped {
  31. public abstract class Person also Biped, Talker, Singer {
  32.     // string is just a primitive keyword of object type String
  33.     string name
  34.     // Much like Go and other languages semicolons are completely optional on new lines.
  35.     // Comma separators are also optional.
  36.     int age height weight
  37.     Gender gender
  38.     // var is also just a primitive Object
  39.     // arrays are lazily initialized as: array = new Object[0];
  40.     var[] attributes
  41.  
  42.     // Types are inferred for any untyped method and constructor parameters.
  43.     // Generates: public Person(string name, int height, int weight) on compile.
  44.     // If types cannot be inferred then a compiler error is thrown must be explicitly typed.
  45.     // JE: public Person(String name, int height, int weight) {
  46.     public Person(name height weight) {
  47.         this.name = name
  48.         this.height = height
  49.         this.weight = weight
  50.         age = 32
  51.         // Natural ordering is given to unspecified index insert of an array.
  52.         attributes[] = name // Extend array by 1, Insert at index array.length - 1.
  53.         attributes[] = age // Extend array by 1, Insert at index array.length - 1.
  54.     }
  55.  
  56.     // No return type was given so this is void.
  57.     // No () is needed for empty arguments, this removes the need for unneeded typing.
  58.     // JE: public void speak() {
  59.     public speak {
  60.         System.io.println(greetings())
  61.     }
  62.  
  63.     // This is a method since it has a block and not a value
  64.     // JE: String greetings() {
  65.     string greetings {
  66.         // string concatenation will use the addition operator +
  67.         return "Hello, my name is " + name
  68.     }
  69.  
  70.     // This is a field since it has declared a value
  71.     string greetings = "Hello, my name is " + name
  72.  
  73.     // Keyword instance is used in place of protected since it's easier to type.
  74.     instance var getAttribute(index) {
  75.         return attributes[index]
  76.     }
  77.  
  78.     public doThing {
  79.         // Since more type information is known at runtime (this will be a string) it
  80.         // will be overloaded to thing(string)
  81.         // Overload to most specific type first
  82.         thing(getAttribute(0))
  83.         // Most specific type for an integer will be thing(var) at runtime.
  84.         thing(getAttribute(1))
  85.     }
  86.  
  87.     private thing(var variable) {
  88.         System.io.println(variable + ": is a " + variable.getClass())
  89.     }
  90.  
  91.     private thing(string str) {
  92.         System.io.println(str + ": is a string")
  93.     }
  94. }
  95.  
  96. // Keyword 'is' is used in place of extends since it's easier/faster to type.
  97. Man is Person {
  98.     // The default block is for lazy initialization of fields in the superclass chain.
  99.     // These are run after memory allocation, before construction.
  100.     // JE: None. But much like static block for instance variables.
  101.     default {
  102.         gender = Gender.Male
  103.     }
  104.  
  105.     // Typical override, optional @Override annotation.
  106.     // JE: Same
  107.     @Override
  108.     string greetings() {
  109.         return "Morning! I'm " + name
  110.     }
  111. }
  112.  
  113. // JE: Same
  114. enum Gender {
  115.     Male Female None
  116. }
  117.  
  118. // JE: Same
  119. interface Biped {
  120.     // JE: void walk();
  121.     walk
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement