MathGroup Archive 2011

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

Search the Archive

Re: pattern bugs and comment on intuitive syntax for the New Year

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115164] Re: pattern bugs and comment on intuitive syntax for the New Year
  • From: Armand Tamzarian <mike.honeychurch at gmail.com>
  • Date: Mon, 3 Jan 2011 03:56:07 -0500 (EST)
  • References: <ifpk7u$bsg$1@smc.vnet.net>

On Jan 2, 9:32 pm, Richard Fateman <fate... at cs.berkeley.edu> wrote:
>   Guess the results.
>
> x+3 /. x+c___ -> aha[c]
> x /. x+c___ -> aha[c]
> x /. x+c___:0 -> aha[c]
>
> compare to
>
> x+y+3 /. x+y+c___ -> aha[c]
> x+y  /. x+y+c___ -> aha[c]
> x+y  /. x+y+c___:0 -> aha[c]
> x+y+a+b  /. x+y+c___ :> aha[c]
> x+y+a+b  /. x+y+c___ :> aha[Plus[c]]
> x+y  /. x+y+c___ :> aha[Plus[c]]
>
> I think the requirement for the :0 represents a bug. Maybe the
> need for the Plus[], too. The treatment of NullSequences within
> a Flat operator could be different, leaving an operator around.
>
> ............
>
> Another item. really, syntax.
>
> define
>
> GreaterThan[q_]:= #>q&
> gt2=GreaterThan[2]   (* a function of one argument.
>                          is that argument > 2? =
*)
>
> mm[2, 10] /. mm[q_, s_?GreaterThan[q]] :> aha[q, s]
>
>   doesn't give aha..
>
> mm[2, 10] /. mm[q_, s_?gt2] :> aha[q, s]
>
> does give aha
>
> this works, though.
> mm[2, 10] /. mm[q_, s_?(GreaterThan[q])] :> aha[q, s]


Not with version 8 on Mac OS X 10.6.5 ...but I didn't expect it to.
The syntax coloring should indicate why.


>
> I love that intuitive syntax. None of that excess
> parentheses and stuff. (sarcasm)


All you had to do is try these to lines:

mm[2, 10] /. mm[q_, s_?(# > 2 &)] :> aha[q, s] (works)

mm[2, 10] /. mm[q_, s_?# > 2 &] :> aha[q, s] (doesn't work, nor should
it be expected to work)

mm[2, 10] /. mm[q_, s_?(# > q &)] :> aha[q, s] (doesn't work, nor
should it be expected to work)


>
> This error would have been
> much more apparent in Lisp.


It is also much more apparent when you read the documentation about
the precedence of "?"


>
> happy new year.

thanks


  • Prev by Date: Re: Import, ReadList, and Unicode
  • Next by Date: Re: Trial version of Mathematica 8 restrictions and a
  • Previous by thread: pattern bugs and comment on intuitive syntax for the New Year
  • Next by thread: Re: pattern bugs and comment on intuitive syntax for the New Year