1
$\begingroup$

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.

$\endgroup$
6
  • $\begingroup$ 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. $\endgroup$ Commented Oct 2, 2016 at 10:16
  • $\begingroup$ Map creates functions that takes a list as argument, Apply at first level creates functions that take multiple arguments. $\endgroup$
    – Feyre
    Commented Oct 2, 2016 at 10:16
  • 5
    $\begingroup$ 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). $\endgroup$
    – Szabolcs
    Commented Oct 2, 2016 at 10:21
  • $\begingroup$ 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. $\endgroup$
    – corey979
    Commented Oct 2, 2016 at 11:42
  • 1
    $\begingroup$ 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}} $\endgroup$
    – user1066
    Commented Oct 2, 2016 at 17:46

0

Browse other questions tagged or ask your own question.