Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6279 > unrolled thread

Re: Scoping of pattern names

Started byRui Rojo <rui.rojo@gmail.com>
First post2011-11-08 12:24 +0000
Last post2011-11-11 10:01 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Scoping of pattern names Rui Rojo <rui.rojo@gmail.com> - 2011-11-08 12:24 +0000
    Re: Scoping of pattern names Rui <rui.rojo@gmail.com> - 2011-11-11 10:01 +0000

#6279 — Re: Scoping of pattern names

FromRui Rojo <rui.rojo@gmail.com>
Date2011-11-08 12:24 +0000
SubjectRe: Scoping of pattern names
Message-ID<j9b72o$4ud$1@smc.vnet.net>
Yeah, it helps. For some reason I only use "?" for predicates or very
simple functions, and got used to using /; for more complex checking. But
it all works fine doing like you suggested for simple cases. I'll just have
to start indexing with #[[]] for more complex behaviour like

h[p_][a_, b_, c_, head[e_, f_]]/;Divisible[p, e] && b===f
h[_][_,_, _, head[_, _]]?(Divisible[#[[0, 1]], #[[4, 1]]] && #[[2]]===#[[4,
2]])&

Can get ugly at times but...whatever works. Thanks

On Mon, Nov 7, 2011 at 8:58 AM, Bob Hanlon <hanlonr357@gmail.com> wrote:

> I'm not sure what you are trying to do. This may help.
>
> pat = _?(# == 8 &);
>
> Cases[Range[20], 2 | pat | _?OddQ]
>
> {1, 2, 3, 5, 7, 8, 9, 11, 13, 15, 17, 19}
>
>
> Bob Hanlon
>
> On Mon, Nov 7, 2011 at 5:53 AM, Rui <rui.rojo@gmail.com> wrote:
> > My goal:
> > store a pattern in a variable for future use
> >
> > My problem:
> > if the pattern I stored has a pattern name in it, (like i_/;i=8),
> > and I use it later to build a new pattern in which I use the stored
> pattern twice, it thinks its the same name (i)
> >
> > My investigation:
> > So far, couldn't find any way to scope pattern's names in a useful way.
> > Module and With, refuse to scope a pattern name that's somewhere on the
> left hand side of a condition contained in them.
> >
> >
> > Sure, I probably haven't tried much yet to build what I want with hard
> expression manipulation, but... I found my objective neat simple and
> useful...
> > I would like to know if there's a proper way to do this, or to achieve
> my objective somehow else. And, I'd also enjoy knowing why such a
> resistance to scope pattern names...
> >

[toc] | [next] | [standalone]


#6370

FromRui <rui.rojo@gmail.com>
Date2011-11-11 10:01 +0000
Message-ID<j9irpu$8ff$1@smc.vnet.net>
In reply to#6279
Thanks Roger, you understood my problem correctly

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web