Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This works:

list // BarChart[#[[2]], ChartLabels -> DateString @@@ #[[1]], ChartStyle -> "Pastel"] &

This doesn't:

list // BarChart[#[[2]], ChartLabels -> 
    DateString[#, {"ShortDay", "/", "ShortMonth"}] & @@@ #[[1]], ChartStyle -> "Pastel"] &

The difference is that in the second version DateString needs to be an anonymous function. But the entire expression already is an anonymous function. Since this won't work, how can I do what I want to do? Is the best way perhaps to define DateString[#,..] somewhere else, or can I solve this with parentheses or something like that?

share|improve this question
up vote 19 down vote accepted

You can always use Function to create anonymous functions:


is equivalent to


and can be used as such, but it is unambiguous.

It can be used as:


(* ==> 4  *)
share|improve this answer

You can always string several anonymous functions together, but you'll also have to pay attention to operator precedence. In this case, you had to enclose the anonymous function in parentheses. Replace the corresponding line in your second example with the following and it works.

ChartLabels -> (DateString[#, {"ShortDay", "/", "ShortMonth"}] & @@@ #[[1]])

You can read this documentation page for more info on operator precedences. In your specific case, Rule or -> has a higher precedence than Function or &.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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