While or not to While that is the question :)

• To: mathgroup at smc.vnet.net
• Subject: [mg46839] While or not to While that is the question :)
• From: János <janos.lobb at yale.edu>
• Date: Tue, 9 Mar 2004 19:57:58 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```Hi,

Inside a While loop I slide on a nested list like
{a,{g,c},{t,a},c,g,a,{g,c},{a,t},c,,g,a,t,t}.  Let's say I start after
{t,a} and {a,t} parallel - positions 4 and 9, that is element c and c.
If I find a single element then I pair it with its corresponding DNA
complement, a->t, t->a, c->g, g->c and replace the element with a
sublist of the element and its complement.  So, after the first step my
list will look like
{a,{g,c},{t,a},{c,g},g,a,{g,c},{a,t},{c,g},g,a,t,t}.  If I find a
double, like the {g,c} on position 7, then first I create a triplet
from it {g,c,c} - the original c in the double is now on the third
position inside the triplet -, and then after some housekeeping I take
the third element of the triplet off and put it into another bucket, so
the triplet becomes a double again and in the While I slide happily
further right on the nested list.   In the above example I would hit
{g,c} after 4 steps.  If I run the While, let say for 5 or more steps,
it errors out complaining that I want to select some parts of the empty
{} list.  If I ran it for 4 steps and then I manually execute ALL the
statements inside the While for step 5, I do not see any complains and
I can go up to as many steps manually, by increasing the loop variable,
as my heart desires.

As being a newbie I have not learned yet to use Modules or Blocks , - I
am still just at page 320 in the book - so all my variables are
globals.

So my first question is why I am getting different results if I execute
the while programatically, for 5 steps, compared to executing it for 4
steps and do the 5th step manually?  I am using 5.0.1 on OS X.

The first error message I get is this:
\!\(\*
RowBox[{\(ReplacePart::"partw"\), \(\(:\)\(\ \)\), "\<\"Part
\\!\\({1, 2}\\)
of \\!\\({}\\) does not
exist. \\!\\(\\*ButtonBox[\\\"More?\\\", \
ButtonData:>\\\"General::partw\\\"]\\)\"\>"}]\)

So, my second question is how to use Trace to determine where in the
code do I get the first  "partw" ?  I use ReplacePart in 4 places
inside the While, but at manual execution none of them complain.

I am sure my code is far from perfect, but still it should give the
same result on both cases.

János

-------------------------------------------------
clear perl code is better than unclear awk code; but NOTHING comes
close to unclear perl code
http://www.faqs.org/faqs/computer-lang/awk/faq/

```

• Prev by Date: How to give back to an image using "Net/Link" and "asp.net"?
• Next by Date: bessel function with complex order
• Previous by thread: Re: How to give back to an image using "Net/Link" and "asp.net"?
• Next by thread: Re: While or not to While that is the question :)