New answers tagged


Short answer The local variables of the form varname$... are used by the system, and it is unwise to use symbols with such names as local variables. With, like many other lexical scoping constructs, performs excessive renamings, often even in cases where it isn't strictly necessary. This probably has to do with efficiency - full analysis may be more costly....


You could do this: Function[{a, b, c, d, e}, Graphics[{{PointSize@Medium, Point[{a, b, c, d, e}]}, Line[{{a,b}, {a,c}, {a,d}, {a,e}, {b,c}, {b,d}, {c, e}}]}]]@@CirclePoints[5] I used a Function to localize the variables and then applied it to the desired points with @@.


The answer is no. The 1st argument of With does not allow destructuring. It only accepts a list of simple assignments. I would rewrite the example you give as Module[{a, b, c, d, e}, {a, b, c, d, e} = CirclePoints[5]; Graphics[ {{PointSize @ Medium, Point[{a, b, c, d, e}]}, Line[{{a, b}, {a, c}, {a, d}, {a, e}, {b, c}, {b, d}, {c, e}}]}]]


tl;dr You need to call Needs before GetBoundaryMesh definition so it can be parsed (found in correct context) correctly or you have to use the full name of ToBoundaryMesh. Relevant part of documentation from SettingUpWolframLanguagePackages Executing a function like Begin which manipulates contexts changes the way that the Wolfram Language ...


This is not a problem peculiar to Module; % won't work in the way you expect in any function definition because it always refers to the last top-level output. Consider, the much simpler g[x_] := (x^2; % + 1) 42 42 g[5] 43 g[5] 44 You see that g ignores the previous evaluation of x^2 and returns the last top-level output increased by 1. ...


I don't see any reason to use Module for what you seem to asking. I suggest g[expr_, var_Symbol] := If[FreeQ[expr, var], $Failed, expr /. var -> var + 1] Then g[n^2, n] (1 + n)^2 g[2 Sqrt[x] + y^x, x] 2 Sqrt[1 + x] + y^(1 + x) but g[a + Sqr[x], y] $Failed


I'd not rely on Module variables after Module's evaluation is done. They have Temporary attribute and it can surprise you later. One way around is to inject Own/DownValues: func[a_] := Module[{primaryOutput, secondaryOutput} , primaryOutput = (Pause@5; 2 a); secondaryOutput := (Pause@2; 0.5 a); Association[ "1" -> primaryOutput, "2" :> ...

Top 50 recent answers are included