Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modules / Namespaces #8

Open
xNaCly opened this issue Feb 20, 2024 · 0 comments
Open

Modules / Namespaces #8

xNaCly opened this issue Feb 20, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@xNaCly
Copy link
Owner

xNaCly commented Feb 20, 2024

Idea

As proposed some time ago in examples/modules.phia.

Modules will be used to group functions together and enable the linking of the standard library via wrappers.

(module person
(fun str [p] (++ "person: " p#["name"])
(module extract ;; namespaces can be nested
(fun name (_ p) p["name"])
)
)

Calling functions of a given module:

;; using a custom module
(use person)
(let pers { name: "anon" })
(println (person::string pers))
;; using nested module
(use person::extract)
(println (person::extract::module pers))

Implementation details:

  1. Modules will be registered with its name upon encountering (module <name>) in consts.MODULE_TABLE via the expr.Module.Eval() structure
  2. Encountering (use <module>) will evaluate the module and place its functions into the consts.FUNC_TABLE prefixed with <module_name>::.
  3. Calling the function via (<module>::<function> <args) is now possible
@xNaCly xNaCly added the enhancement New feature or request label Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant