I just considered if/how one could implement Sequence in Mathematica if it were not predefined. It turned out that the following simple definition has in all my tests exactly the right behaviour:
myseq /: f_[x___, myseq[y___], z___] := f[x, y, z]
Now my question: Does this already correctly reproduce the full behaviour of Sequence, or is there something Sequence does but myseq doesn't which I missed in my tests?
Here's what I tested:
foo[myseq[a, b]]
(*
==> foo[a, b]
*)
Hold[mysec[a,b]]
(*
==> Hold[a, b]
*)
HoldComplete[myseq[a,b]]
(*
HoldComplete[myseq[a, b]]
*)
Hold[f[myseq[a,b]]]
(*
==> Hold[f[myseq[a, b]]]
*)
f[myseq[myseq[a,b],c,d],e,myseq[f,g,myseq[]]]
(*
==> f[a, b, c, d, e, f, g]
*)

myseqfails is for something like{1, 2, 3} /. 2 -> myseq[a, b]. – Heike Jun 18 '12 at 18:57t = {{a, b}, {c, d}, f}; myseq @@tfails – belisarius Jun 18 '12 at 18:58SequenceHoldlikeSequncedoes. – Szabolcs Jun 18 '12 at 18:58myseq[1,2]does the same. It may also be due to the lack ofSequenceHoldsupport. EDIT: it's not. Support can be added withmyseq /: f_[x___, myseq[y___], z___] /; FreeQ[Attributes[f], SequenceHold] := f[x, y, z]– Szabolcs Jun 18 '12 at 19:00