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

Do dynamo call broken for calls inside of methods #62

Open
femtomc opened this issue May 21, 2020 · 0 comments
Open

Do dynamo call broken for calls inside of methods #62

femtomc opened this issue May 21, 2020 · 0 comments

Comments

@femtomc
Copy link

femtomc commented May 21, 2020

I found this interesting bug today as I was trying to move some of my code away from using macros. In the following, I'm using anonymous funcs, but I encountered the same bug in methods.

anon = () -> begin
    tr = Trace()
    tr() do
        foo()
    end
    tr
end

This code works fine when you evaluate anon - it returns the Trace, which has been modified in the dynamo call, as expected. However, if I abstract out the call to foo:

anon = (call, args) -> begin
    tr = Trace()
    tr() do
        call(args...)
    end
    tr
end

the dynamo does not apply (i.e. the Trace is not mutated, as a side effect).
I found a related bug as well - here, foo is nullary function so you might expect this to work:

anon = call -> begin
    tr = Trace()
    tr() do
        call()
    end
    tr
end

but when I pass in foo as anon(foo), it throws:

LoadError: BoundsError: attempt to access 0-element Array{Any,1} at index [0]

This is obviously not what happens outside of the dynamo, i.e.:

anon2 = call -> begin
    call()
end

returns the result of calling foo.


Lastly, maybe I should show what the result of the dynamo is:

tr = Trace()
tr() do
    foo()
end
println(tr, [:val])

results in

| <> (:foo => :bar) => (:q => 2) <>
|          val  = 1.0100076975990129
|
| <> (:foo => :bar) => (:q => 10) <>
|          val  = -1.0067463813037731
|
| <> (:foo => :bar) => (:q => 9) <>
|          val  = 0.3533852496897451
|
| <> :foo => :y <>
|          val  = -0.29516473908558977
|
| <> (:foo => :bar) => (:q => 3) <>
|          val  = -0.3524573630007816
...

when called outside of methods.

Edit: I'm guessing this is an @generated thing?

@femtomc femtomc changed the title Do dynamo broken for calls inside of methods Do dynamo call broken for calls inside of methods May 21, 2020
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