\errorcontextlines=100
\documentclass{article}

\usepackage{xfor}

\makeatletter
% \insertinto{new value}{list}
\newcommand{\insertinto}[2]{%
\def\nlst{}%
\@for\n:=#2\do{%
% store new list in \toks@
\expandafter\toks@\expandafter{\nlst}%
% test current value against new value
\ifnum\n>#1\relax
  \edef\newstuff{\number#1,\n}%
  % end for loop at the end of this iteration
  \@endfortrue
\else
  \edef\newstuff{\n}%
\fi
% append new stuff to new list
\ifx\nlst\@empty
  \edef\nlst{\newstuff}%
\else
  \edef\nlst{\the\toks@,\newstuff}%
\fi
}%
% check to see if for loop was prematurely terminated
\if@endfor
 % loop may have been terminated during final iteration, in
 % which case \@forremainder is empty.
 \ifx\@forremainder\@empty
   % do nothing
 \else
   % loop prematurely ended, append remainder of original list
   % to new list
   \expandafter\toks@\expandafter{\nlst}%
   \edef\nlst{\the\toks@,\@forremainder}%
 \fi
\else
 % wasn't prematurely terminated, so new value hasn't been added
 % add now.
  \expandafter\toks@\expandafter{\nlst}%
  \ifx\nlst\@empty
    \edef\nlst{\number#1}%
  \else
    \edef\nlst{\the\toks@,\number#1}%
  \fi
\fi
\global\let#2=\nlst
}

\newcommand{\insertionsort}[1]{%
\def\sortedlist{}%
\@for\val:=#1\do{{\insertinto{\val}{\sortedlist}}}%
\let#1=\sortedlist}
\makeatother

\begin{document}
\def\mylist{1,2,5,9,12,15,18,20}%
\def\newval{11}%
Original list: \mylist. New value: \newval.

\insertinto{\newval}{\mylist}
New list: \mylist.

Unsorted list:
\def\mylist{4,2,7,1,10,11,20,15}\mylist.

\insertionsort{\mylist}%
Sorted list: \mylist.
\end{document}
