Skip to main content
Bounty Ended with 100 reputation awarded by xyz
edited body
Source Link
xyz
  • 655
  • 4
  • 38
  • 117

I have given your code only a cursory read but I think I spotted a (the?) problem: your Message code uses an unheld equivalent of the test expression itself. This cannot work. If the expression would generate a Message the first time it would even within Message and you will get infinite recursion. Use HoldForm to prevent this:

(*check the type of the first arguments*)
checkArgs[self : func_[a_, b_, c_]] /; ! MatchQ[a, _Integer?NonPositive]NonNegative] := 
 Message[func::intnm, HoldForm[self], 1]

(*check the type of second arguments*)
checkArgs[self : func_[a_, b_, c_]] /; ! MatchQ[b, _Integer?NonPositive]NonNegative] := 
 Message[func::intnm, HoldForm[self], 2]

With this correction your code no longer produces a recursion error on definition, however I get:

Bernstein::intnm: Non-negative machine-sized integer expected at position 1 in Bernstein[n_,i_,u_]. >>

I believe this comes from the limited evaluation that takes place during function definition and I think the definition will still be made correctly, but I'll have to check that later.

Separately I think you can and probably should be including checkArgs in the TagSet definition:

Bernstein /: PiecewiseExpand[Bernstein[n_, i_, u_]?checkArgs] := . . .

However again I haven't made an attempt to test this definition itself. If you have additional problems please note them in the question and I shall try to help when I return to this.

I have given your code only a cursory read but I think I spotted a (the?) problem: your Message code uses an unheld equivalent of the test expression itself. This cannot work. If the expression would generate a Message the first time it would even within Message and you will get infinite recursion. Use HoldForm to prevent this:

(*check the type of the first arguments*)
checkArgs[self : func_[a_, b_, c_]] /; ! MatchQ[a, _Integer?NonPositive] := 
 Message[func::intnm, HoldForm[self], 1]

(*check the type of second arguments*)
checkArgs[self : func_[a_, b_, c_]] /; ! MatchQ[b, _Integer?NonPositive] := 
 Message[func::intnm, HoldForm[self], 2]

With this correction your code no longer produces a recursion error on definition, however I get:

Bernstein::intnm: Non-negative machine-sized integer expected at position 1 in Bernstein[n_,i_,u_]. >>

I believe this comes from the limited evaluation that takes place during function definition and I think the definition will still be made correctly, but I'll have to check that later.

Separately I think you can and probably should be including checkArgs in the TagSet definition:

Bernstein /: PiecewiseExpand[Bernstein[n_, i_, u_]?checkArgs] := . . .

However again I haven't made an attempt to test this definition itself. If you have additional problems please note them in the question and I shall try to help when I return to this.

I have given your code only a cursory read but I think I spotted a (the?) problem: your Message code uses an unheld equivalent of the test expression itself. This cannot work. If the expression would generate a Message the first time it would even within Message and you will get infinite recursion. Use HoldForm to prevent this:

(*check the type of the first arguments*)
checkArgs[self : func_[a_, b_, c_]] /; ! MatchQ[a, _Integer?NonNegative] := 
 Message[func::intnm, HoldForm[self], 1]

(*check the type of second arguments*)
checkArgs[self : func_[a_, b_, c_]] /; ! MatchQ[b, _Integer?NonNegative] := 
 Message[func::intnm, HoldForm[self], 2]

With this correction your code no longer produces a recursion error on definition, however I get:

Bernstein::intnm: Non-negative machine-sized integer expected at position 1 in Bernstein[n_,i_,u_]. >>

I believe this comes from the limited evaluation that takes place during function definition and I think the definition will still be made correctly, but I'll have to check that later.

Separately I think you can and probably should be including checkArgs in the TagSet definition:

Bernstein /: PiecewiseExpand[Bernstein[n_, i_, u_]?checkArgs] := . . .

However again I haven't made an attempt to test this definition itself. If you have additional problems please note them in the question and I shall try to help when I return to this.

Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

I have given your code only a cursory read but I think I spotted a (the?) problem: your Message code uses an unheld equivalent of the test expression itself. This cannot work. If the expression would generate a Message the first time it would even within Message and you will get infinite recursion. Use HoldForm to prevent this:

(*check the type of the first arguments*)
checkArgs[self : func_[a_, b_, c_]] /; ! MatchQ[a, _Integer?NonPositive] := 
 Message[func::intnm, HoldForm[self], 1]

(*check the type of second arguments*)
checkArgs[self : func_[a_, b_, c_]] /; ! MatchQ[b, _Integer?NonPositive] := 
 Message[func::intnm, HoldForm[self], 2]

With this correction your code no longer produces a recursion error on definition, however I get:

Bernstein::intnm: Non-negative machine-sized integer expected at position 1 in Bernstein[n_,i_,u_]. >>

I believe this comes from the limited evaluation that takes place during function definition and I think the definition will still be made correctly, but I'll have to check that later.

Separately I think you can and probably should be including checkArgs in the TagSet definition:

Bernstein /: PiecewiseExpand[Bernstein[n_, i_, u_]?checkArgs] := . . .

However again I haven't made an attempt to test this definition itself. If you have additional problems please note them in the question and I shall try to help when I return to this.