What to do if `@thunk` is applied to a variable (rather than an expression) ?
maybe make @thunk error if applies to a variable (rather than an expression) ? #50
I can imagine an easy mistake to make would be to write:
∂A = foo(x)
return @thunk(∂A)
When one whould have written:
∂A = @thunk(foo(x))
return ∂A
Or we could just make it not return a Thunk
so by adding something like:
macro thunk(expr::Symbol)
return expr # don't thunk single symbols
end
Advantage of this is that we can keep using it as it is currently used in @scalar_rule (I think).
Maybe maybe @scalar_rule should just be calling maybe_thunk or something
So if I understand you correctly then:
julia> function foo(x)
dA = goo(x) + 1
return @thunk(dA)
end
foo (generic function with 1 method)
julia> goo(x) = x^2 + x + 1
goo (generic function with 1 method)
julia> unthunk(foo(1))
4
is not a correct way to use @thunk?
If you use @thunk in that way then it does not delay any computation.
You might as well just do
function foo(x)
dA = goo(x) + 1
return dA
end
The correct thing to do is:
function foo(x)
dA = @thunk(goo(x) + 1)
return dA
end
So that running goo(x) + 1) is delayed until it is unthunked
Understood.