Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Multi-line NextDocs.
- */
- /**
- * Multi-line comments.
- */
- // Single line comments
- /**
- * Next Programming Language, NXT or NPL for short.
- * Null Pointer Language for jest.
- *
- * Every example will include the Java equivalent.
- * JE:
- */
- // Packages are declared using a directory structure of some 'domain'.
- // Packages are also required, every file must be in a domain.
- // No default domains are allowed.
- // JE: package next.lang.test;
- domain next/lang/test
- // Imports are the same as the package declarations in style.
- // JE: import next.lang.test.SomeClass;
- use next/lang/test/SomeClass
- // Keyword 'also' is used since it's easier/faster to type than implements
- // JE: public abstract class Person implements Biped {
- public abstract class Person also Biped, Talker, Singer {
- // string is just a primitive keyword of object type String
- string name
- // Much like Go and other languages semicolons are completely optional on new lines.
- // Comma separators are also optional.
- int age height weight
- Gender gender
- // var is also just a primitive Object
- // arrays are lazily initialized as: array = new Object[0];
- var[] attributes
- // Types are inferred for any untyped method and constructor parameters.
- // Generates: public Person(string name, int height, int weight) on compile.
- // If types cannot be inferred then a compiler error is thrown must be explicitly typed.
- // JE: public Person(String name, int height, int weight) {
- public Person(name height weight) {
- this.name = name
- this.height = height
- this.weight = weight
- age = 32
- // Natural ordering is given to unspecified index insert of an array.
- attributes[] = name // Extend array by 1, Insert at index array.length - 1.
- attributes[] = age // Extend array by 1, Insert at index array.length - 1.
- }
- // No return type was given so this is void.
- // No () is needed for empty arguments, this removes the need for unneeded typing.
- // JE: public void speak() {
- public speak {
- System.io.println(greetings())
- }
- // This is a method since it has a block and not a value
- // JE: String greetings() {
- string greetings {
- // string concatenation will use the addition operator +
- return "Hello, my name is " + name
- }
- // This is a field since it has declared a value
- string greetings = "Hello, my name is " + name
- // Keyword instance is used in place of protected since it's easier to type.
- instance var getAttribute(index) {
- return attributes[index]
- }
- public doThing {
- // Since more type information is known at runtime (this will be a string) it
- // will be overloaded to thing(string)
- // Overload to most specific type first
- thing(getAttribute(0))
- // Most specific type for an integer will be thing(var) at runtime.
- thing(getAttribute(1))
- }
- private thing(var variable) {
- System.io.println(variable + ": is a " + variable.getClass())
- }
- private thing(string str) {
- System.io.println(str + ": is a string")
- }
- }
- // Keyword 'is' is used in place of extends since it's easier/faster to type.
- Man is Person {
- // The default block is for lazy initialization of fields in the superclass chain.
- // These are run after memory allocation, before construction.
- // JE: None. But much like static block for instance variables.
- default {
- gender = Gender.Male
- }
- // Typical override, optional @Override annotation.
- // JE: Same
- @Override
- string greetings() {
- return "Morning! I'm " + name
- }
- }
- // JE: Same
- enum Gender {
- Male Female None
- }
- // JE: Same
- interface Biped {
- // JE: void walk();
- walk
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement