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

Share / export constants between Wing files and libraries #3606

Open
Chriscbr opened this issue Jul 25, 2023 · 4 comments
Open

Share / export constants between Wing files and libraries #3606

Chriscbr opened this issue Jul 25, 2023 · 4 comments
Labels
🛠️ compiler Compiler ✨ enhancement New feature or request 📐 language-design Language architecture 📚 libraries Wing Libraries

Comments

@Chriscbr
Copy link
Contributor

Chriscbr commented Jul 25, 2023

Feature Spec

Wing now supports bringing specifying constants as shared/public by a module (Wing file), and then bringing them into other Wing modules.

Use Cases

Reusing information (supporting DRY). Example:

// constants.w
pub let DATA = "Hello world!";

// main.w
bring "./constants.w" as constants;
bring cloud;

let bucket = new cloud.Bucket();
bucket.addObject("data.txt", constants.DATA);

Alternative syntax suggestions welcome.

Implementation Notes

The design reason to only support sharing constants (and not any values) is to avoid the semantic ambiguities that arise when sharing mutable values across module boundaries:

// file1.w
let pub a = MutArray<num>[1, 2, 3];

// file2.w
bring "./file1.w" as stuff;
stuff.a.push(4);

// file3.w
bring "./file1.w" as stuff;
stuff.a.push(5); // is the array [1, 2, 3, 4, 5] or [1, 2, 3, 5, 4] or [1, 2, 3, 5] ?

In the initial version, a list of types we can support as constants are:

  • num
  • str
  • bool
  • duration
  • datetime
  • Json
  • Array<T>, Map<T>, or Set<T> where T is a valid constant type
  • T? where T is a valid constant type
  • any enum value
  • any struct whose fields are all valid constant types

Free floating functions and may also be reasonable to share across module boundaries in the future.

Component

Language Design, Compiler

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
@Chriscbr Chriscbr added ✨ enhancement New feature or request 📐 language-design Language architecture 🛠️ compiler Compiler labels Jul 25, 2023
@github-actions
Copy link

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days.
Feel free to re-open this issue when there's an update or relevant information to be added.
Thanks!

@github-actions github-actions bot added the Stale label Sep 24, 2023
@Chriscbr Chriscbr changed the title Share / export constants between Wing files Share / export constants between Wing files and libraries Oct 4, 2023
@staycoolcall911 staycoolcall911 added the 📚 libraries Wing Libraries label Nov 15, 2023
Copy link

github-actions bot commented Mar 6, 2024

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days.
Feel free to re-open this issue when there's an update or relevant information to be added.
Thanks!

Copy link

github-actions bot commented Jun 6, 2024

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days.
Feel free to re-open this issue when there's an update or relevant information to be added.
Thanks!

@Chriscbr
Copy link
Contributor Author

@boyney123 mentioned that sharing functions should also be pretty safe to also define as constants under these rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛠️ compiler Compiler ✨ enhancement New feature or request 📐 language-design Language architecture 📚 libraries Wing Libraries
Projects
Status: 🤝 Backlog - handoff to owners
Development

No branches or pull requests

2 participants