Fast, Lightweight & Coherent.
If Python, JavaScript & Lua had a baby, it would be nue.
Track development on GitHubprint("Hello, World!")
Single line comments start with double forward slashes:
//
Comments which span multiple lines start with
//#
and end with#//
Heres an example:
// I'm a single line comment! //# I span multiple lines! #//
-
// Creating a global (non-local) variable var string myString = "Hey guys!" // Private variables (scope limited to where variable was declared) private var number myNumber = 3.14159 // Alias: Creates a reference to something private alias thisMightBeSomething = something.aKey.anotherThing.Lol.wayTooLong thisMightBeSomething = "That was really unnecessary!" print(something.aKey.anotherThing.Lol.wayTooLong) // That was really unnecessary! print(thisMightBeSomething) // That was really unnecessary!
In nue, you can use the
import()
function to retrieve the returned contents of a file.If no specific file path is specified (relative to the program), then nue will search inside the nsh (nue share / package manager) directory for a library.
nue has a few standard libraries which fulfil most of the average user's needs.
Here's an example:
private var table tables = import("tables") // table manipulation library private var table strings = import("strings") // string manipulation library print(strings.reverse("Hello world!")) // !dlrow olleH
Functions are assigned to variables. The name of the variable automatically becomes the function name, and you can call it later.
Nue expects you to define the return type(s) for a function. If it's just a procedure and there are no returns, just declare the return type as
null
.Here's an example:
private var function reverseString = function(string input) -> boolean, string { private var boolean success // defaults to false if type(input) == "the secret code" { return success, "Unable to reverse the secret code." } success = true return success, strings.reverse(input) }
-
// this may be called an array in other programming languages. // nue has no distinction between conventional "arrays", "dictionaries", etc. private var table myThing = { numone = "Rat", testLolz = "Cat", ["does this microphone work"] = "Bat" } // a single-variable for loop will assume that you only want the value for veryCoolValue in myThing { print(veryCoolValue) } //# Rat Cat Bat #// // a double variable for loop will assume that you want both the index and the value for amazingIndex, evenCoolerValue in myThing { print(amazingIndex, evenCoolerValue) } //# numone, Rat testLolz, Cat does this microphone work, Bat #//
-
// Example of advanced data structure private var table complexData = { numbers = {1, 2, 3, 4, 5}, calculate = function() -> number { private var number sum = 0 for num in this.numbers { sum += num } return sum } } print("Sum of numbers:", complexData.calculate())
-
if 5 > 2 { print("5 is greater than 2!") } if 3 > 9 { print("Something went horrible wrong.") } else if 4 != 3 { print("4 isn't equal to 3") } private var boolean bool1 = true private var boolean bool2 = true // Logical OR // Two vertical bars were chosen to represent OR because of the familiarity with other programming languages, // and OR's truth table, where both values can be true and result in true, therefore two bars. if bool1 || bool2 { print("Yup!") } // Logical XOR // The single vertical bar was chosen to denote XOR because XOR only allows one value to be true, therefore it is only one bar. if bool1 | bool2 { print("Something went wrong.") } else { print("Only one of them can be true, therefore the result of the XOR operation was false.") }
In nue, null is a state (the absence of a useful value), and not the complete absence of a value (absolute nothing).
This means that you cannot simply assign null to a variable and expect it to be deallocated from memory accordingly. Therefore, you must deallocate variables and values yourself by using the
delete()
function:
private var number doublePi = 6.2831 private var string tooMuchCringe = "bruh" // delete() accepts multiple variables for convenience. delete(doublePi, tooMuchCringe)
We plan to introduce a custom nullable directive IN THE FUTURE (not current) to potentially override this behaviour. (Might not become a feature unless it is extensively requested)
Any code provided in these demonstrations are subject to change during the development of nue.
More examples will be provided when nue has its first release and some documentation is published.