Example:
f[x_] := f[x] = (If[x < 0, Return[x]]; x)
f[1];
f[-5];
DownValues[f][[1 ;; 2]]
(* {HoldPattern[f[-5]] :> Return[-5], HoldPattern[f[1]] :> 1} *)
I want it to save the value that is returned, without the Return[]
. In case it matters, the actual function looks something like this:
f[list_,n_] := f[list,n] = Block[{li = list, moreVars},
Which[
n == 0, Return@li,
li[[i1]] > 0, li[[i1]]--,
li[[i2]] > 0, li[[i2]]--,
True, Return@li
];
f[li, n - If[bla, 2, 1]]
]