function f(arg)
# Wrap a string with spaces between quotes
if (isa(arg, AbstractString) || isa(arg, Symbol))
out = string(arg)
if (occursin(" ", out))
out = "\"" * out * "\""
end
else
error("Bla")
end
end
It works well when the input has blanks
julia> f("aaa bbb")
"\"aaa bbb\""
but returns nothing
when it doesn’t
julia> f("aaabbb")
julia>
What are you occursin
expecting to do?
It returns true/false depending on weather the the first argument is contained in the second.
In your second call that condition is not met and
the if
block is not executed.
There is no return statement.
if occursin == true
then the implicit return value is out
(it is the last line executed except for end
keywords)
if occursin == false
then there is no assignment as the last line. It is the if
statement. Then nothing
is returned instead.
I suggest adding a return out
at the end.
1 Like
You are right, but I was expecting that when occursin == false
the previous assignment (out = string(arg
) was the last one and that value should be the return value