80 points · by nkurz · 10y ago · 46 comments
I write a lot of Mathematica code for my job. To make life easier I've built in a macro system that makes day-to-day programming a whole lot more pleasant. It will be available in Mathematica 10.4 in the GeneralUtilities package that ships with Mathematica.
One of the built-in macros is a construct that automatically localizes any variables that occur as the L-value of an assignment:
Needs["GeneralUtilities`"]
foo[x_, y_] := Scope[
z = x * y;
PrimeQ[z + 1]
]
This gets rewritten at definition time to be: foo[x_, y_] := Block[{z},
z = x * y;
PrimeQ[z + 1]
]
It's a small thing, but it adds up, especially for large functions, and indeed its silly this isn't a core feature of the language.There are a couple other nice features of Scope, too, like the ability to use a single quote ' anywhere in the body of your function to Echo the value there to the current notebook without actually changing the behavior of the code -- essentially a very lightweight form of 'debugging print'. That also makes a huge difference.
And it has some more powerful variants, like "z '= 2 * 3" will echo a line that explicitly says "z = 6", rather than just "6".
Likewise '' means EchoHold, which prints the expression before being evaluated AND afterwards, so you'll see "z = 2 * 3 = 6" in the above case.
Lastly ''' means Tap, which is a higher-order form of EchoHold which instruments a function to echo its input and output (again without changing behavior). So Fold[Plus''', Range[10]] prints out all the intermediate steps in the fold.
There's a variety of features that add a very lightweight syntax for monadic and exception-based error handling, but that's not quite stable enough to advertise yet.
Same goes for debugging: there's some really powerful stack browsing, history capture and replay features, but again not quite stable enough to advertise for this version.
Like, the third slide of the introduction:
Range[20]
Why not just something like List[1..20] ? Maybe List[1..20] works in Wolfram, but then it's weird that you have this Range function that serves no other purpose than to define a Range.
Same with NestList[f, x, 5]. I don't offhand know the way to create its output in something like Scala or Haskell but I imagine it's pretty concise, but meanwhile, in this case... if it's possible to get the effect without using NestList, then why use it? And if it's not possible to get the effect without using NestList, then how would you ever find out that you can use NestList?
It just seems like the actual programming experience would be a lot more about hunting-and-pecking through documentation and google searches, rather than reasoning your way to solution.
I'd love to hear from someone skilled with Wolfram to offer some clarity. Are you just basically thumbing through the documentation all the time to find that one perfect function call?
That said, WL is in fact based on pretty simple primitives. If you are familiar with functional programming, things like NestList are familiar and you'll start learning by finding the analogues of your favorite FP constructs.
WL also has a lot of functions that you might call "optional": those that could be restated as simple combinations of other functions. The rationale there is pretty simple: if there is a well-defined, commonly used chunk of computation, it should be given a name (and design). The fact that a fair amount of work is put into both the name and design of these things gives a higher sense of coherence (and predictability) than you might expect from their number.
Amazingly, I get the impression they say it as a point of pride, rather than as an embarrassing design decision. Don't get me wrong, having a rich, large standard library is great, but unless you use some kind of hierarchical namespaces, it's impossible to deal with.
Typical Mathematica notebooks (I won't say "programs") use a fair bit less than one hundred of the common functions, plus a handful of domain-specific functions from that the greater set of five thousand. At any time, you can enter ?FunctionName to access documentation far more comprehensive than most languages offer.
The UpperCaseForStandardLibrary and lowerCaseForYourCode convention actually makes a lot of sense in the context of Mathematica's primary use cases vs traditional software engineering projects. When I'm just trying to solve some problem in Mathematica, using my computer as a bicycle for the mind, I appreciate not having to putz with import statements or avoid name collisions.
Either all of your geography related function start with "Geo" followed by a capital. In that case you're basically using a namespace while reaping none of the benefits. You can't use the namespace to avoid repeating yourself in some local context, you can't rename it, you can programmatically inspect its content, etc.
Either they do not, in that case you have an inconsistent mess.
As a user, why should I care?
It's easier to recall a function name than recall the namespace and the function name, isn't it? With modern IDEs this is a none issue anyway. Though from my experience with Mathematica 5-7, the language feels a bit weird. Nevertheless it's quite an achivement that WolframAlpha (the AI search engine) runs on Mathematica code.
> The Wolfram Language is first and foremost an evolution of the symbolic language developed for Mathematica over the course of more than 25 years. But it's considerably more than that—adding the knowledge, knowledge representation and natural language abilities of Wolfram|Alpha, as well as a new symbolic deployment mechanism created with the Wolfram Cloud.
This is followed by a "Buzzword Compliance" section, which lives up to its name, but describes some of the features of the language
> How is it licensed?
> The Wolfram Language has multiple licensing models depending on usage scenario. It is available free for certain casual use in the cloud, in CDF Player, and on systems such as Raspberry Pi. It is available through site licenses at educational institutions. It is also available in a variety of subscription and paid-up product offerings. The Wolfram Language is also licensed for OEM use, embedded in hardware or software systems.
The "casual use in the cloud" may be referring to this: http://programming.wolframcloud.com/ (requires sign-up, haven't tried it), and I'm not sure how you'd go about grabbing the Raspberry Pi edition.
Easiest way is probably to start by buying a RPi.
https://develop.open.wolframcloud.com/app/
The Wolfram Language also ships with Raspberrian for the RaspberryPi.