Operations on Packages

findPackage(String packageName)

findPackage() returns the Package object of the specified name. If the package does not exist it returns null.

findPackage("foo")   ==> null
package("foo")       ==> package "foo"
package("")
findPackage("foo")   ==> package "foo"
package()            ==> package ""
getPackage(String packageName)

getPackage() returns the Package object of the specified name. If it does not exist it creates one and return it.

package()             ==> package ""
findPackage("bar")    ==> null
getPackage("bar")     ==> package "bar"
package()             ==> package ""
createPackage()
createPackage( ` expression ; ... `)
createPackage( expression , ... )

createPackage() creates and returns an anonymous package.

# of parameters The types The action
1 java.lang.String Evaluate the string in a package
1 java.lang.Object[] Interpret each element as a [key, value] pair and define them in a package
any any If there is any function in the parameters, register the function with its name in a package.
e.g.
p = createPackage()
p.x = 1
p.y = 2

q = createPackage("x = 1; y = 2")
q.x     ==> 1
q.y     ==> 2

r = createPackage([["a", "hello"], ["b", "world"]])
r.a  ==> "hello"
r.b  ==> "world"

Unlike ordinary functions, createPackage() evaluates its parameters with the caller's context. See also "Script Package".

removePackage(String name)

removePackage() removes the specified package.

rootScope( )

rootScope() returns the topmost package of the package hierarchy, which is usually the global package.