MathGroup Archive 1995

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

Search the Archive

Programming: List Structure Manipulation

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg872] Programming: List Structure Manipulation
  • From: Xah Y Lee <xyl10060 at fhda.edu>
  • Date: Thu, 27 Apr 1995 01:44:36 -0400

Can anyone show me better ways to write the following function?

fun[listA_, styleList_]:=
   Table[
      Append[
          Flatten@{ First@RotateLeft[styleList,t-1] },  listA[[t]]
      ],
      {t, Length@listA}
  ]

Examples:

fun[Range[0,5],  {a}]         returns

{{a, 0}, {a, 1}, {a, 2}, {a, 3}, {a, 4}, {a, 5}}

--
fun[Range[0,5],  {a,b,c}]         returns

{{a, 0}, {b, 1}, {c, 2}, {a, 3}, {b, 4}, {c, 5}}

--
fun[Range[0,10],  {{a1, a2}, b}]         returns

{{a1, a2, 0}, {b, 1}, {a1, a2, 2}, {b, 3}, {a1, a2, 4}, {b, 5}, {a1, a2, 
6}, {b, 7}, {a1, a2, 8}, {b, 9}, {a1, a2, 10}}

--
fun[Range[0,10],  {{a1, a2}, {{b}}, {c1,c2} }]         returns

{{a1, a2, 0}, {b, 1}, {c1, c2, 2}, {a1, a2, 3}, {b, 4}, {c1, c2, 5}, 
   {a1, a2, 6}, {b, 7}, {c1, c2, 8}, {a1, a2, 9}, {b, 10}}

Thanks.

I am writing a special Plot function, and I need to emulate the behavior of 
PlotStyle in *Plot commands. My current approach above using Append and 
RotateLeft is a slow method.

 Xah Lee            xyl10060 at tiptoe.fhda.edu
                 74631.731 at compuserve.com




  • Prev by Date: Challenge!
  • Next by Date: Re: How can I make a complicated Fit.
  • Previous by thread: Re: Challenge!
  • Next by thread: Re: Programming: List Structure Manipulation