9
$\begingroup$

I found a tutorial that preferred the use of the right T arrow (Esc fn Esc) to define functions which I had never seen before.

It took me a while to find it in the Function help page buried in the Details section but it is interesting to note that it isn't referenced in the basic examples and seems to be very uncommon in general usage (at least in the books I've purchased and the pdf tutorials I've found online).

Perhaps it is very new or very old and people just get used to the # & and f[ _ ]:= formats?

Can anyone comment on why this isn't more commonly used or is it just a matter of style?

$\endgroup$
1
  • $\begingroup$ For those who want to read that tutorial: the usage starts from page 22. $\endgroup$
    – vapor
    Apr 16, 2017 at 7:51

3 Answers 3

6
$\begingroup$

I do make use of \[Function] myself, but rarely.

As Shadowray notes it does not present well outside of the Notebook so it is not as "nice" for preparing answers here on Stack Exchange.

The primary reason I don't use it more often, and simultaneously the primary reason I use it when I do, is that its precedence feels a little odd. Regular & functions are direct to apply and it is easy to string a few together:

{#, 3} & @ {#, 2} & @ {#, 1} & @ 0
{{{0, 1}, 2}, 3}
0 // {#, 3} & // {#, 2} & // {#, 1} &
{{{0, 3}, 2}, 1}

With \[Function] even a simple application require more work; this does not do what I "expect:"

a \[Function] {a, 1}[5]
Function[a, {a, 1}[5]]

Parentheses force the precedence:

(a \[Function] {a, 1})[5]
{5, 1}

Stringing operations doesn't quite work either:

a \[Function] {a, 1}  @  a \[Function] {a, 2} @  a \[Function] {a, 3} @ 0
Function[a, Function[{a, 1}[a], Function[{a, 2}[a], {a, 3}[0]]]]
0 // a \[Function] {a, 1} // a \[Function] {a, 2} // a \[Function] {a, 3}

Function::flpar: Parameter specification a[0] in Function[a[0],Function[a[{a,1}],Function[a[{a,2}],{a,3}]]] should be a symbol or a list of symbols. >>

Function[a[0], Function[a[{a, 1}], Function[a[{a, 2}], {a, 3}]]]

Of course parentheses can force grouping here too, but it doesn't make this syntax convenient in most cases.

The precedence is convenient in other cases where one actually wants it. I'll try to add an example or two later if I have time.

$\endgroup$
3
$\begingroup$

I think this is more like a personal preference. But I see a couple of possible issues with \[Function]:

First, \[Function] looks very similar to \[Rule] and can make reading of the source code more difficult.

Second, it can look cumbersome, especially in an external editor. Compare for example the following two expressions:

Map[(#^2)&, Range[10]]

Map[x \[Function] x^2, Range[10]]
$\endgroup$
0
1
$\begingroup$

I think it is useful to turn the expressions into functions.

For example, I have a list of expressions

myFunc = {E^(-x^2 - y^2), 3 x + 4/y};

and I want to turn them into functions

ClearAll[theFunc]; theFunc = myFunc;(*initialization*)
Table[theFunc[[i]] = {x, y} \[Function] Evaluate[myFunc[[i]]], {i, 
  Length@myFunc}];

Then,

theFunc[[1]][a, b]  (*E^(-a^2-b^2)*)
theFunc[[2]][3.14, 16] (*9.67*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.