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

Allow packet-level environment overlay #38

Open
2 of 3 tasks
jkomoros opened this issue Jul 5, 2023 · 2 comments
Open
2 of 3 tasks

Allow packet-level environment overlay #38

jkomoros opened this issue Jul 5, 2023 · 2 comments

Comments

@jkomoros
Copy link
Owner

jkomoros commented Jul 5, 2023

The best practice is to set a particular memory and store (and, in the future, prefix) that uses a distinctive prefix (e.g. komoroske.com) at the root of each seedGraph to make sure that all of the references within it use the same model/store/prefix.)

However, this quickly gets extremely repetitive in packets that contain lots of entrypoints, and for ones that are intermediate entrypoints, requires duplicative environment let-multi statements that were already done by seeds that called them.

We should add a property, environment, in a packet. It's an optional property, and should specify an EnvironmentData overlay. The starter environment for each seed in the packet will have that environment overlaid on whatever the previous environment was. It's as though each root-level seed is wrapped in a (hidden) let-multi with those properties.

What should the property be named? environment is a bit misleading because it implies it's the entire environment when really it's an overlay. let is a bit wrong because semantically it's a let-multi. vars is wrong because we use var to mean retrieve the environment. env is wrong because that's the only place in user-facing semantics that call it that.

When combined with #37, the convention will be to set a prefix in the packet-level environment every time.

A typical use case for this will be to set a namespace, but also set things like the model. The latter requires the former. Perhaps have the value be an object or an array of EnvironmentData. If it's an array then it should create the environment by overlaying each time. Actually, this might not be required, because namespace is late bound, so you can set it in the same block as another thing.

Originally tracked in #36.

  • Fix the sub-seed overlay problem documented below.
  • Update complex examples to not use top-level let but instead use environment.
  • Fix the edge case for nested seeds getting the environment re-set for them and possibly overriding intermediate lets.
@jkomoros
Copy link
Owner Author

jkomoros commented Jul 6, 2023

Wait, there's a problem: sub-seeds are passed an environment entirely derived by the caller, which means that seeds that expect a given environment to be set will not have that environment set when called as a sub-expression.

The fix is to make it so let/let-multi don't derive an entire environment but rather an overlay. That overlay is put over top of the base environment for each seed when grow() is called.

When this is fixed, update the TODO in README.

jkomoros added a commit that referenced this issue Jul 7, 2023
…at is overlaid on top of the default

environment for each seed in the packet before being executed as a top-level seed.

Note that there is a non-intuitive behavior, documented in a TODO in README, where seeds executed as
sub-seeds of parents in other packets will not have the base environment they expect, since currently the
enviroment for a sub-seed is entirely defined by the calller seed, which might come from a different
context. That makes this feature less useful than it might otherwise be, because seeds that are
entrypoints can't rely on having baseline variables set.

Part of #38.
jkomoros added a commit that referenced this issue Jul 7, 2023
Now it applies as the last step in each seed before it executes, which is notionally equivalent to having
a let-multi at the top of each.

This allows seeds to be confident that their values are set by them and not accidentally by calling seeds.

Part of #38.
jkomoros added a commit that referenced this issue Jul 7, 2023
@jkomoros
Copy link
Owner Author

jkomoros commented Jul 7, 2023

There's still one weird edge case: if you have nested seeds where inside the nested seed it changes the environment overlay with an additional let, it will be re-overriden by the seed's environment before it's executed. This seems like the kind of weird edge case that will be rare but when it bites will be REALLY confusing.

We could make it so private seeds don't get the environment overlay... but that's kind of a weird magical behavior?

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

No branches or pull requests

1 participant