Not sure if this has been asked, but I have a fairly simple operation that I don't know the syntax for. Say I have an array with some values, and a function f that accepts an arbitrary number of arguments. The following:
array = {e,f};
f[a, b, c, d, array];
...is functionally equivalent to:
f[a, b, c, d, {e, f}];
OK, will Sequence help? Nope, this does the same thing:
f[a, b, c, d, Sequence@array];
Essentially, I want to include e and f into the list of arguments, i.e. I want to know the syntax for telling Mathematica I want it to evaluate this:
f[a, b, c, d, e, f];
How do I go about doing this?
Answer
Sequence
means more or less "no head". What you want to do is to remove the head List
from an inner list. Or, put in another way, you want to replace this head with "no head". The operation that changes one head to another is Apply
. Therefore, what you really want is
f[a, b, c, d, Sequence @@ array]
where @@
stands for Apply
.
Comments
Post a Comment