# Tag Info

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}

7

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. ...

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 ...

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}

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 ...

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 ...

4

Using the ideas of Tobias and Joe, I've written a function that allows to evaluate a function on a parallel kernel while keeping the main kernel free for other things, and a callback is called with the result of the computation on the parallel kernel as argument. This basically is asynchronous programming. I've spent a lot of time debugging this and it was ...

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 ]

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[] &; ...

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]] ...

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]]

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[{ ...

3

Or you can use RawBoxes: PasteButton[ RawBoxes @ First @ Names["Global*"] ]

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 ...

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 ...

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]]

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 ...

Only top voted, non community-wiki answers of a minimum length are eligible