Dispatch
((I still don't, hah!)), but that seems to have done it. Seems overly complicated, but this was more so an attempt at "I wonder if you can...without using...".
12:39 AM
@b3m2a1 thanks a bunch! I did not know too much about
@WReach it seems that might be a less complicated method, but I can't seem to get the
$rules
formatted in such a way as to accept that the initial pattern check is a bit...complex? Not as in a complex number, but it uses OrderlessPatternSequence and carries a part from the check to the transformation. So it is more involved than checking a single number, rather checking a list within the list of lists one supplies to Cases
@CATrevillian
Dispatch
is just for performance. You don't need it, but it's so easy to add in that why not?
4 hours later…
4:33 AM
@CATrevillian
Cases
does really work with sequences even where there is only a single rule. It always inspects individual elements even when given sequence patterns and level specs. In the form I gave, it is crucial that the outer pattern i_
match everything so that Condition
can do its work.
5:14 AM
2 hours later…
7:22 AM
Well, all public and private Wolfram Cloud kernels run under Linux. So it definitely is first-class, at least kernel-wise.
Regarding the standard local Front End: Lately I checked some of nontrivial Dynamic code related to FrontEnd operations and the 12.1 FrontEnd (under CentOS) was much more responsive than under Windows. But I did not use it that much.
Mathematica-buginess is a function of time and it is also related a lot to the interaction with the underlying operating system ( and problems of those). It really depends what you are doing. Looks like that most people in academia use mac…
Regarding the standard local Front End: Lately I checked some of nontrivial Dynamic code related to FrontEnd operations and the 12.1 FrontEnd (under CentOS) was much more responsive than under Windows. But I did not use it that much.
Mathematica-buginess is a function of time and it is also related a lot to the interaction with the underlying operating system ( and problems of those). It really depends what you are doing. Looks like that most people in academia use mac…
7 hours later…
2:03 PM
@b3m2a1 I'll have to defer to you judgment on that one... I am frequently criticized on this site for not paying enough attention to performance :) The
Condition
approach removes some redundant pattern-matching in exchange for other overheads. But unless the expression structure and patterns are particularly simple (and even then), it would be hard for me to predict whether that trade-off is worth it. I would have to benchmark in the context of the real problem.
4 hours later…
6:25 PM
@WReach In my experience (which is quite small in comparison to yourself and @b3m2a1) I find that there is often a tradeoff in this or that, whatever it may be, and here we have a tradeoff between simplest/most concise, and most efficient. Here, in my opinion, your method is most concise, but (and I too lack this knowledge) b3's would be most efficient.
6:42 PM
@CATrevillian I mean in this case you'd want two things:
1
turn each n
into n_Integer
to avoid even trying PrimeQ
or PerfectNumberQ
on stuff that isn't an int
Replace[ Range[10], {n_Integer?PrimeQ :> prime[n], n_Integer?PerfectNumberQ :> perfect[n], _ -> Nothing}, 1 ] {prime[2], prime[3], prime[5], perfect[6], prime[7]}
Also I'm not entirely convinced @WReach's solution is more concise? I think you're getting confused because it's a one-liner. If you're not going for speed, mine is this
@b3m2a1 all valid points :D there's a (much) better way to do this, as you've just noted, but I figured I would see if it could be possible with
Cases
, and it is! Ah yes, I guarantee I am confused and getting more confused ;) such is my existence, haha! Thank you for the advice, I like this level of learning how to use the system/syntax! Haha yes I see, I will need to study up on the usage of the Alternatives@@
bit there
« first day (3050 days earlier) ← previous day next day → last day (1402 days later) »