Questions tagged [design-patterns]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
139 votes
8 answers

Can one identify the design patterns of Mathematica?

... or are they unnecessary in such a high-level language? I've been thinking about programming style, coding standards and the like quite a bit lately, the result of my current work on a mixed .Net/...
Verbeia's user avatar
  • 34.2k
123 votes
7 answers

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 ...
Cassini's user avatar
  • 5,566
92 votes
5 answers

What does the construct f[x_] := f[x] = ... mean?

This question mentions "x := x = trickery". What does defining a function as f[x_] := f[x] = ... do and what is it good for?
Chris K's user avatar
  • 20.2k
30 votes
3 answers

How and why to use monadic programming in Mathematica?

This is a methodological question with two parts: How to use monadic programming in Mathematica? Why use monadic programming in Mathematica? In my opinion the questions are inter-related -- we ...
Anton Antonov's user avatar
29 votes
5 answers

How can I implement object oriented programming in Mathematica?

Roman Maeder's object oriented programming package is nice, but I'm hoping someone can suggest a sleek and novel implementation that is easy to use.
M.R.'s user avatar
  • 31.5k
26 votes
4 answers

Permanently extending the behaviour of functions (like decorators)

Suppose I have a function, e.g. f[x_] := x^2 It works like this: f[5] (* 25 *) I would like to permanently modify it so ...
Szabolcs's user avatar
  • 235k
23 votes
2 answers

Code Readability and Object-Oriented Code

The basic problem I have been running into is making readable code, where in other languages I am more familiar with I might have been using class or struct like objects. For example, you can imagine ...
Jonathan Gleason's user avatar
22 votes
2 answers

How can one define a custom data object?

In Mathematica there are different objects like InterpolatingFunction or SparseArray? How can I define a custom data object with ...
PlatoManiac's user avatar
  • 14.8k
13 votes
3 answers

What's the analogue of UML in Mathematica land?

What's the analogue of Unified Modeling Language (UML) in Mathematica land? Mathematica has elements of object-orientation, but most Mathematica programs or applications aren't of object-oriented ...
user13253's user avatar
  • 8,666
12 votes
1 answer

Art on Mathematica: How can I export 4K resolution png images?

This question is solely based upon $[1]$ and therefore, the reading of $[1]$ could be interesting. How can I export the image created, by the code in the following, with high definition, beautiful, 4K ...
M.N.Raia's user avatar
  • 503
12 votes
5 answers

Implement settable properties

I am looking for advice on implementing the following. (It is possible that the answer is that it is simply not a good idea to do this.) I would like to have an object similar to ...
Szabolcs's user avatar
  • 235k
11 votes
2 answers

Longest and Shortest won't work in ReplaceList?

I'm trying to make a pattern that's easy to preceive by human but hard to write out by Mathematica when I came across this problem. (Check the original problem here) Let's check this simple case: I'...
Wjx's user avatar
  • 9,588
10 votes
2 answers

Art on mathematica with filled circles and straight paths: how can I reproduce minimalist suns?

I would like to know: how can I construct minimalist images like this one?
M.N.Raia's user avatar
  • 503
10 votes
2 answers

Opposite of Alternatives

I was looking at this question (here) and I tried to find any thing gives the opposite of Alternatives. In other words, some pattern matching function that gives ...
Basheer Algohi's user avatar
10 votes
1 answer

Why does MapIndexed return the index in a list?

MapIndex returns the index in a list instead of as shown in my revised example. I can work with it (or work around it), but what's the design concept? It seems ...
George Wolfe's user avatar
  • 5,462
6 votes
1 answer

How to add texture to a parametric plot?

I need to put some simple textures to some parametric plots. My textures are not complicated, They are like the first example in here. Is there any simple way of doing this? For example, How can I ...
lino's user avatar
  • 267
5 votes
2 answers

Obtaining Pairs of Consecutive Elements with Conditional Adjustment

