请教一下,下面的不同是什么原理导致的?函数内部作用域?
julia> str
"Turns hello_to_you into HelloToYou"
julia> function splitter(dlm)
function r(str, dlm)
split(str, dlm)
end
return r
end
splitter (generic function with 1 method)
julia> str |> splitter('_')
ERROR: MethodError: no method matching (::var"#r#3")(::String)
Closest candidates are:
(::var"#r#3")(::Any, ::Any)
@ Main REPL[4]:2
Stacktrace:
[1] |>(x::String, f::var"#r#3")
@ Base .\operators.jl:907
[2] top-level scope
@ REPL[11]:1
julia> function splitter(dlm)
function r(str)
split(str, dlm)
end
return r
end
splitter (generic function with 1 method)
julia> str |> splitter('_')
3-element Vector{SubString{String}}:
"Turns hello"
"to"
"you into HelloToYou"
julia> function splitter(dlm)
function r(str, dm)
dm = dlm
print("dm is", dm)
split(str, dm)
end
return r
end
splitter (generic function with 1 method)
julia> str |> splitter('_')
ERROR: MethodError: no method matching (::var"#r#8"{Char})(::String)