58,807 reputation
6175266
bio website mathprogramming-intro.org
location St. Petersburg, Russia
age 38
visits member for 2 years, 9 months
seen 3 hours ago

Ok, an obligatory note: opinions expressed here are mine and not those of my employer.


4h
comment Unprotect fails the first time, works on second pass
As a general comment, I would much rather use UpValues on customHead, than add a DownValue to Plus, which is generally a pretty error-prone operation and should be avoided when possible.
1d
comment To UpSet or not to UpSet when using MakeBoxes
One observation here which I find interesting is that MakeBoxes is HoldAllComplete. This should mean that it doesn't perform any UpValue search. Yet, UpValue-based definitions do work with it. There must be something rather interesting going on there, but I never had the energy to investigate deeper.
1d
comment Is there a way to stop Export if the file size is too big?
The only reliable way I can suggest is to write your own exporter, which would export in chunks. In such a case, you will be able to inject such constraint into the logic of your exporter. It might be not as hard as it may sound, since in many cases you can use ExportString to export individual chunks (e.g. this is the case for CSV).
1d
comment Metaprogramming in Mathematica
@Reb.Cabin In fact, I wanted to do the same, in the sense of reading Lisp books / learning that stuff, and then trying to get some of that into Mathematica. But I agree, that's a lot of work. Still, I'd really like to do that, at least in part, when I get more time on my hands. For instance, I've written some preliminary code for custom code loader in Mathematica, which would have a real read time, making real read-time macros possible. But serious work in any of those directions requires much more time than I currently have.
2d
comment DownValue assignment using Apply
+1. I think I will point to a similar discussion I had in my post answering this question.
2d
comment Detect Messages within an expression without losing the return value?
@becko See my edit.
Oct
17
comment Detect Messages within an expression without losing the return value?
@becko I think, this spec is underdesigned. What if more than one message is generated during the evaluation? Do you want to evaluate expr2 on every generated message? Also, you will probably need to somehow pass the information about the currently generated message to the expr2. One way of doing this would be to use the syntax withMessageDetection[expr1, {msginfo_Symbol,expr2}], where you refer to whatever symbol you pass as msginfo, inside expr2, if you need that. Another way would be to make expr2 a function of those message parameters. Let me know which you'd prefer.
Oct
17
comment Association and rudimentary object-oriented programming
I have discussed this topic a bit in my post on the use of Associations, and also here (not in the context of Associations). I you search this site, and also Wolfram Mathematica tag on Stack Overflow, you will find many more OO-related discussions.
Oct
16
comment How to write complex function definitions at run time?
@Mr.Wizard I saw this question the moment it was asked. Unfortunately, I don't have the time at the moment for anything more than a few comments. But, chances are that I wouldn't produce a better answer here than you did. If I had the time, I'd try to address a problem more generally, but that would require a lot more time than I currently have.
Oct
16
comment How to write complex function definitions at run time?
The new constructs you mentioned are really not in the same league as macros in CL, simply because in Mathematica there is no read time (at least not in the sense in which it is present in CL), and everything is happening at run-time. Therefore, you can't safely assume that the code (except macros) is truly inert, and so far I haven't seen a compelling case where the new constructs would significantly alleviate the pain of evaluation control.
Oct
16
comment How to Use Mathematica as a C/C++ compiler
@halirutan I certainly meant the second one, but somehow I think the answer is the same regardless :)
Oct
16
comment How to Use Mathematica as a C/C++ compiler
@halirutan But will that work if they buy a mining truck instead?
Oct
16
comment How to Use Mathematica as a C/C++ compiler
This is the most weird request I've encountered in a very long time. If you want to learn C, learn how to use the C compiler.
Oct
15
comment Automating constructor definitions (OptionValue eval time)?
I actually think this is a dupe of that link, so I'd better vote to close. It's probably still worth to keep this question, perhaps the title could be changed a bit to reflect that the actual problem is in OptionValue.
Oct
15
comment Automating constructor definitions (OptionValue eval time)?
Ok, here it is. Not sure whether or not your question is a dupe of that, would need to study it closer to tell.
Oct
15
comment Automating constructor definitions (OptionValue eval time)?
Don't have much time to test now, but it should work when you change OptionValue to (OptionValue[#]&), and has indeed to do with how / when OptionValue is evaluated. There has been a discussion on that, I will try to find a link.
Oct
13
comment DownValue assignment using Apply
Set holds its first argument, so you need to force the evaluation inside Set. To work in all cases (including the case when a has been already defined on that index), I'd do something like Hold@@index/.Hold[inds__]:>Set[a[inds],5]. This seems to be a duplicate of at least one similar question, but I can't find it.
Oct
13
comment File-backed lists/variables for handling large data
@VividD Thanks :). This isn't as complete as I wanted it to be, and perhaps I will add a few things here some time soon.
Oct
9
comment The conflated two uses of SameTest within Intersection
@Ymareth Well, the first step would be to clearly formulate what you actually want. It is clear that for non-transitive sameness function, the result will depend on the order of the elements in your lists. OTOH, functions like Complement, Intersection, Union etc. treat lists as sets. Which means that they are probably inappropriate for your needs, unless you manage to reformulate your problem to use a transitive sameness function.
Oct
9
comment The conflated two uses of SameTest within Intersection
In your first example, there is a typo, you use #1 in both cases. In general, your sameness function is not transitive (meaning that from a ~ b and b ~ c does not follow a ~ c in general, where I used ~ to denote sameness function), so you may expect different results depending on the order in which things are compared. So, you should either use a transitive sameness function, or rely on a particular order of comparisons, if you want predictable and deterministic results.