This question already has an answer here:

Splicing a list of arguments into a function with Sequence

2 answers

Let’s say I have an operation like

Intersection[{1, 2, 3}, {1, 2, 3}, {-1, -2, -9}, SameTest -> (Abs[#1] == Abs[#2] &)]

but the arguments are being handed to me in the form of a list like

a={{1, 2, 3}, {1, 2, 3}, {-1, -2, -9}};

How do I pass a to the Intersection function above?

Intersection[a, SameTest -> (Abs[#1] == Abs[#2] &)]

doesn’t work and neither does

Apply[Intersection[#, SameTest -> (Abs[#1] == Abs[#2] &)] &, a]

What should I be doing?

=================

=================

1 Answer

1

=================

You can use SlotSequence (##) and Apply (@@)

Intersection[##, SameTest -> (Abs[#1] == Abs[#2] &)] & @@ {{1, 2, 3}, {1, 2, 3}, {-1, -2, -9}}

It could be useful to inspect what following lines do:

a = {{1, 2, 3}, {1, 2, -3}, {-1, -2, -9}};

Sequence @@ a

## & @@ a

## & @ a

Sequence @ a

# & @@ a

# & @ a

1

This works as, per the suggestion of b.gatessucks, does a2 = Apply[Sequence, a]; Intersection[a2, SameTest -> (Abs[#1] == Abs[#2] &)]

– Michael Stern

Jul 7 at 19:47