Globalne Reguły, ciąg dalszy

a=b;
f[x_]:=x^2

Struktury

v=Vector[x,y];
u=Vector[a,b];
VectorX[v_Vector]:=v[[1]]
VectorY[v_Vector]:=v[[2]]

VectorX/@{v,u}

VectorX[Vector[x_,y_]]:=x
VectorY[Vector[x_,y_]]:=y

VectorGet[v_Vector,"X"]:=v[[1]]
VectorGet[v_Vector,"Y"]:=v[[2]]

VectorX[v_Vector]:=v[[1]]
VectorY[v_Vector]:=v[[2]]
VectorLength[v_Vector]:=Sqrt[VectorX[v]^2+VectorY[v]^2]

VectorLength[u]

VectorRotate[v_Vector,angle_]:=Vector@@(RotationMatrix[angle].{VectorX[v],VectorY[v]})

VectorRotate[v,a]

Turtle[{x,y},angle]
TurtlePos[t_Turtle]:=t[[1]]
TurtleAngle[t_Turtle]:=t[[2]]

TurtleMove[t_Turtle,"F"]:=Turtle[TurtlePos[t]+RotationMatrix[TurtleAngle[t]].{0,1},TurtleAngle[t]]
TurtleMove[t_Turtle,"R"]:=Turtle[TurtlePos[t],TurtleAngle[t]+Pi/4]
TurtleMove[t_Turtle,_]:=t

TurtleMove[Turtle[{0,0},0],"R"]
TurtleMove[%,"F"]
TurtleMove[%,"R"]

?VectorX

Lokalne Reguły

c->b
g[x_]:>x^2

?c
?g

r1=(a->b);
r2=(g[x_]:>x^2);
r3=(g[x]->x^2);

?r1
?r2
?r3

{a,b,c}/.r1

{g[x],g[y],g[z]}/.r2

{g[x],g[y],g[z]}/.r3

_Integer=Integer

{1,2,3,a,b,c,1.,1/2}/._Integer->Integer

{1,2,3,a,b,c,1.,1/2}/._Integer->RandomReal[]

{1,2,3,a,b,c,1.,1/2}/._Integer:>RandomReal[]

{1,2,3,a,b,c,1.,1/2}/._Integer->Integer/._Rational->Rational

{1,2,3,a,b,c,1.,1/2}/.{_Integer->Integer,_Rational->Rational}

{1,2,3,a,b,c,1.,1/2}/.n_:>Head[n]

{1,2,3,a,b,c,1.,1/2}/.Except[_List|List,n_]:>Head[n]

fac[n_Integer/;n>0]:=n fac[n-1]
fac[0]:=1

fac[4]

ruleFactorial={
factorial[n_Integer/;n>0]:>n factorial[n-1],
factorial[0]->1};
factorial[4]/.ruleFactorial
%/.ruleFactorial

?factorial

?ruleFactorial

factorial[4]//.ruleFactorial

Hold[x+x]/.x->2