Tag Info

Hot answers tagged

30

Internal`InheritedBlock (IIB) is similar to Block, except that it preserves the original definition of the function being passed to it. The function can then be modified as we wish inside the IIB without affecting the external definition. Let's see how Block works first: f[x_] := x Block[{f}, Print@DownValues[f]; f[x_, y_] := x y; ...


26

I am somewhat reluctant to offer this as an answer since it is inherently difficult to comprehensively address questions on undocumented functionality. Nonetheless, the following observations do constitute partial answers to points raised in the question and are likely to be of value to anyone trying to write practical compiled code using Bags. However, ...


15

This is not related to evaluation. Internal`Bag, like many other special types, is an atomic object. You can verify this using AtomQ[x]. This is despite its InputForm suggesting a structure. This is no different from how Graph, Rational, Complex or SparseArray behave. (Though for SparseArray, most list manipulation functions are implemented, so it's ...


12

About your question regarding the definition of the type of local variables in Compile, Compile has an optional third argument that allows you do this in the same manner you specify arguments. It helps the compiler solve some type ambiguity issues sometimes as by default a local variable is considered a Real number. This can be the case if a local variable ...


8

As a starting point I'll write up what I found about these functions before. I'm hoping someone will take a better look at them and will write a more complete answer. Spelunking in version 8, Internal`AddPeriodical[Print["boo!"], 3] Now you get a boo! every 3 seconds. Internal`Periodicals[] (* ==> {Print["boo!"]} *) Now do ...


7

I think Internal`Bag is a monolithic object which is only constructed using the Bag[list] syntax. Note that the same is true for Graph: Graph[{1<->2,2<->3}]//Head (* ==> Graph *) Graph[{1<->2,2<->3}]//Depth (* ==> 1 *) Also note the output of the objects when typing directly in the kernel: Internal`Bag[{2,3}] (* ==> ...


5

You can turn this then into a package, and change the lower-case to uppercase... Hope it works well enough for your goals. If not, we'll improve it in time AppendTo[$ContextPath, "Internal`"]; ClearAll["`private`*"]; SetAttributes[`private`count, HoldRest]; `private`count[_, expr_, count_Symbol][id_, ___] /; Block[{$scheduledTask = `private`getST[id]}, ...


4

I don't know about temporary values, but if you want to monitor the progression of Nest you could use the following: intensiveCalculation[x_] := (Pause[0.5]; x + 1) Nest[(PrintTemporary[#]; #) &@ intensiveCalculation[#] &, 1, 5]



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