You could use apply(op(e), ...) instead of substpart(op(e)...) and args(e)
instead of substpart("[",e,0). I don't think you need to special-case p=1
q=m, either. How about:
rempart(e,n):=block([p,q,argse:args(e)],
if listp(n) then [p,q]:n else p:q:n,
apply(op(e),append(rest(argse,-length(e)+p-1),rest(argse,q))))
This also is consistent with part re. inpart.
-s
On Sat, Sep 1, 2012 at 5:00 PM, Jean-Claude ARBAUT <
jeanclaudearbaut at orange.fr> wrote:
> rempart(e, n) := block([p, q, v, m: length(e)],
>
> if listp(n) then [p, q]: n else p: q: n,
> if p = 1 and q = m then rest(e, q)
> else substpart(op(e), append(rest(v: substpart("[", e, 0), -m + p - 1),
> rest(v, q)), 0))$
>