pkgs and nses #5

Open
opened 2023-12-14 01:27:24 +00:00 by kredati · 4 comments
kredati commented 2023-12-14 01:27:24 +00:00 (Migrated from github.com)

A module form could be interesting. It describes a namespace, but instead of an explicit associative data structure (as the ns form is currently), it would be followed by a block. It would then bundle up all the bindings in this block into an equivalent namespace.

The following would then be equivalent:

& current `ns` strategy: 
let foo = ...
let bar = ...
let baz = ...
ns Foobar { foo, bar, baz }

& new `module` strategy:
module Foobar {
    let foo = ...
    let bar = ...
    let baz = ...
}

This is not quite pure sugar: it relies on the plumbing of Ludus being able to do something with the context of the scope. But I think this is quite ergonomic.

  • Is module the right name for this?
  • Is ns actually the name for this?
  • Is the old ns strategy the right one now that we don't have structs?
A `module` form could be interesting. It describes a namespace, but instead of an explicit associative data structure (as the `ns` form is currently), it would be followed by a block. It would then bundle up all the bindings in this block into an equivalent namespace. The following would then be equivalent: ``` & current `ns` strategy: let foo = ... let bar = ... let baz = ... ns Foobar { foo, bar, baz } & new `module` strategy: module Foobar { let foo = ... let bar = ... let baz = ... } ``` This is not quite pure sugar: it relies on the plumbing of Ludus being able to do something with the context of the scope. But I think this is quite ergonomic. * [ ] Is `module` the right name for this? * [ ] Is `ns` actually the name for this? * [ ] Is the old `ns` strategy the right one now that we don't have structs?
kredati commented 2023-12-14 05:15:48 +00:00 (Migrated from github.com)

Better names? A current ns should actually be a package, pkg; the module proposal here is more properly called a "namespace."

Better names? A current `ns` should actually be a _package_, `pkg`; the module proposal here is more properly called a "namespace."
scott self-assigned this 2023-12-15 21:25:22 +00:00
scott removed their assignment 2023-12-27 04:18:16 +00:00

The revised, current strategy:

& a package, `pkg`: 
let foo = ...
let bar = ...
let baz = ...
pkg Foobar { foo, bar, baz }

& a namespace, `ns`:
ns Foobar {
    let foo = ...
    let bar = ...
    let baz = ...
}

A namespace is a package; it exports all first-level bindings into the package.

Packages must have capitalized names; unlike dicts, they panic if you try to access a key that isn't on them.

Only packages may be used with the use form: use Foobar, above, would load foo, bar, and baz into the local scope. use may also only be used at the toplevel.

The revised, current strategy: ``` & a package, `pkg`: let foo = ... let bar = ... let baz = ... pkg Foobar { foo, bar, baz } & a namespace, `ns`: ns Foobar { let foo = ... let bar = ... let baz = ... } ``` A namespace is a package; it exports all first-level bindings into the package. Packages must have capitalized names; unlike dicts, they panic if you try to access a key that isn't on them. Only packages may be used with the `use` form: `use Foobar`, above, would load `foo`, `bar`, and `baz` into the local scope. `use` may also only be used at the toplevel.

Accepted, and implemented in scanner, parser, validator.

Accepted, and implemented in scanner, parser, validator.
scott changed title from To consider: a `module` form to `pkg`s and `ns`es 2024-05-19 19:26:50 +00:00
scott added this to the Computer Class milestone 2024-05-19 19:26:52 +00:00

Current status, good enough for Computer Class, I think:

  • pkg works and is validated.
  • ns access does not pass validation, and is not yet implemented in the interpreter.
  • pkg access, e.g. Foo :bar is validated properly.
  • pkgs are not (yet) implemented in the interpreter.
Current status, good enough for Computer Class, I think: * `pkg` works and is validated. * `ns` access does not pass validation, and is not yet implemented in the interpreter. * pkg access, e.g. `Foo :bar` is validated properly. * pkgs are not (yet) implemented in the interpreter.
scott modified the milestone from Computer Class to 0.2.0 2024-05-31 16:40:10 +00:00
scott added this to the Completing the language project 2024-07-21 17:45:44 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: twc/ludus#5
No description provided.