# Tag Info

8

I think the reason, at least primarily, that it works differently for Plus is the following from its documentation: Unlike other functions, Plus applies built-in rules before user-defined ones. It may seem a little obscure, because perhaps we don't know all the rules, but these two are mentioned explicitly: Plus[] is taken to be 0. ...

4

I suppose this is what you need. So the first thing is to use Module since With injects values into held expressions. Moreover PrePrint is probably to late to catch "5+7". So I'd go with $Pre:$Pre = Function[expr, Module[ {expr$= ToString[Unevaluated[expr], InputForm]}, MSPToExpression[expr$] ], HoldAllComplete ]

0

I don't have any points to comment on Daniel W's answer. But here's how you write this z[[1]]/z[[2]] /. z -> zz to not generate any part errors Indexed[HoldForm[z], 1]/Indexed[HoldForm[z], 2] /. HoldForm[z] -> zz Out[1]=3/4

1

Ad 1 After commenting the second definition, fun[x,y] was evaluated and left in this form since no definition was provided for symbolic arguments. Then the replacement was done and tutorial/Evaluation says: [...] in evaluating an expression like h[e1, e2, ...]. Every time the expression changes, the Wolfram Language effectively starts the evaluation ...

6

It doesn't seem to be possible with EvaluationCompletionAction but you can wrap input with custom function using $PreRead and friends:$Pre = Function[expr, Module[{start, result}, start = AbsoluteTime[]; result = expr; If[AbsoluteTime[] - start > 2, Speak @ "wow, it took at least 2 seconds"]; result ], HoldAll ] I'm using ...

0

Another way is to store each part of the list using memorization and then call the part you want. Quit[]; i = 1; (f[i++] = #) & /@ (lis = {x + y, If[x > 0, Pause[5]], Sin[x] y + Exp[y], x^2 y}); Now try this and check the difference in time. x = 1; f[1]; lis[[1]];

0

The problem is the function you want to invert becomes complex out of range. Here are a couple of approaches: With[{d = 10^-4, r = 10^-8, s = .005, L = 16, n = 10^6}, f[y_] := -((L s)/(d Log[s/(y r)])) ProductLog[-1, -((d y Log[s/(y r)] n^(1/L) (s/(y r))^-((d y)/(L s)))/(L s))]; myh[x_] := y /. FindMinimum[Abs[f[y] - x], {y, 10}][[2, ...

5

If you define lis before x and y as a plain List you can use the following trick with OwnValues ClearAll[x, y]; lis = {x + y, x y, Sin[x] y + Exp[y], x^2 y}; x = {1, 2, 3, 4, 5}; y = {3, 4, 5, 6, 7}; Part[Hold@lis /. OwnValues@lis, 1, 1] (* {4, 6, 8, 10, 12} *) Indeed, it calculates the first element only: Part[Hold@lis /. OwnValues@lis, 1, 1] // Trace ...

9

You could map Hold over the list:- lis = {x + y, x y, Sin[x] y + Exp[y], x^2 y}; heldlis = Map[Hold, lis]; x = {1, 2, 3, 4, 5}; y = {3, 4, 5, 6, 7}; ReleaseHold@heldlis[[1]] {4, 6, 8, 10, 12}

6

Is there a simple way to take and evaluate a specific part of a list without evaluating the rest? You could use the Rule[] rather than Set[]. For instance, lis = {x + y, x y, Sin[x] y + Exp[y], x^2 y}; lis[[1]] /.{x -> {1, 2, 3, 4, 5}, y -> {3, 4, 5, 6, 7}} {4, 6, 8, 10, 12}

0

Example: DynamicModule[ {font = "Courier"}, EventHandler[ Style["Text", FontFamily -> Dynamic[font]], {"KeyDown", "x"} :> (font = font /. {"Times" -> "Courier", "Courier" -> "Times"})] ] On press of button x text "Text"toggles between font "Times" and "Courier"

3

It seems to me now that my conjecture was too simple. Here is an example that shows that we might need Refresh inside a Dynamic that is visualized on the screen in a DynamicBox. The crucial point is that this DynamicBox is displayed in a DynamicModuleBox, which has an effect on the updating procedure. Consider the following example: Panel[Column[{ ...

1

Each Dynamic is using preemptive link and it is theoretically possible to do what you need. However, there are no tools to manage evaluation precisely (one could try with FinishDynamic[]). At the moment you are using one link which is busy so it can't update second Dynamic. You can't count on specific order of tasks but you can send one to main link by ...

4

On[Assert] $AssertFunction := ( (*1*) SelectionMove[EvaluationNotebook[], All, Notebook, AutoScroll -> False]; FrontEndExecute @ FrontEndToken @ "RemoveFromEvaluationQueue"; SelectionMove[EvaluationCell[], After, Cell, AutoScroll -> False]; (*2*) RunScheduledTask[$Pre =., {1}]; $Pre = Abort[] &; ... 3 Or you can use RawBoxes: PasteButton[ RawBoxes @ First @ Names["Global*"] ] 4 You could use ToExpression to convert the string to a symbol, with Defer as the third argument: symbolname = First@Names["Globalmy*"] (* "myList" *) PasteButton[ToExpression[symbolname, InputForm, Defer]] 1 Provide name as a String and use one of those methods to assign the value: How do you programatically load data into symbols? Manipulate[x, {{variablename, "test", "variable name"}, (InputField[#, String] &)}, {{x, x1, "value"}, ControlType -> InputField}, Button["save", ToExpression[variablename, StandardForm, Function[name, name = x, ... 1 This will work so long as you don't try to assign a variable that already has an assignment Manipulate[x, {{variablename, defaultname, "variable name"}, ControlType -> InputField}, {{x, x1, "value"}, ControlType -> InputField}, Button["save", Evaluate[variablename] = x]] 0 It sounds like you want to inspect the stack when an assertion fails. Will Dialog do what you want? As in$AssertFunction:=Dialog[] As already mentioned however, cells queued for evaluation, and even subsequent lines in the current cell, will still execute when you Return or ExitDialog. You can ExitDialog[Unevaluated[Abort[]]] to abort a statement, but ...

5

This is another problem that used to be kind of a pain back before Mathematica 10, but is now dramatically simplified by Associations and the related functions: CompareRows[tables:{___List}] := MapThread[SortBy, {(Apply[Join]) @* Values /@ KeyIntersection[GroupBy[First] /@ tables], PositionIndex /@ tables}]; The SortBy/PositionIndex ...

4

Using DialogInput instead of CreateDialog DialogInput[ Grid[{{"Year:", InputField[Dynamic[yyyy], Number]}, {"Month:", InputField[Dynamic[mm], Number]}, {"Day:", InputField[Dynamic[dd], Number]}, {CancelButton[], DefaultButton[ DialogReturn[{Year = yyyy, Month = mm, day = dd}]]}}, Spacings -> {1, Automatic}, Alignment -> Left]] ...

1

You can use Block inside body of f function to temporarily set desired symbols to those passed as arguments of f. ClearAll[argument, f, test] argument = {xx, yy, zz}; test[t_] := {argument^2, Range[t]} f[kx_, ky_, kz_, t_] := Block[{xx = kx, yy = ky, zz = kz}, test[t]] f[a, b, c, 4] (* {{a^2, b^2, c^2}, {1, 2, 3, 4}} *) Alternatively you could first ...

Top 50 recent answers are included