52 lines
1.2 KiB
Plaintext
52 lines
1.2 KiB
Plaintext
// variable definition and initialization/assignment
|
|
//
|
|
// variables are initialized when they are defined
|
|
a = 1
|
|
b = 2
|
|
c = null
|
|
|
|
// datatypes
|
|
//
|
|
// variables may contain any datatype, and this can be
|
|
// changed at any time by assigning a new value. they may
|
|
// also contain native java types
|
|
var = "a string"
|
|
var = 123
|
|
var = new(Nanoquery.Util.Random)
|
|
var = new(java.lang.Object)
|
|
|
|
// scope
|
|
//
|
|
// all classes, functions, and control blocks have their
|
|
// own scope
|
|
x = 5
|
|
for i in range(1, 2)
|
|
// we can reference 'x' within this loop without issue
|
|
println x
|
|
|
|
// we can also define variables that have this loop as their
|
|
// scope
|
|
y = 5
|
|
end
|
|
// trying to reference the variable 'y' outside of its scope would result
|
|
// in a null reference exception
|
|
println y
|
|
//%null reference exception: variable object 'y' has not been defined
|
|
// at <global>:33
|
|
|
|
|
|
// referencing
|
|
//
|
|
// as already demonstrated, variables are referenced by using their
|
|
// name
|
|
part1 = "this is "
|
|
part2 = "a test sentence"
|
|
println part1 + part2
|
|
|
|
// other facilities
|
|
//
|
|
// variables may be marked for garbage collection in their current
|
|
// scope using the 'delete' command
|
|
test_var = "pretend this is a really large object we want to free up"
|
|
delete test_var
|