I seem to lack understanding the combination of an \edef and the definition of a macro inside another definition. This is probably best shown with an example.
The following MWE (I know it is not really useful so minimal) does not work:
\documentclass{article}
\def\mymacro#1{%
\def\do##1{##1}%
#1%
}
\begin{document}
\edef\savedValue{\mymacro{argument}}%
savedValue: \savedValue
\end{document}
The error is in the \edef line and states Illegal parameter number in definition of \savedValue.
I thought that the \edef would expand \mymacro{argument}, which first expands \def\do##1{##1} to nothing leading to the output argument, which is then saved into \savedValue. Without the line \def\do##1{##1} this seems to work as explained, but with that line I get the mentioned error.
What is the problem here?
Using xparse's command does work
\documentclass{article}
\usepackage{xparse}
\NewDocumentCommand{\mymacro}{m}{%
\def\do##1{##1}%
#1%
}
\begin{document}
\edef\savedValue{\mymacro{argument}}%
savedValue: \savedValue
\end{document}
and gives the expected output: 
What is the actual difference to using \def?