last day (14 days later) » 

09:55
7
A: How to Override the Head of a Symbol

Mr.WizardI don't believe it is possible to implement your literal request. While you can make an UpSet definition for Head: Unprotect[Ket]; Head[Ket[_]] ^:= Bob Head[Ket[Subscript[x, B]]] ^:= BobKet Head[Ket[Subscript[x, A]]] ^:= AliceKet Head[Ket[Subscript[x, B]]] BobKet Since Head is not actual...

Re: '...Head is not actually used by the pattern matcher ' , what about in the context of Operate, Inactive, RightComposition. Can you clarify why the pattern matcher is or is not involved?
@alancalvitti As far as I know the function Head is not used in core pattern matching operations; it is a user-level function. One might write pattern matching using Head e.g. as part of a Condition, something like x_ /; Head[x] === Plus but that is not the way that fundamental patterns like x_Plus are matched, so UpSetting Head will not produce a match generally and will not affect Operate etc.
+1. Somehow I didn't see this Q / A before. The patterns not involving PatternTest or Condition (I call them syntactic) don't use any "functions", simply because a function is something that needs evaluation by the main evaluator. Syntactic patterns are being matched completely by the pattern-matcher, and evaluator is not involved.
@Leonid Thanks for restating that. I like your terminology and I'll try to remember use it.
@LeonidShifrin, help me understand: (1 + 2)[c] /. f_[x_] :> {f, x} ==> {3,c} or even (1+2)[c]//Head ==>3 in the context above as there's no explicit PatternTest or Condition.
09:55
@alancalvitti What you see are evaluation artifacts, and have nothing to do with the pattern-matching proper. By the time rules are tried, 1+2 have been already evaluated to 3, in both cases.
@LeonidShifrin, I don't get it, isn't Blank in an expression part of the input to pattern-matching evaluation?
@alancalvitti Learn the evaluation process, or read about the interplay of patterns and evaluation here on this site - there were plenty of discussions on this. You won't have these questions then,
@LeonidShifrin, can you link to the most appropriate discussions please?
@alancalvitti Here is the first one I found.
@LeonidShifrin, thanks but there's no explicit mention in that post of why PatternTest and Condition are special vs, say, Blank. Any more insightful links?
09:55
@alancalvitti You still don't get it, it seems. Your example has nothing to do with PatternTest or Condition, it has to do with the fact that patterns do evaluate like other expressions. I can't provide links, because you didn't formulate well what exactly you want to know. I did answer your specific question given examples you provided. If you have another one, consider asking on the main site as a separate question.
@LeonidShifrin, will ask in main site. There's 2 sides to Q/A: maybe I didn't get it, maybe you didn't explain it.
@alancalvitti This wasn't a Q/A. You had a question, I did answer it. You had another, without stating it clearly. Both asked in comments.I am not supposed to explain things in detail in comment to other question, particularly when the question is not formulated well. I didn't get many complaints before for not explaining things well, so perhaps there is still just one side here.
@LeonidShifrin, I've also asked some nice Q's, not necessarily here but on math.se, so what? Get used to a world w/ shifting boundaries like Crimea. Just b/c it's called comments doesn't mean you can't have a Q/A, just like South China Sea doesn't belong to China.
@alancalvitti In case you didn't realize it yet: there are certain general rules on this site, and the fact that sometimes people bend them for a good cause, doesn't change that. Comments are expressly not for asking separate questions. There are good reasons for that.

last day (14 days later) »