How was Nothing implemented?
Ok, I failed to find a duplicate so here is my comment:
I don't know how Nothing
is internally implemented but you can do something like this with UpValues
:
nothing /: {a___, nothing, b___} := {a, b}
I would speculate that the internal implementation might build upon Sequence[]
. Consider
{a, b, Sequence[], c, d, Sequence[]}
which evaluates to
{a, b, c, d}
However, to use that in replacement rules, you need to wrap it in Unevaluated
like this
{a, b, c, d} /. c -> Unevaluated[Sequence[]]
which gives
{a,b,d}
P.S. I found out about Sequence[]
from some answer on this site some years ago, but I don't remember which one exactly. I use it since then in all my codes, so that I consider Nothing
just some sort of syntactic sugar (which is also not compatible with older Mathematica versions).