Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Favorites infavorites:mine
infavorites:1234
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with Search options user 142

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

7
votes
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
9
votes
You can watch the evaluations of a function using On: SetAttributes[zot, HoldFirst] zot[x_, y_] := {x, y} On[zot] In[11]:= zot[1+1, 2+2] During evaluation of In[11]:= zot::trace:zot[1+1,2+2 … ] --> zot[1+1,4]. During evaluation of In[11]:=zot::trace: zot[1+1,4] --> {1+1,4}. Out[11]= {2,4} Here we can see the original unevaluated arguments to zot and also the partially evaluated arguments …
answered Feb 28 '14 by WReach
3
votes
: 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
26
votes
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[1], 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
13
votes
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
13
votes
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
5
votes
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
17
votes
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
7
votes
. 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
4
votes
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
3
votes
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
77
votes
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
5
votes
[100]] $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
15
votes
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[10] := watch[q …
answered Jan 21 '12 by WReach
10
votes
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
4
votes
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
4
votes
As @image_doctor notes in a comment, the problem occurs because the definition of Test`Private`fQ is not being distributed to the other kernels. DistributeDefinitions uses Language`ExtendedFullDefini …
answered Jan 31 '15 by WReach
19
votes
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
14
votes
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
2
votes
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
10
votes
[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
10
votes
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
24
votes
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
51
votes
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
11
votes
[{cache} , m:cache[x_] := m = longCalculation[x] ; f[x_] := Module[{r = cache[x]}, r /; r < 8] ] Here is a sample use: In[61]:= f /@ Mod[2Range[20], 10] During evaluation of In[61]:= calculating … value for 2 During evaluation of In[61]:= calculating value for 4 During evaluation of In[61]:= calculating value for 6 During evaluation of In[61]:= calculating value for 8 During evaluation of In[61]:= calculating value for 0 Out[61]= {2,4,6,f[8],0,2,4,6,f[8],0,2,4,6,f[8],0,2,4,6,f[8],0} …
answered Jan 24 '12 by WReach
13
votes
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
7
votes
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
4
votes
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
21
votes
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
75
votes
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