Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1995
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1995

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

Search the Archive

Re: Get Parts of Expression by Position list

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg391] Re: Get Parts of Expression by Position list
  • From: Xah Y Lee <xyl10060 at fhda.edu>
  • Date: Mon, 9 Jan 1995 00:19:41 -0800 (PST)

>Problem: How to write a function that work like Part[] but 
>uses the syntax returned by Position[] to specify parts of expression.

Dearly Beloved MathGroupers,

I made a blunder in my previous message.

The reason for my Part function not to work is because myPart should be 
  {{3,2,3},{3,1,2},{5}} not {{3,2,3},{3,1,2},5}.

It will work now:
--
 myTree = Insert[Range[20],{{a,b,c}, Range[100,105]}, 3];
 myParts = {{3,2,3},{3,1,2},{5}};
 Fold[ Part[#1,#2]&, myTree, #]& /@ myParts
--
or, we could write a function. The function will emulate Part[] but uses 
the syntax returned by Position[] to specify parts of expression.
--
Clear[myPartFunction]

myPartFunction[ tree_List, pos_List] :=
	 Fold[ Part[#1,#2]&, tree, #]& /@ pos
--

 I'd be interested to know from WRI why they decided
 for Delete[] and Part[] to use different syntax as their argument.
 
 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: Unique List
  • Next by Date: mma2html program
  • Previous by thread: Get Parts of Expression by Position list
  • Next by thread: for Adam RUSSELL HALVORSEN