9,355 reputation
11840
bio website
location
age 27
visits member for 1 year
seen 10 hours ago
stats profile views 328

May
17
comment Flat function with repeated sequence
You mean something like adding the definition JoinH[a_, b_, rest___] := joinH[a, JoinH[b, rest]]?
May
16
comment Dynamic Updating CreateDialog Problem
In the first example you give, you can close the dialog. It just so happens a new one is created whenever you close an old one. You can notice this through the names changing in the output. In the second case, you forgot your Dynamic around CreateDialog if that was what you are asking about. Perhaps you are simply looking for CreateDialog[Dynamic@y] ?
May
9
comment Conditionals slower than operators?
I understand that you just delete the output, but why are you timing how long it takes to print 4000 numbers? If you have any sort of real usage, where you need to show the user 4000 numerical values you would never print them one at a time to the notebook. It seems like a very odd example.
May
9
comment Conditionals slower than operators?
What are you trying to accomplish? I'm assuming that the goal of your function isn't to print out 4000 numbers to the notebook, In that case you should provide a better example since almost all the time spent here is used by the print statements.
May
6
comment Refresh dynamic variable when used with Get
I always figured that Update was intended to be used exactly in situations like this, however it doesn't seem to work.
May
2
comment Instruct a Table to only evaluate until a condition is fulfilled
In the general case you are not guaranteed that you can perform your limit test globally, and you are left in the situation that calculating the range of elements you would want to iterate is effectively the same as iterating them. Though for the model case given this is naturally not the situation. As for this case, I think the results will depend greatly on how large you make your table, and you didn't really make it all that large.
May
2
comment Instruct a Table to only evaluate until a condition is fulfilled
@LeonidShifrin Thanks, I've added a block to scope the variable, and I simply forgot the attribute.
May
2
comment Instruct a Table to only evaluate until a condition is fulfilled
I've added a NestWhileList solution to my answer to show what I mean. The solution is much more concise, yet it still doesn't actually use any of the iteratively passed on results for anything other than book keeping.
May
2
comment Instruct a Table to only evaluate until a condition is fulfilled
Well that really was my point. You don't need this particular recursion pattern, but you chose it as a method of collecting results and thus end up using a loop constructor not because it fits the problem but because it fits your chosen method of collecting results. This seems counter productive, at the same time if you really wanted a "functional" style solution you should arguably have used a fixed point iteration since you don't want a fixed number of iterations but a short circuit iteration, thus you should have used either FixedPoint or NestWhile not fold.
May
2
comment Instruct a Table to only evaluate until a condition is fulfilled
In my opinion this seems like a very counter productive solution. Fold is used as the loop constructor, but not because it nicely fits the problem, rather you needed to build a heap of scaffolding around it to make it work. The typical use case of fold is a loop where each iteration depends on the output of the last, which is not the case in this problem, every iteration depends only on the state of the iterators, and the only problem to solve is how to allow short circuiting.
May
2
comment Cusom PopupMenu file selector
@halirutan Thanks for correction, it should be system independent now.
Apr
23
comment Going full functional (Haskell style)
Very cool and simple "currying" definition. You can add something like MakeBoxes[Function[arg_, f[a__, arg_], HoldAll], StandardForm] := RowBox[{"f", "[", Sequence @@ Riffle[{ReleaseHold[ Function[x, ToString[Unevaluated[x]], HoldAll] /@ Hold[a]]}, "]["], "]"}] to make it still look simple as long as it's still gathering parameters. I suspect it could be achieved in a more elegant fashion, but it demonstrate the idea.
Apr
17
comment How to use Show in case one of the graphics doesn't exist?
@Mr.Wizard That's great for cases where your plot function will return either a valid graphics or {}, but in the general case it's nice to be able to perform an arbitrary check. Though you could replace Unevaluated[Sequence[]] with {}. That's just my personal preference.
Apr
15
comment Kramers-Kronig Mathematica code
Am I understanding you correctly that alpha is a function of h, and you want to integrate over h? If that is the case you are a bit off track. NIntegrate numerically integrates an analytical expression, it's not an integration over list elements. Though it will happily integrate each expression in a list, but that's quite different from integrating over it.
Mar
25
comment Fortran kind of matrix creation
Have you looked at the docs for the Do command?
Mar
17
comment Confusing efficiency and evaluation when returning pure functions?
Seems you can avoid all your trouble by just using the Evaluated->True option of Plot.
Mar
6
comment Problem with creating a large list of tuples
Ahh, seems that by "inappropriate" it means that the bound is to large. It works up to n=16 so it's properly just to large for it to work with. Try running a while loop instead, and again I would advice trying to estimate total run time by running a smaller number of iterations.
Mar
6
comment Problem with creating a large list of tuples
That error message seems to suggest that you haven't defined n meaning that the iterator doesn't have appropriate bounds since it doesn't know what (n-1)^(n+1) is. You should make sure you have set n to a value when you do this loop.
Mar
5
comment Problem with creating a large list of tuples
You misspelled the function. It's LazyTuple not LazyTuples, and while such an evaluation will take quite a while to finish due to the 37,589,973,457,545,958,193,355,601 iterations it needs to go through, it should be possible as long as you are not using up to much memory in your func calls. I would suggest you start out trying to calculate how long it should approximately take before just blindly running the code and waiting though.
Mar
5
comment Problem with creating a large list of tuples
Yes. If you go from the code in that question you could simply do allmyTuples=lazyTuples[Range@20,19]; which will not actually calculate them all yet, then if you call for instance allmyTuples[[21312312841789283727]] it will return only that one tuple, without having calculated all the others. If you want to iteraet over the tuples, the length can be found by calling Length[allmyTuples].