Tag Info

New answers tagged


Clear["Global`*"] g[x_] := x^3 f1[x_] := g[x^2] f2[x_] := g[x^3] Definition@f1 f1[x_] := g[x^2] FullDefinition@f1 f1[x_] := g[x^2] g[x_] := x^3 Head@f1 Symbol Information["f*"] a[1] = 1; a[2] = 2; ?a DownValues@a UpValues@a


A Condition is treated as part of the unique pattern of every assignment, even on the right-hand-side: f := 1 /; foo f := 2 /; bar Definition[f] f := 1 /; foo f := 2 /; bar You are using the notably unusual form: lhs := Module[{vars}, rhs /; test] allows local variables to be shared between test and rhs. You can use the same construction with ...


Let's pretend that f is going to be a function that will see serious use. For such functions, we must consider not only normal use cases, but also edge cases and outright abuse. And we must also consider how f will act in combination with other functions. For this particular case, we might reason that f that, while f[5] may be of little value at top level, ...


You can set f to hold its arguments, like so: ClearAll[f]; SetAttributes[f, HoldAll] f[x_] := x += 2 Then x = 5 f[x] x evaluates to (* 5 7 7 *) You can also use the third argument of Function for this, like so: f = Function[{z}, z += 2, HoldAll]

Top 50 recent answers are included