Quantcast
Channel: Which symbol gets DownValues or OwnValues when using SetDelayed? - Mathematica Stack Exchange
Viewing all articles
Browse latest Browse all 2

Which symbol gets DownValues or OwnValues when using SetDelayed?

$
0
0

I have been looking at various usages of Pattern objects. Here's a number of ways to define the same thing:

mod[x_] := {x}

which gives modDownValues. Nothing unexpected.

e : mod[_] := ReleaseHold @ (Hold[e] /. mod -> List)

This is nice, as we don't need to give the argument of mod a name now.

e_mod := ReleaseHold @ (Hold[e] /. mod -> List)

Now we don't need to specify the pattern of arguments to mod at all. However, all three lines of code give DownValues to the symbol mod.

Let's look at the FullForm:

SetDelayed[mod[Pattern[x, Blank[]]], List[x]]SetDelayed[Pattern[e, mod[Blank[]]], ReleaseHold[ReplaceAll[Hold[e], Rule[mod, List]]]]SetDelayed[Pattern[e, Blank[mod]], ReleaseHold[ReplaceAll[Hold[e], Rule[mod, List]]]]

The first example is nothing special, the first argument of SetDelayed has the mod head, thus mod gets the DownValues. However the next two examples have head Pattern. If we use someOtherHead instead of Pattern, (in the second definition) we will get a "function" that does this:

someOtherHead[e, mod[x]](* e *)someOtherHead[e, mod[x, y]](*     someOtherHead[e, mod[x, y]] *)

and if we add the third definition as well, then:

someOtherHead[e, mod[x, y]](* e *)

So clearly there are some special rules for the head Pattern.

My question is three-fold:

  • How does MMA choose, which Symbol gets its DownValues in a Set or a SetDelayed? Especially I am interested in the non-standard procedure, as in my last two examples, but will be happy to get better insight in the standard case presented in my first example.

  • Where is this behavior documented, if at all? I am primarily looking for references, but will happily accept answers from those who know how this works even if they cannot point me to a specific reference.

  • A sub-question of the previous two: where can I find the special rules specifically for the head Pattern?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images