I've encountered a particular problem and was wondering if anyone has any insights on how to approach it more efficiently or elegantly. To be accurate, given the list: ...
E. Chan-López's user avatar
4 votes
2 answers

Equivalent of Nothing for patterns

Let's say we want a pattern, that matches, when expression contains some terms but it can optionaly contain some other terms. For example: ...
GalZoidberg's user avatar
4 votes
1 answer

Draw Graph with upper and lower limit

I am attempting to draw a graph with a slope of 200,000 that becomes "saturated" at $y= \pm 10$. Essentially, the graph is of the form $y=200000x$. However, I have been unsuccessful in getting it to ...
tyler a's user avatar
  • 43
4 votes
1 answer

Do "objects" in Mathematica have to be declared?

A while ago I learned a trick which allows one to imitate object-oriented programming in MMA using SubValues: ...
VF1's user avatar
  • 4,722
3 votes
2 answers

How can a verbal reasoning question be solved with Mathematica?

Could a "verbal reasoning" problem like the following be solved with Mathematica? What comes next in the series. KD XP NG VN QJ TL TM Correct answer is <...
Manu Chadha's user avatar
3 votes
2 answers

How to define the pattern for the sum of some specified terms?

I want to define a function to check whether the expression is the sum of these terms a*x+b*y^n+c*Exp[k*z] (* n can be 1*) These ...
Curious Cat's user avatar
3 votes
1 answer

Fourier Transform of a symbolic expression

Hello I would like to do the Fourier Transform of H1'[t - L2[t]/c - L2primo[t]/c] I know that its transform has to be: ...
Martina's user avatar
  • 39
2 votes
1 answer

Pattern Match "Empty" Term in NonCommutativeMultiply

Not sure if this has been asked before, please point me to the post if it has. Is there a way to treat terms like (b+c), a**(b+c)...
JvT's user avatar
  • 33
2 votes
0 answers

Does Mathematica have a method for achieving the same goals that Aspect Oriented Programming does?

I imagine that this question has been asked before, yet I'm not able to find an answer using the form of the question I believe might be asked. Is there a mechanism for duplicating the ...
LibertyTrooper's user avatar
2 votes
0 answers

Design problem with an an InterpolatingFunction-like object: bad performance over a remote kernel

I these last times, I found myself using often the following approach. Given some data, I make some preliminary, common, computations and I store these results in an ...
unlikely's user avatar
  • 7,103
1 vote
2 answers

Unusual performance of the Cases function [closed]

Recently I was surprised by unusual performance of Cases function. The code ...
Konstantin's user avatar
1 vote
2 answers

How can I collect the sum of any number of gradients without using ReplaceRepeated[]?

Recently, I have run into the problem where I need to collect the the sum of any number of gradients. I have defined a function grad[] to represent the gradient, ...
AlbertLew's user avatar
  • 483
1 vote
2 answers

How to construct a pattern that match the multiple partial differential of any multi-variable functions?

For example,I want to match a multiple partial derivative of a function $f^{(1,0,1)}[x,y,z]$ which is the same as$\frac{\partial^2{f}}{\partial{x}\partial{z}}$.The only information given is the list ...
kikyou's user avatar
  • 13
0 votes
2 answers

Is there a way to make $g$ changeable independently of $f$ in this code?

My problem is that in the below code, every time I want to change $g$ I also have to change $f$. Let's say we have three functions: $f$, $h$, and $g$ ($h$ is not really relevant for the question, but ...
user56834's user avatar
  • 545
0 votes
0 answers

Designing a Manipulate Block

I am trying to create a Manipulate block which contains tabels, graphs and explanations. In the first row I want to add some tables and explanations, but sometimes the tabels are cut. For doing this I ...
kobibo's user avatar
  • 215
0 votes
0 answers

How to correctly use PatternTest (?) [duplicate]

This works fine: {3, -5, 2, 7, -6, 3} /. x_ /; x < 0 :> 0 (*{3, 0, 2, 7, 0, 3}*) and this works fine: ...
Basheer Algohi's user avatar