1

Does the function Map (/@) is equivalent to Apply to first level (@@@) ?

he way that I see this head functions are that both are equivalent. Please, comment if they have a fundamental difference.

  • Compare f /@ g[h[1], h[2], h[3]] and f @@@ g[h[1], h[2], h[3]] to see the difference :) Remember, Map wraps functions around stuff, while Apply replaces the heads of stuff. – Marius Ladegård Meyer Oct 02 '16 at 10:16
  • Map creates functions that takes a list as argument, Apply at first level creates functions that take multiple arguments. – Feyre Oct 02 '16 at 10:16
  • 5
    Well, try it: f @@@ {{1,2},{x,y}} and f /@ {{1,2}, {x,y}}. Is the result the same or different? Remember that it's not necessary to define f to do this (in fact you shouldn't define it to really see what's happening). – Szabolcs Oct 02 '16 at 10:21
  • f /@ list maps a function f onto each element of list, so list is a set of arguments on which f will be evaluated. f @@@ list replaces the Head of each level-1 element in list. – corey979 Oct 02 '16 at 11:42
  • 1
    You might be interested in this answer by dreeves who points out that we may think of f@@@lst as being a shorthand for f @@ # & /@ lst. That is, we may think of Apply at level one as being equivalent to mapping Apply to each (level one) element of lst. Perhaps this is what you mean? f @@ # & /@ {{1, 2}, {x, y}} == f @@@ {{1, 2}, {x, y}} – user1066 Oct 02 '16 at 17:46
  • Yes.. this is correct.. This is what O meant and using the purge function example help me see the picture. Also, I am assuming that "lst" is a typo? do you mean "list" .... f@@@list or this is just a short hand? – Jose Enrique Calderon Oct 09 '16 at 12:28

0 Answers0