How can I prevent an expression from being evaluated in substitution?

I encounter a situation demonstrated in the following piece of codes:

X := `<,>`(1, 2, 3);
T := proc () K[1] end proc;
S := proc (X) subs(K = uneval('X'), eval(T)) end proc;
S(X);
The output is:
                                [1]
                                [ ]
                           X := [2]
                                [ ]
                                [3]

                   T := proc() K[1] end proc

    S := proc(X) subs(K = uneval('X'), eval(T)) end proc

 proc() 'Vector(3, [...], datatype = anything)'[1] end proc

How can I prevent X from being evaluated into a Vector in the substitution in S?

I really expects to get

proc() 'X'[1] end proc

as output of S(X).

 

Thanks!

 

Note:

If I directly run subs(K = uneval('X'), eval(T)) in maple document, I can get the expected result:

proc () 'X'[1] end proc

I really doubt if it is a bug.

A solution found!

<p>Thank you everyone anyway!</p>
<p>I eventually found a solution, to use convert(&quot;X&quot;,symbol) instead of uneval('X').&nbsp; But it does not work in more complex case.&nbsp; Therefore, a solution is still expected.</p>

acer's picture

uneval quotes, evaln

I'm not really sure what you're trying to get.

> X := `<,>`(1, 2, 3):

> T := proc () K[1] end proc:

> S := proc (X::evaln) subs(K = ''X'', eval(T)) end proc:

> g:=S(X);
                          g := proc() 'X'[1] end proc

> g();
                                     X[1]

What is the "more complex case", and what do you wish for it?

acer

Robert Israel's picture

Preventing evaluation

The real problem, I think, that you want your procedure S to be passed the name X rather than the value of X.  Try this:

> S:= proc(Y::uneval) subs(K=Y,eval(T)) end proc;
acer's picture

apparently

According to the original post, he apparently wants,

> S(X);
                            proc() 'X'[1] end proc

Presumably, that really is what he is after.

That won't happen for the S above. But with a few uneval quotes like in subs(K=''Y'',eval(T)) it could. Then it might be a question of whether he'd rather define it as proc(Y::uneval)... or as proc(Y::evaln)...

acer

Thank you, but

I am not passing a name to S. X is a vector in practice, it is the value of X that is intended to be passed.

In fact, the procedure T acts as a template, so that K, in T, is to be replaced by what actually makes T work.  But T has a variable X, which is of the same name as the one in S.  In the process of building new procedure based on T, K need be replaced with an expression involving X.  For example, K may be expected to become X.X or X+X.X.  After that replacement, the new procedure is compiled and run.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}