Questions about implementing or applying functions which: (1) always yield the same result for the same input, (2) are independent of outside information, and (3) produce no side effects.

learn more… | top users | synonyms

17
votes
2answers
485 views

Using several anonymous functions mixed together

This works: list // BarChart[#[[2]], ChartLabels -> DateString @@@ #[[1]], ChartStyle -> "Pastel"] & This doesn't: ...
22
votes
2answers
981 views

Is there any way to define pure functions with optional arguments?

For example consider the following function: Function[{u,v},u^2+v^4] Is there anyway to define default values for the variables ...
39
votes
2answers
2k views

Memoization with pure functions?

Is this possible? If I have a simple function, say: f=If[#>0,1,2]& then for each value of # this will re-evaluate f right? Is it possible to define a ...
13
votes
3answers
243 views

Using Through to evaluate complex expressions

Suppose we're given the expression f*g+h, where f,g,h are all pure functions. How can we evaluate this expression on some ...
27
votes
2answers
2k views

What are the cool kids talking about when they use ##&[]? [duplicate]

All the cool kids are apparently using ##&[] for Unevaluated @ Sequence[] but I have no idea what either means. ...
16
votes
4answers
1k views

Second level depth pure function?

I have the following working construction: Select[ln125, # == Nearest[ln125, 551.748][[1]] &] Here, ln125 is a one ...
13
votes
1answer
335 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 ...
4
votes
2answers
244 views

Multiplying expressions within a list of pure functions

Let's say I have a list of pure functions that are nice algebraic expressions: say l = {(#1 - 1)&, (#1^2 + #1)&, (#1^3 - 1)&} What's an easy way to ...
15
votes
2answers
316 views

What are Root objects with multiple polynomials?

In Mathematica 9 a new flavor of Root object with multiple polynomials was introduced. For example, ...
22
votes
1answer
925 views

Is it possible to reference “self” from a pure function?

This would calculate the factorial of 6, if the "self" was the function itself. Is there something that could allow this? ...
7
votes
5answers
250 views

How to write an operator that acts on pure function (to give another pure function)

I would like to write an operator oper that acts on a pure function f with an undetermined number of arguments, with the syntax ...
1
vote
1answer
170 views

Requiring NumericQ in Pure Function

Potential duplicate, but doesn't seem to solve my problem: Using patterns in pure functions I have a function that returns an InterpolatingFunction, and it works ...
10
votes
1answer
327 views

Why does the documentation call functions “pure”?

Clearly, functions in mathematica are not pure functions according to the definition on Wikipedia (no side effects - basically implementabe with table lookups): ...
10
votes
1answer
138 views

What are the scoping rules for function parameters shadowing System` symbols?

Here are some very contrived code snippets, highly unlikely to appear in real code, but still I am curious why they behave like this: ...
9
votes
3answers
361 views

Operate over list of pure functions

I have list of pure functions (All functions are InterpolatingFunction) i.e {{a, b}, {c, d}, {e, f}, ...} and I would like ...
4
votes
2answers
112 views

Conflict with variables in pure functions

Consider the following snippet of code. Clear[f, g] f[x_] := Function[{i}, x]; g[h_] := Module[{Z}, Z[i_] := Print[h]; Print[h]; Z[1]; ]; When ...
-5
votes
1answer
404 views

Split dataset based on the first column [duplicate]

I have a dataset which I want to split based on the first column. The data looks like this ...
5
votes
4answers
161 views

Syntax for Table with a pure function

I have: g = #1^2 + a #2^3 / #1 & Now I wish to make a Table evaluating this from 1 ...
1
vote
2answers
156 views

`Slot` (#) interfering with evaluation

In the following I am using one function makeFunc to assemble two functions a[t] and b[t] to ...
0
votes
4answers
138 views

Cases vs Select, Pattern vs Pure function [duplicate]

What is the difference between having Cases with selection condition presented by pattern and a with pure function as condition? ...
-1
votes
1answer
336 views

How to define a pure function with a Module?

I was not able to use a self defined (using Module and For loops) piecewise function to fit data. It seems that the problem is that I have to define a pure function. I would like to learn how to ...