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

Feb
16
comment Is it possible to use Compile on a function with optional arguments?
@OleksandrR. Well, that's reassuring :)
Feb
16
comment Is it possible to use Compile on a function with optional arguments?
@OleksandrR. Interesting. I should have spent more time and do this analysis. Now it looks like there wasn't a single correct statement in the second part of my answer. :-) Time to sleep now, but I will give it another shot tomorrow. As I said, please feel free to improve the answer in the meantime, should you wish to do so.
Feb
16
revised Is it possible to use Compile on a function with optional arguments?
added 163 characters in body
Feb
16
comment Is it possible to use Compile on a function with optional arguments?
@OleksandrR. Yes, you are right. It actually crossed my mind, but I did not test. Too bad. So, this means that we don't actually gain anything from inlining which we can't get by using With or other means of pre-computing. I can't think clearly now, but will come back to this tomorrow and correct the answer. Also, if you'd like, please feel free to edit it as you see fit.
Feb
16
revised Is it possible to use Compile on a function with optional arguments?
Fixed a few typos
Feb
16
comment Is it possible to use Compile on a function with optional arguments?
@Xerxes I made an attempt to address your remark, in my edit.
Feb
16
comment Is it possible to use Compile on a function with optional arguments?
@Szabolcs Ok, I added some more meat to it :-)
Feb
16
revised Is it possible to use Compile on a function with optional arguments?
Added auto-compilation
Feb
15
comment Is it possible to use Compile on a function with optional arguments?
@Szabolcs That's what your previous comment prompted me to start doing :)
Feb
15
answered Is it possible to use Compile on a function with optional arguments?
Feb
15
comment Is it possible to use Compile on a function with optional arguments?
@Szabolcs Well, I was hoping that someone would come up with something more clever :-). All right, putting this as an answer...
Feb
15
comment Is it possible to use Compile on a function with optional arguments?
@Xerxes This is a good point. There indeed may be situations where treating the second argument as a constant may significantly speed up the code, although those probably won't represent the majority of use cases.
Feb
15
comment Is it possible to use Compile on a function with optional arguments?
Just compile as you would do for a full list of arguments, such as compJ = Compile[{x, y}, x + y], and then delegate the execution from your main function j to compiled one as j[x_, y_: 1] := compJ[x, y].
Feb
14
comment how to read in a file in the same directory?
@JoelKlein Thanks, I am aware of that.
Feb
13
comment How to clear parts of a memoized function?
Yes, I think this is correct - the option only governs the hashed values, not pattern-based rules. And as long as we don't count on the ordering of DownValues with the Sort->False option setting being some specific ordering (like e.g. the order in which they were entered), I think the results will not depend on the particular ordering. Of course, the main reason to use Sort->False option is for speed, since we then skip the sorting step when extracting the DownValues.
Feb
13
comment How to clear parts of a memoized function?
One comment (+1,of course) - with the Sort->False option, DownValues are not listed in the order they were entered (which is what I used to think for some time in the past), but in whatever order they are internally stored - which is rather arbitrary in general. This is probably known to you, but some of those reading the answer may be unaware of this.
Feb
13
answered How to clear parts of a memoized function?
Feb
13
awarded  Nice Answer
Feb
12
comment Accessing files in different directories
See also this answer for another example of what I mean.
Feb
12
comment Accessing files in different directories
Don't make your project notebook-centric then. Put your project layout into e.g. $UserBaseDirectory/Applications, and you can use $InputFileName to record the absolute location of your main package at load-time (see this answer for details). Locate your other resources by fixed relative paths, relative to the main package. This is how such things are usually done. Then, in notebook, you will simply have to call Needs[your-package].