# Preventing evaluation until all undefined symbols are resolved

FixedPoint[If[# <= 0, 0, # - 1]&, 2 x]


Causes an infinite loop because of 'x'. How do i automatically prevent evaluation until 2 x is known? I have a similar function being fed into Plot[] and it has control over when x is known.

-

This question leaves us all guessing, but my guess is that you want a combination of the answers already given. I think you want to test the second argument of FixedPoint and only evaluate when this is numeric. You could use:

fp[function_, start_?NumericQ] := FixedPoint[function, start]


Now this halts evaluation:

expr = fp[If[# <= 0, 0, # - 1] &, 2 x]

fp[If[#1 <= 0, 0, #1 - 1] &, 2 x]


But after x is given a numeric value:

x = 5;
expr

0


Interaction with Plot with a modified function:

Plot[fp[If[# <= 0, #, # - 1] &, 2 z], {z, 0, 3}]


-

Your use-case is not really clear. When you simply define a function from your expression, you can control that it is called with any expression which makes sense

myFixedPoint[x_] := FixedPoint[If[# <= 0, 0, # - 1] &, 2 x]


Let's say now you have an expression for x which doesn't end in an infinite loop, you can call

y = 3;
myFixedPoint[7 y]

(* 0 *)

-

ClearAll[x]
f[x_] := FixedPoint[If[# <= 0, 0, # - 1] &, 2 x ];
myFixedPoint = Function[x, If[NumberQ[x], f[x], Undefined]];

myFixedPoint[x]
myFixedPoint[123.4]
x = 123.4
myFixedPoint[x]


with output

Undefined
0
123.4
0

-