madlambda/nash

language: packages with proper namespacing

vitorarins opened this issue · 1 comments

Packages will work by returning a value that can be used when you import a
package.

For example,

import "x"

Will create a local variable x containing the value returned by package "x".
You can change the name of the imported package using the syntax below:

y = import "x"

The value returned from the package could be anything. See examples below:

Ex.:

# package strings
# returns a map of functions

fn join(lst, sep) {}
fn trimleft(str) {}
fn trimright(str) {}
fn trim() {}

return {
    "join": $join,
    "trimleft": $trimleft,
    "trimright": $trimright,
    "trim": $trim,
}

You can use the package above with code below:

import "strings"

str <= strings["trim"]("    test  ")
echo $str # Output: test

I think this depends on #202