# Search Results

Results tagged with Search options user 142
34 results

Questions about how Mathematica evaluates expressions, tracing evaluation (Trace*), handling expressions in unevaluated form (Hold*, Unevaluated), nonstandard evaluation, etc.

is given the HoldAll attribute to delay the evaluation of the arguments until after we have had a chance to process them. It wraps the supplied sequence of symbols in Hold and then uses Replace to …
answered Apr 5 '14 by WReach
You can watch the evaluations of a function using On: SetAttributes[zot, HoldFirst] zot[x_, y_] := {x, y} On[zot] In:= zot[1+1, 2+2] During evaluation of In:= zot::trace:zot[1+1,2+2 … ] --> zot[1+1,4]. During evaluation of In:=zot::trace: zot[1+1,4] --> {1+1,4}. Out= {2,4} Here we can see the original unevaluated arguments to zot and also the partially evaluated arguments …
answered Feb 28 '14 by WReach
: Iteration limit of 4096 exceeded. >> *) To guard against this possibility, we make sure that the last definition only takes effect if the evaluation of its argument actually resulted in a change … themselves HoldAll because Block will temporarily disable that attribute as well, leading to evaluation leaks. It would also be unsuitable if the application will not tolerate the partial evaluation of expressions such as we see in the last example above. …
answered Jan 31 '15 by WReach
Evaluation stops when there is no definition in place whose pattern matches the expression being evaluated. Conversely, evaluation will continue as long as there is a matching definition. Thus, if … I have this definition: zot[x_] := zot[x] and I evaluate zot, the evaluation will never terminate even though the expression never changes. (Well, in principle it will never terminate but …
answered Mar 17 '11 by WReach
prints the tracing information as execution proceeds instead of returning that information in the final evaluation result. Thus, TracePrint meets the stated requirement. However... The output of … the draw, it will crash. Also, the front-end is slow to respond to Abort Evaluation requests when large quantities of output are present. TraceScan TraceScan is an alternative to TracePrint that …
answered Jan 17 '15 by WReach
We can use some of Mathematica's built-in tracing facilities to help us answer this question. Let's start by ensuring that the symbols we are about to use carry no extraneous definitions: ClearAll[f …
answered Jan 28 '15 by WReach
h[e1,e2,...]. The evaluation sequence is described in more detail in Chapter 7 of Power Programming with Mathematica by David B. Wagner. It is freely available to StackExchangers via (16485). When … they self-evaluate. Such symbols are said to be "inert". In the present case, f is inert. As a result, when evaluation gets down to the eleventh step the down-value of f is used to produce the …
answered Oct 11 '16 by WReach
We can define a new "variable container" that can be used to assign the same value to multiple variables: ClearAll[vars] SetAttributes[vars, HoldAll] vars /: s:(_vars = _) := CompoundExpression @@ Th …
answered Jan 21 '12 by WReach
. Responding to the Updated Question If we wish to update the original variables, we need to prevent the evaluation of the individual variables. For example: Scan[Function[Null, PrependTo[#, {"A", "B … programs the chance for so-called "evaluation leaks" to spring up grows quickly. All of the built-in destructive operators (like PrependTo, Set, SetDelayed etc) require held arguments. In other …
answered Mar 8 '17 by WReach
I agree with @Ymareth that the simplest thing would be to have the calling notebook take explicit measures to communicate the context to the target notebook. However, if for some reason it is undesir …
answered Dec 1 '14 by WReach
Short Version The behaviour we see is by design. It is due to the fact that we are using the special head Evaluate to force early evaluation of the second argument of CompoundExpression -- an … wrap the second expression within Evaluate, it is evaluated before the compound expression itself is evaluated: Print["one"]; Evaluate[Print["two"]] (* two one *) After that early evaluation and …
answered Jan 8 by WReach
discarding some of the trace information. TraceScan provides more information since it calls a user-specified function at the start and end of every evaluation. Two functions are defined below that try to … format the TraceScan information in (somewhat) readable form. traceView2 shows each expression as it is evaluated, along with the subevaluations ("steps") that lead to the result of that evaluation
answered Apr 3 '11 by WReach
] \$myAccumulator (* <|runningSum->5050|> *) Beware that this simple redefinition of partial still contains an evaluation leak. While the curried arguments are correctly preserved unevaluated …
answered Aug 18 '14 by WReach
We can explore the evaluation sequence using TraceScan. Let's start by defining a helper function, watch, that presents the results of TraceScan in a convenient form: ClearAll[watch] SetAttributes … , args]]] ; exit[args__] := With[{d = --depth}, fn[Hold["exit", d, args]]] ; TraceScan[enter, expr, _, exit] ] Now, let's look at the evaluation of q from the supplied use cases: In := watch[q …
answered Jan 21 '12 by WReach
the original definition to unwrap the association object during the initial evaluation and to recreate it upon use. We do that using Normal@URLParse[...] and Inactive[URLBuild@*Association]. The …
answered Aug 2 by WReach
A simple way to inject the value of expression into the unevaluated LinkWrite argument is to use With: Clear[bar] expression = Hold[bar = 3]; bar (* bar *) With[{x = expression}, LinkWrite[newK …
answered Sep 10 '15 by WReach
As @image_doctor notes in a comment, the problem occurs because the definition of TestPrivatefQ is not being distributed to the other kernels. DistributeDefinitions uses Language`ExtendedFullDefini …
answered Jan 31 '15 by WReach
The term pure function used in Mathematica is not being used in the same sense as the cited Wikipedia article. In Mathematica it refers to an anonymous function. In the Wikipedia article it is a ter …
answered Nov 1 '14 by WReach
If we are the ones writing the package in question, then we could proceed as follows. First, we define a public version of the function that delegates all calls to a private version: ClearAll[public …
answered Mar 11 '12 by WReach
I agree with the comment by @march that using an indexed list would simplify things nicely. However, if we wish to press on with named lists then one way would be to create a list of functions that e …
answered Jan 7 '16 by WReach
[1 + 1]]] (* a :> 1 + 1 *) This is different from the normal evaluation process which only strips one level: ClearAll[f] f[x_] := x f[Unevaluated[Unevaluated[Unevaluated[1 + 1]]]] (* Unevaluated …
answered Aug 18 '16 by WReach
The behaviour we see is due to the precedence of &, which is much lower than the precedence of /@. As a consequence, the expression Line /@ (Print[#]; #) is bound tightly together by the high precede …
answered Jan 3 '15 by WReach
Here are a couple of alternatives to Trott-Strzebonski in @R.M's answer: Hold[{3,4,5|6}] /. Verbatim[Alternatives][x__] :> RuleCondition@RandomChoice@List@x Hold[{3, 4, 5}] Hold[{3,4,5|6}] / …
answered Mar 7 '12 by WReach
Which one we use depends upon what we are trying to determine. If our goal is to measure algorithmic time complexity, Timing (used carefully) is the tool. If we want to measure how long a computatio …
answered Nov 5 '12 by WReach
[{cache} , m:cache[x_] := m = longCalculation[x] ; f[x_] := Module[{r = cache[x]}, r /; r < 8] ] Here is a sample use: In:= f /@ Mod[2Range, 10] During evaluation of In:= calculating … value for 2 During evaluation of In:= calculating value for 4 During evaluation of In:= calculating value for 6 During evaluation of In:= calculating value for 8 During evaluation of In:= calculating value for 0 Out= {2,4,6,f,0,2,4,6,f,0,2,4,6,f,0,2,4,6,f,0} …
answered Jan 24 '12 by WReach
One way to achieve this is to use a "vanishing" wrapper. The idea is to temporarily wrap the substituted expression with a holding symbolic head, and then remove that head in a second replacement: M …
answered Feb 28 '14 by WReach
Prior to version 10 of Mathematica, there was a menu option Evaluation / Interrupt Evaluation... with the hot-key ALT-, (comma). This would temporarily suspend the current evaluation in progress … . The bad news is that this menu item is gone. The good news is that the hot-key still works in versions 10 and 11. The sequence of events is as follows: Start a long-running evaluation. At some …
answered Jan 22 '17 by WReach
ReplacePart did not work with associations in versions 10.0.0 and 10.0.1, but it does as of version 10.0.2. The proposed expression shown in the question will work in 10.0.2 (after making the minor …
answered Dec 15 '14 by WReach
How about this: list = {1, 2, 3}; ToExpression["list", InputForm, Hold] /. Hold[v_] :> AppendTo[v, 3] {1, 2, 3, 3} list {1, 2, 3, 3}
answered Mar 6 '12 by WReach
RuleCondition provides an undocumented, but very convenient, way to make replacements in held expressions. For example, if we want to square the odd integers in a held list: Hold[{1, 2, 3, 4, 5}] /. …
answered Oct 6 '11 by WReach

15 30 50 per page