Tag Info

New answers tagged

4

Caveat Instead of answering your question I am going to try to convince you not to do what you are describing. While it is true that Mathematica is highly configurable in many areas there are nevertheless paradigms and principles that are best heeded. You did not give an example of where or why you feel a usage message is needed so it is difficult to ...


1

rcollyer provides the literal answer to your question in his answer. Another way to do it is simply to give f the HoldFirst attribute and make it take an additional first argument, namely the symbol you want to link the message to, i.e. v. Then you can do v::usage="bla" and v=value inside the definition of f, and just call it like f[v,...] instead of ...


4

As follows, are three different methods to answer your question. They each have there merits and flaws. The first is a literal attempt to do as you ask, but it requires modifying the behavior of a System` function to do it. The second method deviates from what you ask by using a different binary operator for the assignment, but still links a message to the ...


5

As you've seen, a definition like u = u[x,y,z] is not generally appropriate in Mathematica because the principle of the Mathematica evaluator is to repeatedly apply all known definitions to an expression until the result no longer changes. Here, the recursive definition is repeatedly applied, with no termination condition. If you're just looking for a ...


2

Map[(f[# - 1] := #) &, Range[3]]; f[n_] := f[n] = f[n-1] + f[n-2] + f[n-3]; Or alternatively: (f[#-1]:= #)&/@Range[3]; f[n_] := f[n] = f[n-1] + f[n-2] + f[n-3]; Just in one line: f[n_] := If[MemberQ[Range[0, 2], n], n + 1, f[n - 1] + f[n - 2] + f[n - 3]];


7

Some version of the following might be useful: ClearAll[f]; Evaluate@Thread[f[{0, 1, 2}]] := {1, 2, 3}; In this case you could also use Set instead of SetDelayed (:=), because the arguments are "atomic", not patterns. Both = and := hold their first argument unevaluated by default, so that a construct like Thread as I am using it above will only work in ...



Top 50 recent answers are included