Questions on how to write code in a better or different style, using Mathematica's capabilities for coding in multiple styles.

learn more… | top users | synonyms

13
votes
4answers
404 views

Short syntax for accessing System`Utilities`HashTableAdd and System`Utilities`HashTableGet

I have a need for a struct analogue in Mathematica. After reading this post I came to the conclusion that System`Utilities`HashTable is one of the best options. But ...
14
votes
2answers
541 views

Are there advantages to using generalized Part extraction instead of specialized functions like First, Last?

There are many ways to extract different parts of lists in Mathematica. For example, the first part of a list v can be accessed either as ...
8
votes
3answers
367 views

Can this code be written in a more functional style

Referencing this question, I wonder if the following code can be written more concisely using a functional style, i.e. without For loops or ...
25
votes
3answers
2k views

Extracting values from nested rules in JSON data

I have been using Mathematica to analyse some data from the StackExchange API. It is conveniently available in JSON form, which Mathematica interprets as replacement rules. However, some of the rules ...
16
votes
1answer
371 views

Are there advantages to using additional arguments of common functions rather than alternative ways of calculating with lists?

(Apologies for the long question title.) One of the interesting, if sometimes confusing, things about Mathematica is that there is always more than one way to do things. Even intermediate users can ...
5
votes
1answer
300 views

Alternative to overloading Set

In the ideas shared in my answer to this post Struct equivalent in Mathematica? at the end I propose a solution that changes the way Set works in a particular case that can be expressed in plain words ...
87
votes
7answers
8k views

Struct equivalent in Mathematica?

I really miss having something like a struct in Mathematica. I know of (and regularly use) a couple of programming techniques which feel like a ...
12
votes
3answers
457 views

With versus Function

I've seen people compare Block with Module and With as scoping constructs, and try to figure ...
37
votes
5answers
758 views

Placement of Condition /; expressions

It is my practice to place Condition expressions on the left side of := and :> in almost ...
121
votes
3answers
19k views

Alternatives to procedural loops and iterating over lists in Mathematica

While there are some cases where a For loop might be reasonable, it's a general mantra – one I subscribe to myself – that "if you are using a ...