Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Style for function calls?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97173] Re: Style for function calls?
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Sat, 7 Mar 2009 02:38:25 -0500 (EST)
  • References: <goqpg6$lsb$1@smc.vnet.net>

Hi,

> I'm aware with the operator forms for Postfix (//), Prefix (@), and 
> Infix (~), and I've found the // operator useful for piping long results 
> through the ...Form functions, or N, or the like, as a quick 
> afterthought while typing a lot of stuff.

> What are the analogous situations where @ or ~ are used?  Looking at 
> random notebooks around I've from time to time seen them used but there 
> doesn't seem to be any rhyme or reason; 

one use case for @ I use very often is this: When debugging I just put a
Throw@ or Print@ in front of the expression I want to examine and remove
it when I'm done. Removing that is much easier than when using [] and
often clearer than //.

> it's not clear when 
> stylistically they'd be useful, as opposed to the // operator, which I 
> can see and use myself.

I think there are cons and pros for using or not using the *fix
notations, just as is the case for any other shortcut within
Mathematica, so it boils down to a matter of taste. I personally use @
and // frequently in "throw away" code because it saves me from
searching the start/end of an expression, but tend to use [] (and fewer
shortcuts like /@, @@@, #&) in code that i want/need to maintain for a
longer period, just because I find it is easier to read when I come back
after a longer period. Using too many shortcuts results in "write only"
kind of code more often for me. There are some other drawbacks for @ and
// : they can't easily be extended to more than one argument (e.g. when
you later find that you want to use an option) and you sometimes need
extra brackets to enforce the precedence you need (e.g. {a, b} // f /. a
-> 5). I see infix like ~op~ only used very rarely in Mathematica code
(except of course for some built ins like *,+,=,=,...), one of the few
occasions was a former colleague who liked to use infix for Join: a
~Join~ b ~Join~ c.

hth,

albert


  • Prev by Date: Re: list/sequence problem: a 'keep' list to a list of
  • Next by Date: Re: Bug In LogPlots with WorkingPrecision option?
  • Previous by thread: Re: Style for function calls?
  • Next by thread: Re: Style for function calls?