uje
July 15, 2022, 3:15pm
1
In python I could do this and the result will be as follows
>>> a, b, *c, d = [1, 2, 3, 4, 5, 6]
>>>a
1
>>>b
2
>>>c
[3, 4, 5]
>>>d
6
I know there’s unpacking in Julia and know how to use it. But the part where I can pack multiple values into c
as I did in python here is were I can’t figure out yet.
Have any idea?
1 Like
jling
July 15, 2022, 3:22pm
2
1 Like
uje
July 15, 2022, 6:34pm
3
Thank you, can’t wait to have it on board
1 Like
here a rough workaround.
julia> macro splatin(e)
pos=findfirst(el -> !(el isa Symbol), e.args[1].args)
L=length(e.args[1].args)
permute!(e.args[1].args,[1:pos-1...,pos+1:L..., pos])
R=length(e.args[2].args)
permute!(e.args[2].args,[1:pos-1...,pos+R-L+1:R..., pos:pos+R-L...])
return esc(e);
end
@splatin (macro with 1 method)
julia> @splatin (a,b, c..., d) = [1,2,3,4,5,6,7];
julia> a,b,c,d
(1, 2, [3, 4, 5, 6], 7)
DNF
July 20, 2022, 6:25am
5
Nice macro, but shouldn’t it be called @slurp
? Splat is the opposite operation.
ok let’s go with @slurpin