hide local variables from substitution for a user defined object



On 2013-11-29, Sergey Litvinov <slitvinov at gmail.com> wrote:

> How to work with local variables? My attempt fails.
>
> (%i8) is(inpart(e1, 1)=i);
> (%o8)                                false
> (%i9) is(part(e1, 1)=i);
> (%o9)                                false
>
> It would be nice to respect `listdummyvars'. Currently,
>
> (%i11) block([listdummyvars: false], listofvars(e1));
> (%o11)                                [i]
> (%i12) block([listdummyvars: true],  listofvars(e1));
> (%o12)                                [i]
>
> How to impliment this function?
>
> (%i10) substdummy(j, i, e1);
> (%o10)                 my_sum(j, [j])

The local variables in blex are different from any other variables of
the same name. E.g. x - blex([x], x) => x - x. So subst(i = ...,
blex([i], ...)) doesn't substitute anything because the inner i is
distinct from the outer i. This is the intended behavior; we can
certainly argue about whether it is useful.

It would be useful if there were a function to find such local
variables. For now, the only way to find them is to extract them with
part or args, or return them from the block, for later use. Maybe:

  [my_dummy, e1] : blex ([i], ..., [i, my_sum(...)]);
  subst (my_dummy = ..., e1);

(I didn't try that but I think it should work.)

Hope this helps,

Robert Dodier