[Date Index]
[Thread Index]
[Author Index]
Re: Insulating data from code
*To*: mathgroup at smc.vnet.net
*Subject*: [mg66595] Re: Insulating data from code
*From*: "Pratik Desai" <pratikd at wolfram.com>
*Date*: Sun, 21 May 2006 22:30:41 -0400 (EDT)
*References*: <e4ekai$9av$1@smc.vnet.net><e4jtnn$d02$1@smc.vnet.net> <e4mn63$6o7$1@smc.vnet.net> <e4or6i$6cr$1@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
Peter Pein wrote:
> Paul Abbott schrieb:
> > In article <e4jtnn$d02$1 at smc.vnet.net>, Peter Pein <petsie at dordos.net>
> > wrote:
> >
> >> Ray Koopman schrieb:
> >>> >From time to time I've wanted to partition the first level of one
> >>> list, say A, the same way that another list, say B, is partitioned.
> >>> One way to do this is
> >>>
> >>> copyPartition[A_List, B_List] /; Length@A >= Length@Flatten@B :=
> >>> Module[{i = 0}, Map[A[[++i]]&,B,{-1}]]
> >>>
> >>> But all the methods I've thought of have a pointer that functions
> >>> something like i in the above code. I'd like to eliminate the pointer,
> >>> because in the unlikely event that A contains an unevaluated symbol
> >>> that is the same as the name of the pointer with $ appended -- e.g.,
> >>> i$, if the pointer is i -- then in the returned list that symbol will
> >>> have a numeric value assigned to it. Unique[i] doesn't help. The
> >>> only solution I see is the probabilistic one of giving the pointer a
> >>> strange (random?) name that hopefully would be very unlikely to show
> >>> up as data. But that would be giving up. Does anyone have any ideas?
> >>>
> >> Hi Ray,
> >>
> >> use Replace[]:
> >>
> >> A={a,b,c,d,e};
> >> B={{1},{2,3},{{{4}},5}};
> >>
> >> Ap=B/.Thread[Flatten[B]\[Rule]A]
> >> --> {{a},{b,c},{{{d}},e}}
> >
> > No, that won't work. Try
> >
> > A={a,b,c,d,a};
> > B={{1},{2,1},{{{3}},2}};
> >
> > Ap=B/.Thread[Flatten[B] -> A]
> >
> > You get
> >
> > {{a}, {b, a}, {{{d}}, b}}
> >
> > whereas I think the OP wanted
> >
> > {{a}, {b, c}, {{{d}}, a}}
> >
> > Cheers,
> > Paul
> >
> > _______________________________________________________________________
> > Paul Abbott Phone: 61 8 6488 2734
> > School of Physics, M013 Fax: +61 8 6488 1014
> > The University of Western Australia (CRICOS Provider No 00126G)
> > AUSTRALIA http://physics.uwa.edu.au/~paul
> >
> Hi Paul,
>
> well, I recognized this and came to a solution similar to J. Siehler's:
>
> A={a,{b,{c,{d,{e}}}},f};
> B={x,{x},{{x,x},x},x};
>
> cpStruct=ReplacePart[##,
> Sequence@@(Position[#,_,{-1},Heads->False]&/@{##})]&;
>
> cpStruct[B,A]
> --> {a,{b},{{c,d},e},f}
>
> Peter
Maybe something like this ??
In[1]:=
Clear[list,skeletor]
A={a,b,c,d,e};
B={{1},{3,5},{{{5}},5}};
skeletor[list1_?
ListQ,list2_?ListQ] /;Length@list2=Length@Flatten@list1:=list1/.{
x_?NumberQ\[RuleDelayed]Hold[Part[list1,x]]}/.{list1\[RuleDelayed]list2}
skeletor[B,A]//ReleaseHold
Out[5]=
{{a},{c,e},{{{e}},e}}
Pratik Desai
Wolfram Research, Inc
Technical Support
Prev by Date:
**Re: Exporting Graphics to .eps**
Next by Date:
**Unit sphere triangulation**
Previous by thread:
** Re: Insulating data from code**
Next by thread:
**Re: Insulating data from code**
| |