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

Might be confusing to have Do defwire always reuses the context of the first parent wire that calls it #713

Open
Yttruire opened this issue Jun 26, 2023 · 0 comments

Comments

@Yttruire
Copy link
Contributor

According to the documentation on shards flow,

Do allows you to run a Wire without having to schedule it on a Mesh. This is useful when you wish to reuse a Wire multiple times, similar to a function.

However, contrary to expectation, calling (Do wire-name) from different wires may result in unexpected behaviour because wire-name will only have a reference to the context of the first parent wire that called (Do wire-name). This might be problematic in the case that a wire wants to reference variables from multiple different caller wires, but can only reference variables from the first wire that calls it.

Example of possible unexpected behaviour:
If (Do caller-1) is called followed by (Do caller-2), then wire-name will always assign 10 to the .parent-variable in caller-1 without being able to reference the .parent-variable in caller-2. If this is a non-issue, then the documentation should be updated as the explanation could be misleading regarding reusability of wires in this way.

(defwire wire-name
  10 > .parent-variable)

(defwire caller-1
  0 >= .parent-variable
  (Do wire-name))

(defwire caller-2
  0 >= .parent-variable
  (Do wire-name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant