Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

A more syntactically compact way?

  • To: mathgroup at
  • Subject: [mg62991] A more syntactically compact way?
  • From: "Trevor Baca" <trevorbaca at>
  • Date: Sat, 10 Dec 2005 06:03:01 -0500 (EST)
  • Sender: owner-wri-mathgroup at

This is a question about using assigning an upvalue to a symbol and
"type"-checking the symbol with some sort of Q predicate:

If we define a "type" with the predicate ...

  fooQ[f_] := MatchQ[f, foo[_Integer, _Integer]]

... then assigning an upvalue this way doesn't work ...

  foo /: jiggle[f_?fooQ] := First[f]^Last[f]
  TagSetDelayed::tagnf: Tag foo not found in jiggle[f_?fooQ]

... and assigning an upvalue this way ....

  foo /: jiggle[f_foo] := First[f]^Last[f]

... does (syntactically) work, but at the cost of checking only the
*head* but not the "type".

So, to both successfully assign the upvalue AND check "type", I usually
use something like:

  foo /: bar[f_foo?fooQ] := First[f] * Last[f]

which works fine.

Question: is there a syntactically more compact solution?


  • Prev by Date: Re: Skewness problem
  • Next by Date: Re: general nth term of series
  • Previous by thread: Re: A list of numbers without "73"
  • Next by thread: Re: A more syntactically compact way?