62,137 reputation
6188280
bio website mathprogramming-intro.org
location St. Petersburg, Russia
age 38
visits member for 3 years
seen 1 hour ago

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


1d
comment I define a variable as local to a module BUT then the module uses its global value! Why?
@pan_e_gaban The evaluation semantics of Set is then responsible for the rest: Set evaluates its r.h.s. at the time of assignment, which results in r.h.s. being evaluated with the global value of h. Now, in your first example in your comment, there are no pattern variables, and therefore no bindings to protect (only pattern variables are considered the local variables which induce bindings and make Set a scoping construct). In any case, you've run into a fairly advanced stuff, don't expect to fully understand it without getting a deeper understanding of scoping and related issues.
1d
comment I define a variable as local to a module BUT then the module uses its global value! Why?
@pan_e_gaban I suggest to read the linked post, which explains parts omitted here. Also, read the documentation of Set, to understand its evaluation semantics. And read on scoping constructs in the documentation, to understand how Module implements lexical scoping. Basically, Module localizes variables by renaming them in code, with local symbols with unique names that it creates. This renaming is prevented in this case, as I described. Now, at the time Module evaluates its body, the symbol h remains unrenamed, and is then taken from the surrounding (global in this case) environment.
1d
comment I define a variable as local to a module BUT then the module uses its global value! Why?
I just noticed that Simon Woods made a comment to Mr. Wizard's answer (now deleted), essentially the same as what I have described here. I didn't see that comment before posting this.
1d
answered I define a variable as local to a module BUT then the module uses its global value! Why?
1d
comment What to use instead of ReplaceAll to replace a parameter with a number before the evaluation of an integral?
+1. But, two or more levels of Unevaluated usually signal (to me), that Unevaluated is generally the wrong tool for the job (not in this particular case).
1d
comment Why can AppendTo modify a referenced list in-place but Part cannot?
@EricParker What you describe is a special case of what is usually called linked lists in Mathematica. Using them is indeed another good method of accumulation of intermediate results, which was the only one before the introduction of Reap and Sow into the language. I have posted a rather detailed post devoted to them, here.
1d
comment Mathematica style guide?
@AlbertRetey Completely agree. I actually had that in mind when writing the previous comment, but did not write. This is really important, to avoid name clashes. Basically, with this, the shadowing problem goes away, while now one has to resort to less convenient, and actually strictly inferior, methods, such as using fully qualified symbol names, etc.
1d
comment Mathematica style guide?
@rcollyer Which is one reason why Python, for example, has a form from some-module import some-symbol, which is considered the preferred way to do imports (as opposed to from some-module import *). This makes it easy to see which symbols are imported, even in the plain-text mode. I wish Mathematica had a similar mechanism.
1d
comment Mathematica style guide?
@rcollyer Well, the notion of system function is somewhat blurred, given that system functions live in a large set of contexts. Perhaps, the real problem here is that, by looking at the code of a package, it may not immediately clear whether a symbol is defined in that package, or imported from another package. But I view this as a problem of the IDE, which should have a better language analysis tools. A totally solvable problem. Conceptually, I don't think there should be a separation between system functions and functions exported by packages.
1d
comment Mathematica style guide?
@rcollyer I don't see why there should be a separation between system functions (which can also live in the top-level code), and functions in packages, if packages are supposed to be extensions of Mathematica language. In fact, I find this rather harmful in that it reinforces the attitude that people use Mathematica + occasionally some packages, but using lots of packages is not considered normal. This is one reason why we don't have many third-party / open source projects around, although obviously not the main one (rather, it is a consequence of more fundamental ones).
1d
awarded  Enlightened
2d
awarded  Nice Answer
2d
comment Why can AppendTo modify a referenced list in-place but Part cannot?
@DanielLichtblau Well, coming from you, Daniel, this is the best thing I could hear. But, this would raise the bar of expectations for what to see in my answers way to high :).
2d
comment Why can AppendTo modify a referenced list in-place but Part cannot?
@EricParker In fact, here is a reference to a more detailed discussion of this. Thanks for the accept, by the way - but generally, it is a good practice to wait for some time, to encourage more answers to appear.
2d
comment Why can AppendTo modify a referenced list in-place but Part cannot?
@EricParker Yes, it does use copy-on-modify.
2d
revised Why can AppendTo modify a referenced list in-place but Part cannot?
added 8 characters in body
2d
revised Why can AppendTo modify a referenced list in-place but Part cannot?
Added a bit of extra explanation
2d
answered Why can AppendTo modify a referenced list in-place but Part cannot?
2d
comment Localising OptionValues
A somehwat relevant discussion. Since that post, I have changed my views a little, now I use strings as option names somewhat more often than before.
Jan
26
comment Having used Mathematica as a “gateway” language, where to from here?
@DaoTRINH Great! Hope you'll find it useful. To me, that page is mostly marketing, I'd prefer something going way deeper into details.