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

Found bug in @use_ref #14

Open
schlichtanders opened this issue Jun 23, 2023 · 2 comments
Open

Found bug in @use_ref #14

schlichtanders opened this issue Jun 23, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@schlichtanders
Copy link

schlichtanders commented Jun 23, 2023

Hi there,

I am experimenting a lot with PlutoHooks. They are still very very complex. Hence I guess it is super helpful if these primitives work 100% as intended, so that one can build an intuition on those primitives instead of thinking about how they work precisely.

The current @use_ref code is

if @use_did_deps_change([])
	$ref_ref[] = Ref{Any}($(esc(initial_value)))
end
$ref_ref[]

however if initial_value fails

  • the Ref stays undefined, which is probably expected, but in addition
  • if another cell is changed which now retriggers execution of this cell, the following uncomprehensible exception is thrown
UndefRefError: access to undefined reference

    [email protected]:37[inlined]
    [email protected]:56[inlined]
    macro expansion@[Local: 211](https://...#)[inlined]
    macro expansion@[Other: 26](https://...#)[inlined]
    top-level scope@[Local: 1](https://...#)[inlined]

One direction of thought how this may be fixed:

  • Maybe get rid of @use_did_deps_change entirely and rewrite @use_deps so that it can check whether the initialization failed and create a new cell_id the second time. Then use @use_deps instead of @use_did_deps_change.
@Pangoraw
Copy link
Member

Thanks for the issue!

Maybe we could go with something like this, which would retry initial_value until it succeeds:

value = $ref_ref[]
if !isassigned(value) || @use_did_deps_change([])
    $ref_ref[] = Ref{Any}($(esc(initial_value)))
end
value

What do you think?

@Pangoraw Pangoraw added the enhancement New feature or request label Jun 23, 2023
@schlichtanders
Copy link
Author

sounds really good, super simple actually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants