While similar questions have already been posted on this website, none of them deal with the Julia language. I have already implemented a working version of the algorithm, and am looking for language-specific optimisations.
Here is the code I've written in Julia:
S(a::Array, n::Int64)::Array{Array} = n == 0 ? [[]] : vcat([push!.(deepcopy(S(a, n-1)), α) for α in a]...)
Although this code works as intended, it is quite slow and consumes a lot of memory.
I've tried optimising it slightly by avoiding recomputing S(a, n-1) several times:
S(a::Array, n::Int64)::Array{Array} = n == 0 ? [[]] : (arr::Array{Array} -> vcat([push!.(deepcopy(arr), α) for α in a]...))(S(a, n-1))
The issue of memory ineffciency, however, persists. Is there any way in which I can optimise this code to make it more memory efficient?