Hi,

This is an interesting syntax indeed. Thanks!

Jan

Dňa streda, 21. októbra 2015 18:04:47 UTC+2 Ben Arthur napísal(-a):
>
> element-wise multiplication of string vectors works too, but only if one 
> vector is of length 1:
>
> julia> @time ["["] .* ["as", "sdf", "qwer"] .* ["]"] 
> 0.000033 seconds (35 allocations: 1.656 KB) 
> 3-element Array{ASCIIString,1}: 
> "[as]" 
> "[sdf]" 
> "[qwer]"
>
> if you prefer this syntax to map or comprehension, extending .* as follows 
> uses less memory:
>
> julia> import Base.(.*) 
>
> julia> (.*){T<:AbstractString}(v::Vector{T},s::T) = [i*s for i in v] 
> .* (generic function with 36 methods) 
>
> julia> (.*){T<:AbstractString}(s::T,v::Vector{T}) = [s*i for i in v] 
> .* (generic function with 37 methods)
>
> julia> @time "[" .* ["as", "sdf", "qwer"] .* "]" 
> 0.000010 seconds (19 allocations: 1024 bytes) 
> 3-element Array{ASCIIString,1}: 
> "[as]" 
> "[sdf]" 
> "[qwer]"
>
> see https://github.com/JuliaLang/julia/issues/13053
>

Reply via email to