-
Notifications
You must be signed in to change notification settings - Fork 14
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
Why not define this function in a normal way? #141
Comments
Julia has bad semantics around capturing variables in closures, causing frequent bugs like this julia> x = rand(2,3);
julia> f = y -> y + x
#3 (generic function with 1 method)
julia> a = rand(2,3);
julia> f(a)
2×3 Matrix{Float64}:
1.39317 1.18612 1.0031
0.303721 1.17959 0.689349
julia> x = 4 # I'm now doing something else, so redefining x
4
julia> f(a) # let me call f again... oops!
ERROR: MethodError: no method matching +(::Matrix{Float64}, ::Int64)
For element-wise addition, use broadcasting with dot syntax: array .+ scalar
Closest candidates are:
+(::Any, ::Any, ::Any, ::Any...)
@ Base operators.jl:585
+(::T, ::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8}
@ Base int.jl:87
+(::Rational, ::Integer)
@ Base rational.jl:332
...
Stacktrace:
[1] (::var"#3#4")(y::Matrix{Float64})
@ Main ./REPL[2]:1
[2] top-level scope
@ REPL[6]:1 Using julia> x = rand(2,3);
julia> f = let x = x; y -> y + x; end
#5 (generic function with 1 method)
julia> a = rand(2,3);
julia> f(a)
2×3 Matrix{Float64}:
0.600399 1.78474 1.07068
0.416237 1.025 0.708488
julia> x = 4
4
julia> f(a) # f still works!
2×3 Matrix{Float64}:
0.600399 1.78474 1.07068
0.416237 1.025 0.708488 |
If I understand correctly, |
Ha ha, no, you understand it correctly. That is a bug. |
Hello guys,
I just started using SimpleChains.jl.
For me, Julia is a tool and I didn't learn the language very carefully so I don't know all the syntaxes. It's a little bit hard for me to understand the function below, which is found in the first example of SimpleChains.jl. I think there must be a lot of users like me who don't have sophisticated knowledge of Julia.
So could the authors write documentation and examples in a simpler/common way?
Thanks!
The text was updated successfully, but these errors were encountered: