MathGroup Archive 2005

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

Search the Archive

A more syntactically compact way?

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

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?


Trevor.


  • 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?