Modules & the Package Ecosystem
Larz covers Larzscript's module system: import a package by name, give it a short alias with as, and call its functions through that alias - a first look at the real 160+ package ecosystem.
import and namespacing
Import a module by name, give it an alias with as, then call its functions through that alias:
import "mathx" as mathx print(mathx.is_prime(97)) print(mathx.fib(10))
Output
true 55
stack and queue
mathx is just one of 160+ packages. stack and queue are two more - a real last-in-first-out and first-in-first-out, ready to import the same way:
import "stack" as stack import "queue" as queue let s = stack.new() stack.push(s, "a") stack.push(s, "b") print(stack.pop(s)) let q = queue.new() queue.enqueue(q, 1) queue.enqueue(q, 2) print(queue.dequeue(q))
Output
b 1
Every snippet on this page is run through the real larzscript interpreter, not hand-typed โ what you see in the Output blocks is the actual output, for everything shown: importing a module, aliasing it, and calling its functions.
Related
Lesson 8: Error Handling โ try/catchtry/catch and require - what's next after modules.→Lesson 6: Strings & Text Processingupper/lower, slicing, strip, split and join - string methods just like the package methods called here.→Lesson 5: Collections โ Lists & Dictslist and dict literals, push(), len() - the data structures stack and queue are built out of.→What Is Larzscript?The full explainer on the money-native pitch, for more depth than a lesson video covers.→Learn Larzscript Cookbook29 short "how to X in Larzscript" recipes, most of them built on imports exactly like these.→