Reputation
66,378
Next tag badge:
209/100 score
19/20 answers
Badges
6 195 286
Newest
 Nice Answer
Impact
~420k people reached

Feb
9
comment Is Table the only functional way to construct nested loops in Mathematica?
@jVincent Yes, that's true. I have a habit of working with indices,but here they don't bring much of an advantage. Will edit your suggestion in, thanks.
Feb
9
revised Is Table the only functional way to construct nested loops in Mathematica?
added 86 characters in body
Feb
9
answered Is Table the only functional way to construct nested loops in Mathematica?
Feb
8
comment Interrupting package evaluation, handling error
@Murta Catch and Throw are exactly the right tool for this. Good luck with this! Have a look also at this answer of mine. And one more thing: although I don't advocate this, and never really used it for anything serious, you may in really simple cases try GoTo and Label for the scripts. This is a really cheap way to avoid writing functions. Don't take it as my recommendation, but for small scripts this may work, at least as a first, quick and dirty version.
Feb
8
comment Splicing a list of arguments into a function with Sequence
@SimonWoods Thanks :-). I came up with this when writing a book, so just borrowed from there.
Feb
8
comment Interrupting package evaluation, handling error
@rcollyer I agree. But decisions such as at which level which exceptions are handled are in any case a part of a design. Moreover, usually this comes out more or less automatically once you have some experience with this.
Feb
8
comment Interrupting package evaluation, handling error
@rcollyer Finally, for certain languages (such as Scheme) which support continuations, there is a resume mechanism. Even in Java, I suspect this is still possible if one really wants, since one can access the execution stack via reflection (although I personally did not use this much).
Feb
8
comment Interrupting package evaluation, handling error
@rcollyer In other words, most important is the right separation between different modules, and loose coupling. Besides, the developers of a given module have to make sure that they do all the clean-up work so that exceptions they throw don't leave their module in some invalid state. There is a big debate which exceptions must be checked (compile-time) and which must be run-time, here there are different opinions. I personally think that checked exceptions are good because this is documented in method's signatures, although some exceptions should be run-time.
Feb
8
comment Interrupting package evaluation, handling error
@rcollyer Well, when I was dealing with exceptions during my work in industry with Java (a typical project would be more than a thousand classes), the standard way is to subclass exceptions to have specific exception types for various error cases. Those exceptions are just thrown from whichever function encounters the error, without any additional wrappers - there is no need for them. What is really important is modular design and right API design, and specific exceptions which can be thrown by various methods are part of the API specs. What you do with the error is application-specific.
Feb
8
revised Interrupting package evaluation, handling error
added 130 characters in body
Feb
8
answered Interrupting package evaluation, handling error
Feb
8
comment Retaining and reusing a one-to-one mapping from a sort
Well, I left that comment specifically for you to use it should you wish to do so. I posted another answer because it became clear that the OP wants SortBy-like behavior with a list of comparison functions, and it was more than just using Ordering.
Feb
8
awarded  Enlightened
Feb
8
comment Wavelets: Relative error vs compression ratio
+1. It's nice to see you here, Vivek!
Feb
8
comment Splicing a list of arguments into a function with Sequence
+1. The extent to which this can be called "bypassing" depends on whether or not SlotSequence (##) uses Sequence internally. One thing I am certain about is that both use the same underlying mechanism. In particular, Sequence @@ array can be also written as ##& @@ array (a form beloved by @Mr.Wizard). The discussion in comments below my answer to this question seems relevant here.
Feb
8
comment pointer like operations in mathematica and evaluation control
I think I've done something very similar to what you want in this answer
Feb
8
answered Retaining and reusing a one-to-one mapping from a sort
Feb
8
comment Retaining and reusing a one-to-one mapping from a sort
If I wanted to make this a separate answer, I would have done so at the start :). I think it would be better to start with order = Ordering@Ordering@ref, replacing the slower Position- based code, since people tend to pay more attention to things at the begining of the post. But this is up to you, of course.
Feb
8
comment Retaining and reusing a one-to-one mapping from a sort
Istvan, the way you compute order is really not efficient. Efficent way would be Ordering[Ordering[ref]], and that's all there is to it here, really (so you don't need your longer code using rules either) .
Feb
8
comment Retaining and reusing a one-to-one mapping from a sort
You most certainly can do this, just the ordering function would become more complex,and this can possibly degrade the efficiency. Another option is to construct a list with positions like Transpose[{lst,Range[Length[lst]]}],where lst is the original list, and use SortBy on this one, changing all your sorting functions as f-> First@f[#]&. Then, after a list is sorted, extract positions of elements of the original list in a sorted list as sorted[[All,2]].