Publishing Your Own Package
The last lesson: a package is just a file of functions, importable with a relative path - and larzscript pkg publish is the one command that put every package in this course into the real ecosystem.
a package is just a file
Write functions in a file, then import it with a relative path - the same mechanism as importing any package from Lesson 7:
# greetings.lz โ your own package is just a file of functions
fn hello(name) {
return "hello, " + name + "!"
}
fn shout(msg) {
return msg.upper() + "!!!"
}
# use_it.lz โ import it with a relative path, same as any package
import "./greetings" as greetings
print(greetings.hello("Ada"))
print(greetings.shout("it works"))hello, Ada! IT WORKS!!!
search, install, done
larzscript pkg publish <git-url> [as <name>] is the exact command every package in this course was published with. Once it's out there, pkg search and pkg install work on it like any other package - shown here against stack, already published and live:
larzscript pkg publish <git-url> [as <name>] larzscript pkg search stack larzscript pkg install stack
stack installing stack ... stack is up to date -> /home/larz/.larzscript/lib/stack use it with: import "stack"
Every snippet on this page is run through the real larzscript interpreter, not hand-typed โ including pkg search and pkg install against a real, already-published package. pkg publish itself has real, live effects against the package registry, so its syntax is shown exactly as documented rather than triggered from this page.