Skip to content

new import syntax for modules#70

Merged
cowboyd merged 2 commits into
mainfrom
new-module-syntax
Feb 4, 2023
Merged

new import syntax for modules#70
cowboyd merged 2 commits into
mainfrom
new-module-syntax

Conversation

@cowboyd
Copy link
Copy Markdown
Member

@cowboyd cowboyd commented Feb 1, 2023

Motivation

Import syntax and module semantics are suboptimal. See #57 for a write-up.

Approach

To summarize, this makes imports a map instead of a list:

before

$import:
  - names: [capitalize,decapitalize]
    from: https://pls.pub/std@1.0.0/strings.yaml
  - names: [parse]
    from https://pls.pub/x/parse.yaml

after

$import:
  capitalize, decapitalize: https://pls.pub/std@1.0.0/strings.yaml
  parse: https://pls.pub/x/parse.yaml

This also simplifies the module semantics. Modules do not have a list of symbols and a value, they just have a value, and that value you can imported key by key.

$import:
  something: https://pls.pub/x/things@1.0.0/mod.yaml

Or, use the << merge key after a symbol name to indicate that the entire module value should be bound to that name.

$import:
  everything<<: https://pls.pub/x/things@1.0.0/mod.yaml

It is possible to have both a slurp everything import and a named import:

$import:
  everything<<, thing: https://pls.pub/x/things@1.0.0/mod.yaml

There is not currently a method to alias imported names, but that should be provide for eventually.

Import syntax and module semantics are suboptimal. See
#57 for a
write-up.

To summarize, this makes imports a map instead of a list:

**before**

```yaml
$import:
  - names: [capitalize,decapitalize]
    from: https://pls.pub/std@1.0.0/strings.yaml
  - names: [parse]
    from https://pls.pub/x/parse.yaml
```

**after**

```yaml
$import:
  capitalize, decapitalize: https://pls.pub/std@1.0.0/strings.yaml
  parse: https://pls.pub/x/parse.yaml
```

This also simplifies the module semantics. Modules do not have a list
of symbols and a value, they just have a value, and that value you can
imported key by key:

```yaml
$import:
  something: https://pls.pub/x/things@1.0.0/mod.yaml

```

Or, use the `<<` merge key after a symbol name to indicate that the
_entire module value_ should be bound to that name.

```yaml
$import:
  everything<<: https://pls.pub/x/things@1.0.0/mod.yaml
```

There is not currently a method to alias imported names, but that should be
provide for eventually.
Copy link
Copy Markdown
Member

@taras taras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should document this immediately

@cowboyd cowboyd merged commit ea53eaf into main Feb 4, 2023
@cowboyd cowboyd deleted the new-module-syntax branch February 4, 2023 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants