Tag Info

Hot answers tagged

15

This can be relatively easily done using extremely useful $FrontEnd option "ClearEvaluationQueueOnKernelQuit" introduced by Chris Degnen. Usage Print @ $SessionID quitAndEvaluate[ Print @ $SessionID ] 25183094379509806957 25183094575602627552 quitAndEvaluate[] will restart kernel without aby additional tasks. It may be useful if you want ...


11

So recently I've learned from John Fultz that RawBoxes are kind of verbatim indicator for MakeBoxes which is not well stressed out in documentation. This or I've missed the point but it doesn't matter, here we have handy way to do this: x = 5; ToExpression @ MakeBoxes[RawBoxes["x"] = 123]; x 123


7

unevaluatedF = Function[{x}, Unevaluated@x, {HoldFirst, Listable}]; {a1, a2, a3} = {1, 2, 3}; unevaluatedF@{a1, a2, a3} {Unevaluated[a1], Unevaluated[a2], Unevaluated[a3]}


6

I believe Block will work for you here: mem : averageFreeEnergyDensityCompiled["square", n_] := mem = Block[{Part}, Compile[{{j, _Real}, {d, _Real}, {a, _Real}, {h, _Real}, {dx, _Real}, {th, _Real, 2}, {ph, _Real, 2}}, Evaluate[(*apply boundary conditions*) s[i1_, i2_] := Which[i1 == n + 1 && i2 == n + 1, s[1, 1], i1 == ...


6

Here's a try for the first question: reallySameQ[a_, b_] := SameQ[Hold[a], Hold[b]] SetAttributes[reallySameQ, HoldAllComplete] reallySameQ[5, 5] (* True *) reallySameQ[2 + 3, 5] (* False *)


6

Using the answer of belisarius in Setting up diagnostic error messages in large Mathematica projects allows to do exactly what I wanted. $MessagePrePrint = ( #; Print[Stack[_][[;; -5]]]; Abort[]) & t = {t} (*prints the stack and aborts*) Specializing $MessagePrint to only print the Stack in a recursion helps even more for this question. ...


5

This answer is in the same spirit as Kuba's answer, but it avoids conversion between boxes and expressions. Here is our workhorse mark::usage = "Use in combination with markedExpression"; markedExpressify::usage = "Use mark to mark strings for conversion to expressions"; markedExpressify[expr_] := Module[{pos, hCExpr, ext, thr, rLH, expresser}, ...


4

In version 10.1 timings are pretty much as I expected: f1[x_Integer] := x; f2[x_] := x /; x ∈ Integers; f3[x_?IntegerQ] := x; First @ Timing @ Do[#[i], {i, 1*^6}] & /@ {f1, f2, f3} {0.374402, 1.06081, 0.499203} As m_goldberg commented _Integer should be fastest as unlike the others it does not require evaluation; it directly matches the ...


4

Following WReach's fine explanation here one cannot even rely on SameQ to check for identical expressions; instead it seems one needs Order, therefore with holding added: SetAttributes[identicalQ, HoldAll] identicalQ[x_, y_] := Order[Unevaluated @ x, Unevaluated @ y] == 0 Now: identicalQ[2 + 3, 5] identicalQ[5, 5] False True


3

Instead of f @ (g @@ x) you can use f @ Apply[g] @ x (since Mathematica 10). This is more verbose, but it saves parentheses. Since visually matching parentheses is hard, I think that the latter variant is more readable, especially when there's a long chain of functions. This style can be used with postfix too (x // Apply[g] // f) and it makes it easy to ...


3

you can try also: {a1, a2, a3} = {1, 2, 3}; Unevaluated /@ Unevaluated@{a1, a2, a3} (*{Unevaluated[a1], Unevaluated[a2], Unevaluated[a3]}*)


3

This happens because legend items are wrapped in HoldForm to prevent the elements from taking on values: Observe: c = 5; RegionPlot[{x^2 + y^2 <= c, x < 0}, {x, -Pi, Pi}, {y, -Pi, Pi}, PlotLegends -> "Expressions"][[2, 1, 2]] // InputForm {HoldForm[x^2 + y^2 <= c], HoldForm[x < 0]} Without the HoldForm any global values (such as c ...


3

Let me through a first version into the room: SetAttributes[echo, HoldAll]; echo[x___] := StringRiffle[{##}, ", "] & @@ Function[arg, ToString[Unevaluated[arg], InputForm], {HoldFirst}] /@ Hold[x]; Now you get Print[TemplateApply[">``<", echo[2^2, "foo", 2 + 2, None]]] (* >2^2, "foo", 2 + 2, None< *) Be aware that you might ...


2

Perhaps you want PolynomialGCD instead of GCD: PolynomialGCD @@ Denominator@*Together /@ Flatten[mL] (* 32 h *)


2

As @ciao showed you, it is possible to use $AssertionFunction to force Assert into aborting. I don't think this should be done. Just imagine what happens when you publish a package where you change the behavior of Assert. Then, for all people using your package, Assert will no longer work in the expected way. What about implementing your own AbortAssert? ...


2

I think you've found a bug. It seems to me that the Encrypt/Decrypt functionality introduced in 10.1 needs more work. But, I have found that the following work around may help. If you explicitly pass the EncryptedObject properties into an EncryptedObject via its Association parameter, they will be correctly interpreted with no errors. Try this: encryptedObj ...


2

In version 10 even a single Rule will produce a Dispatch object: Dispatch[ a -> 1 ] // InputForm Dispatch[{a -> 1}] Dispatch[ a -> 1 ] // AtomQ True Association is also a hash structure and provides a comparably fast alternative to Dispatch, which an interface for adding, deleting and updating rules. In many cases Associations may be ...


1

First a link to a presentation everyone should read: Working with Unevaluated Expressions - Robby Villegas Now some additional methods: List @@ Unevaluated /@ Hold[a1, a2, a3] Unevaluated /@ Unevaluated @ {a1, a2, a3} More contrived: Unevaluated @@@ Thread @ Hold[{a1, a2, a3}] {Unevaluated /@ Hold[a1, a2, a3]} // ReleaseHold Delete[{Unevaluated /@ ...


1

f1[x_Integer] = x; f2[x_] = x /; x \[Element] Integers; f3[x_?IntegerQ] = x; Timing[f1 /@ Range[10^6];] {0.424561, Null} Timing[f2 /@ Range[10^6];] {0.69525, Null} Timing[f3 /@ Range[10^6];] {0.630597, Null}


1

I know I have answered a very similar question before but I can't find it now. Of what I can find my own question How can I get the unchanged Box form of an arbitrary expression? is probably closest, though more recently Why aren't parentheses ( ) an expression in Mathematica? maybe closer in application to what you need. For pursuing your goal it is ...


1

Here is another alternative, in which the values of the variables are temporarily cleared using Block and an injector pattern. ClearAll[getSymbolNames]; SetAttributes[getSymbolNames, HoldAll]; getSymbolNames[list_Symbol] := Hold[list] /. OwnValues[list] /. Hold[{vars__Symbol}] :> Block[{vars}, SymbolName /@ {vars}] With some planning one might ...


1

As Fred Simons comments NIntegrate has the HoldAll attribute but alone that does not explain this behavior. With the literal assignment z = 1 no NIntegrate::nlim message prints: z = 1; NIntegrate[f[x], {x, 0, z}] Table normally works by the same mechanism as Block, and indeed we see the same behavior from Block: ClearAll[f, x, z] Block[{z = 1}, ...


1

EvaluationNotebook gives the palette Notebook itself; try using InputNotebook instead: CreatePalette[{TextCell["\n1. Choose any file for analysis?", Bold, Blue, 16], Row[{FileNameSetter[Dynamic[cdflocation]], Spacer[20], Dynamic[cdflocation]}], Button["Go!", If[Head[cdflocation] === Symbol, Print["not ready"], (Print["tag should update now"]; ...


1

If you want to add formatting: Format[A[x_, y_]] := Subscript[A, ToString[x] <> ToString[y]] Sum[A[i, j], {i, 1, imax}, {j, 1, jmax}]



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