460 views

### DownValue “associative array” to list? [duplicate]

I have a "sparse array" like this arr[1.5]=0.4, arr[3.5]=0.7, arr[7]=0.3 which is not really a sparse array since the keys are not all integers. This is like a ...
14k 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 ...
4k views

### How do I evaluate only one step of an expression?

I am looking for a simple, robust way to evaluate an expression only one step, and return the result in a held form. The definition of a single step is ambiguous, and this itself is probably worthy ...
716 views

### Implementing a safe ValueQ that does not evaluate its argument

Mathematica has a built-in function ValueQ. Quoting the docs, ValueQ[expr] gives True if ...
476 views

### Accumulate second elements in sublist

I want to accumulate the second elements in each sublist identified by its first element. ...
498 views

### Selectively clear DownValues

How can I clear a subset of a symbol's DownValues ? For example, suppose I have created some DownValues for $f$ like this: ...
479 views

### Replace with position and order number

question conversion1 : Convert "[AA]AB[AA]BB[AA]B[AA]CCC" to "[A1A2]A3B1[A4A5]B2B3[A6A7]B4[A8A9]CCC" conversion2 : Convert <...
1k views

### When to use indexed variables

Still learning the fundamentals of the language I would like to ask you what advantages there might be in writing something like: a[1] = 2; a[2] = 4; a[3] = "x"; ...
178 views

### Get DownValues that do not involve patterns?

Say I have a function with a few definitions that also implements memoization: f[x_] := f[x] = x^2 f[x_, y_] := f[x, y] = x^2 + y^2 I then apply the function to ...