MathGroup Archive 2006

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

Search the Archive

Re: Insulating data from code

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66567] Re: Insulating data from code
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Sat, 20 May 2006 04:47:28 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 5/17/06 at 3:29 AM, koopman at sfu.ca (Ray Koopman) wrote:

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

Here is an alternative that has no explicit pointer and avoids the issue you mention

copyPartition[A_List, B_List] :=
  ((Take[A, #]) & /@ Transpose@{Most@#, 
        Rest@# - 1}) &[FoldList[Plus, 1, Length /@ B]]
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: queuing network model
  • Next by Date: Re: What's wrong with Integrate [ 1/x, {x,1,Infinity}]?
  • Previous by thread: Re: Insulating data from code
  • Next by thread: Re: Insulating data from code