The tag has no usage guidance.

learn more… | top users | synonyms

60
votes
3answers
5k views

Metaprogramming in Mathematica

Being functional, and having no "quotation", i.e. essentially treating data and programs semantically same, Mathematica seems naturally capable of doing metaprogramming. But could anyone construct a ...
38
votes
4answers
2k views

Compiling more functions that don't call MainEvaluate

I would like to use Compile with functions defined outside Compile. For example if I have the two basic functions ...
19
votes
1answer
726 views

List manipulation to build a functional expression

Since Mathematica deals with Head[a, b] as an expression in this way The first Part of Head[a, b] is ...
16
votes
3answers
640 views

Comparing Mathematica expressions like diff

I am looking for a way to compare (or "diff") two Mathematica expressions, similarly to how to diff utility can compare two text files and report the differences. Has anyone already written such a ...
13
votes
2answers
662 views

How can I compile this function

I want to simplify my function f1 to f2, but f2 can't be compiled. How can I make it ...
9
votes
2answers
2k views

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.
8
votes
1answer
322 views

A smarter nested With?

I often find myself writing code that looks a bit like this: ...
10
votes
1answer
206 views

What's the goal of the Macros` package?

I see in the Mathematica install a Macros` package. In windows the paths is for example: ...
14
votes
3answers
650 views

How would I return a random Mathematica command?

I'm doing some metaprogramming. How would I make a Mathematica function that returns a random Mathematica command? Is there a list of command names that I could use ...
14
votes
2answers
524 views

How to REALLY Hold arguments and capture FullForm?

I'm trying to write an expression deconstructor or FullForm-capturer; might even call it a parser, maybe, but that might be too glorious a word. I got some great ...
15
votes
2answers
207 views

How to find out what files are touched when Get is called?

Is there a way to capture all package files touched whenever a package is called via Get, Needs, ...
12
votes
3answers
263 views

Find all heads a function is defined on

So say I've got a function g defined as follows: g[x_Integer] := x + 1 g[s_String] := s <> "!!!" How would I write a ...
6
votes
2answers
325 views

How to write complex function definitions at run time?

(Posting as a self-answered question to share a technique I discovered) In a certain project, I have many function definitions in which all parameters should be optional and come with default values. ...
8
votes
7answers
1k views

Better code to find Narcissistic number

My code finding Narcissistic numbers is not that slow, but it's not in functional style and lacks flexibility: if $n \neq 7$, I have to rewrite my code. Could you give some good advice? ...
3
votes
1answer
80 views

Generate assignment code to symbols from string

I want the function to take in string, then assign a value to its corresponding symbol. An implementation using ToExpression is ...
2
votes
0answers
188 views

Best approach for 'manual' common subexpression elimination

I have working code, but am looking for ways to make it more elegant. I have a fairly large expression with plenty of repetition and structure. A shortened toy example is ...