MathGroup Archive 1995

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

Search the Archive

Get Parts of Expression by Position list

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg390] Get Parts of Expression by Position list
  • From: Xah Y Lee <xyl10060 at fhda.edu>
  • Date: Sun, 8 Jan 1995 23:35:23 -0800 (PST)

Dearly beloved MathGroupers,

Dana_Scott at POP.CS.CMU.EDU raised an interesting question when he 
mentioned a possible design fault with mma syntax of Part[] and Delete[]. 
([mg374])

The question I thought of from his message is: How to write a function 
that emulate Part[] but uses the syntax of Delete[]?

I had some partial success, but still have some problems.
Here's my "progress".
--
(*here I define myTree *)
myTree = Insert[Range[20],{{a,b,c}, Range[100,105]}, 3];
--
(* here are the positions in myList that I am interested to get *)
myParts = {{3,2,3},{3,1,2},5};
--
(* this gives me the first one *)
myTree[[3]][[2]][[3]]
--
(* or we can do*)
Fold[ Part[#1,#2]&, myTree, {3,2,3}]
--
(* Now we try to get them all at once *)
Fold[ Part[#1,#2]&, myTree, #]& /@ myParts
(*this doesn't work*)
--

Why doesn't the last one work?
Is there a better way to do this?
Also, I'd be interested to know from WRI why they decided
for Delete[] and Part[] to have different syntax.

It seems to me functions like Part[] or Take[] would be better off using 
the syntax returned by Position[] like in Delete[].


There once was a brainy baboon     | Xah Lee
Who always breathed down a bassoon,| xyl10060 at tiptoe.fhda.edu
For he said, "It appears           |
That in billion of years           |
I shall certainly hit on a tune."  <-- Author not known to me.



  • Prev by Date: Re: Re: Unique List
  • Next by Date: for Adam RUSSELL HALVORSEN
  • Previous by thread: Re: Problem with Contexts
  • Next by thread: Re: Get Parts of Expression by Position list