1.20 pattern example 15

Replace variable \(x\) in expression with a value \(1\).

L:=[x, x^2,y,z, sin(x), exp( tan(x) )]: 
 
f:=proc(X::anything,x::symbol) 
    local la,y; 
 
    if patmatch(X, conditional( y::anything, _has(y,x) ),'la') then 
        eval(y,la); 
        eval(%,x=1); 
     else 
        X; 
     fi; 
end proc; 
 
map(X->f(X,x),L); 
 
 
     [1, 1, y, z, sin(1), exp(tan(1))]
 

Actually, we do not need patmatch for this, but the above is just an exercise. This can be done in one line in Maple as follows

L:=[x, x^2,y,z, sin(x), exp( tan(x) )]: 
map(X->eval(X,x=1),L) 
 
   [1, 1, y, z, sin(1), exp(tan(1))]
 

In Mathematica

L={x, x^2,y,z, Sin[x], Exp[Tan[x]]} 
L/.x->1 
 
   {1,1,y,z,Sin[1],Exp[Tan[1]]}