3 ms·
Ditto, I'd love to hear more of this talk. It feels like Wolfram/Mathematica has its own terminology, but I'd love to hear it interpreted in more mainstream pro
by ianbicking 4y ago
Ditto, I'd love to hear more of this talk. It feels like Wolfram/Mathematica has its own terminology, but I'd love to hear it interpreted in more mainstream programming language terms.
The symbolic evaluation is pretty novel. I assume it's not _just_ an AST. What do those structures look like?
What is the scoping? It feels like the emphasis is on global variables everywhere, but is it more subtle than that?
Are the data structures what we expect? Just in this post, Threaded implies some abstractions there. I would assume that some kind of "deferred" values are pretty typical throughout, is there a formal notion of that? A lot of it is deliberately hidden in the language, but I assume you can write code that handles that stuff directly.
Speaking of derivatives, I assume you can indicate how to take the derivative of new kinds of functions. How does that work? Generic functions, object oriented, ad hoc registries, or something else?
- carry_bit 4y agoScoping: Symbols belong to "contexts" (namespaces). You get lexical scope using With and Module, and dynamic scope with Block. The variables in Module are replaced with a uniquely named temporary symbol (removed when all references go away), so they can be returned from the Module expression and acted upon (though they'll appear ugly). Data structures: you have special syntax for lists and "associations" (dictionaries/maps/hashtables). Those are immutable objects, but in at least some cases the implementation has an optimization where it'll directly mutate the object if there is only one reference to it. There are other data structures with no special syntax in the language, for example numeric and sparse arrays. A number of mutable data structures have also been recently introduced: https://reference.wolfram.com/language/guide/DataStructures.html https://reference.wolfram.com/language/guide/DataStructures.... One thing that you might expect to be a special data structure but actually isn't are "pure functions" (anonymous functions). There are actually just the unevaluated expression, so you could programmatically inspect the body if you so wanted to. Deferred values: You can apply the HoldFirst/HoldRest/HoldAll/HoldAllComplete attributes so during evaluation they receive the corresponding arguments unevaluated. You might think this would make metaprogramming be easy, but it's actually tricky because of the "infinite evaluation" (it keeps evaluating until a fixed point is reached) of the language. Derivatives: It's a term rewriting language, so you just provide the rewrite rules like you would with any other user function. f /: D[f[x_]] := x^2 will define the derivative of f(x) to be x^2, and associates that definition with f so that rule won't have to be checked for all usages of D (this also saves you from having to unprotect D to add the rule).