Because to my understanding the @threads macro applies to the for loop it stands before. This doesn’t come out in my example,but [i @threads for i in 1:4 for j in 1:3]
would not be the same as: [i for i in 1:4 @threads for j in 1:3].
In the first case, the parallelization would be over i, in the second case over j.
There’s also a technical reason to prefer @threads [x for x in xs] — it can work without any parser changes.
julia> :([x @threads for x in xs])
ERROR: syntax: invalid comprehension syntax
julia> :(@threads [x for x in xs])
:(#= REPL[2]:1 =# @threads [x for x = xs])
I am going to make a broad statement and say
macros are the wrong tool for the job.
(the current use of @threads included)
thread_map(f, xs) is the right tool,
and we should have that. which would for your example me thread_map(identity, 1:4).
Ontop of such functions it is easy to build some macro based DSL,
if you want.
Or to build an Array type that automatically dispatches to using multiple threads,
when using normal map
etc.