You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Julia allows pattern matching on tuples in some cases (iteration) but not others (applying anonymous functions). This isn't a major issue, but it does seem a bit of a design inconsistency and could be confusing to new users:
julia> versioninfo()
Julia Version 0.5.0
Commit 3c9d753 (2016-09-19 18:14 UTC)
Platform Info:
System: NT (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.7.1 (ORCJIT, sandybridge)
julia> x = [(1,2),(3,4),(5,6)]
3-element Array{Tuple{Int64,Int64},1}:
(1,2)
(3,4)
(5,6)
julia> for (a,b) in x
println(b)
end
2
4
6
julia> [b for (a,b) in x]
3-element Array{Int64,1}:
2
4
6
julia> sum(b for (a,b) in x)
12
julia> map((a,b) -> b, x)
ERROR: MethodError: no method matching (::##125#126)(::Tuple{Int64,Int64})
Closest candidates are:
#125(::Any, ::Any) at REPL[20]:1
in _collect(::Array{Tuple{Int64,Int64},1}, ::Base.Generator{Array{Tuple{Int64,Int64},1},##125#126}, ::Base.EltypeUnknown, ::Base.HasShape) at .\array.jl:320
in map(::Function, ::Array{Tuple{Int64,Int64},1}) at .\abstractarray.jl:1683
The text was updated successfully, but these errors were encountered:
See #6614. The syntax in that case would be map( ((a,b),)->b, x ).
It's vaguely possible to have a language where a function of 1 2-tuple is the same as a function of 2 arguments, but overall I think that leads to worse problems and more confusion.
Julia allows pattern matching on tuples in some cases (iteration) but not others (applying anonymous functions). This isn't a major issue, but it does seem a bit of a design inconsistency and could be confusing to new users:
The text was updated successfully, but these errors were encountered: