Linked Questions

221 votes
2 answers
14k views

What is the distinction between DownValues, UpValues, SubValues, and OwnValues?

When reading through the documentation, you often encounter the phrases DownValues, UpValues, ...
rcollyer's user avatar
  • 34k
106 votes
5 answers
6k views

Replacement inside held expression

I wish to make a replacement inside a held expression: f[x_Real] := x^2; Hold[{2., 3.}] /. n_Real :> f[n] The desired output is ...
Alexey Popkov's user avatar
90 votes
6 answers
3k views

How to avoid nested With[]?

With[ {v1 = #}, With[ {v2 = f[v1]}, g[v1, v2] ] ] How to avoid nested With[] like the above? I'd like to use <...
user13253's user avatar
  • 8,666
69 votes
10 answers
3k views

Injecting a sequence of expressions into a held expression

Consider the following toy example: Hold[{1, 2, x}] /. x -> Sequence[3, 4] It will give Hold[{1, 2, Sequence[3, 4]}] ...
Szabolcs's user avatar
  • 236k
83 votes
3 answers
9k 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 ...
user13253's user avatar
  • 8,666
67 votes
4 answers
6k 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 ...
Mr.Wizard's user avatar
  • 272k
26 votes
6 answers
884 views

Constructing symbol definitions for With

I would like to be able to define two arrays, one containing symbol names and one containing the values of those symbols, for use in constructs such as With. For ...
bobthechemist's user avatar
24 votes
2 answers
1k views

Pure function with attributes of arbitrary number of arguments: Is it possible?

Mathematica allows to define pure function, like Function[{a, b},Length[Unevaluated@a]{b}][1+2,2+3] (* ==> {0} *) Pure functions in Mathematica can take an ...
celtschk's user avatar
  • 19.2k
14 votes
2 answers
946 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 ...
chyanog's user avatar
  • 15.6k
8 votes
3 answers
628 views

Metaprogramming: creating compiled functions from inter-dependent code blocks

I want to create a compiled function from inter-dependent code blocks. Here is a minimal example showing the salient features based on strings: ...
mrupp's user avatar
  • 777
19 votes
1 answer
936 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 ...
Life's user avatar
  • 660
7 votes
4 answers
2k views

Delayed evaluation of assignment

I have a set of PDE's that depend on parameters. They depend on many parameters, but for simplicity we can here assume that they depend only on one, say a. I want ...
yohbs's user avatar
  • 7,046
12 votes
1 answer
563 views

A smarter nested With?

I often find myself writing code that looks a bit like this: ...
Teake Nutma's user avatar
  • 6,021
8 votes
1 answer
376 views

Creating a Block from a list of rules

How can I create a function which works like Block but takes a list of rules as its first argument, rather than a list of assignments? The function needs to be ...
Simon Woods's user avatar
  • 85.1k
4 votes
1 answer
384 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 ...
vapor's user avatar
  • 7,921

15 30 50 per page