7
$\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$
  • $\begingroup$ For those who want to read that tutorial: the usage starts from page 22. $\endgroup$ – happy fish Apr 16 '17 at 7:51
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$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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