Closed tamasgal closed 5 years ago
This has nothing to do with @set
or vectors, but with the parser. Just add some parens to make clear that foos
is not an argument of the macro:
julia> altered_foos = map(e -> @set(e.a += 1), foos)
10-element Array{Foo,1}:
Foo(1.6176958141023454, 0.3878116659353461)
Foo(1.5538936455530625, 0.2978874484594669)
Foo(1.021292203475409, 0.713884428905962)
Foo(1.4367673447106937, 0.8425043609446288)
Foo(1.1680935435405346, 0.47500893921412546)
Foo(1.4694724149539797, 0.10487020499341693)
Foo(1.8587307634157302, 0.5589899822874727)
Foo(1.3008984188881783, 0.8409580699510877)
Foo(1.6341708040433869, 0.9045141471856328)
Foo(1.321901352224907, 0.9466203120046159)
Ah thanks ;) and sorry for the noise!
Your welcome. It's a common gotcha when using macros in the middle of a line. I also fall for it every now and then.
I need to create copies of
Vector
s of immutable structs and tried to usemap
and@set
with lambdas but it does not seem to work. However, creating a named function and passing it tomap
works:which gives
So I was wondering how to do such vectorised operations?
This one works fine but I'd like to be able to do it without declaring a new function:
giving