Algosim documentation: ↦

↦ (maps to)

Creates a function.

Syntax

Description

The operator creates a function. Its left operand is a comma-separated list of function arguments; all these are symbols that must be valid variable names. The right-hand side is an expression that may contain zero or more of these symbols. These symbols take precedence over any other symbol already defined with the same name.

The operator is implemented by the CreateFunction function.

Examples

f ≔ n ↦ n^2 + 1
custom function
f(21)
442
SequenceVector(10) @ f
(2, 5, 10, 17, 26, 37, 50, 65, 82, 101)
SequenceVector(10) @ (n ↦ n^n)
(1, 4, 27, 256, 3125, 46656, 823543, 16777216, 387420489, 10000000000)
a ≔ (m, n) ↦ m^2 + 3⋅m⋅n − 2⋅n
custom function
a(3, 2)
23

A function may construct and return a function:

adder ≔ n ↦ (x ↦ x+n)
custom function
AddFive ≔ adder(5)
custom function
AddFive(394)
399

A custom plotter:

p ≔ f ↦ (
  grph ≔ plot(y = f(x));
  AdjustVisual(
    grph,
    "point size": 4,
    "fill color": "steelblue",
    "line width": 0,
    "window width": 400,
    "window height": 300
  )
);
p(sin)

Image 1

p(cos)

Image 2

See also