1. Yagl update(again) + coding problem.

The library is done but delayed since I wanted to write a good demo or two
before releasing it and I've been pretty busy.

My problem has to do with this piece of code:

dist = sqrt((209+p[ix_part][a]-p[x_part][a])*(209[p[ix_part][a]-p[x_part][a])+
(138+p[iy_part][a]-p[y_part][a])*(138+p[iy_part][a]-p[y_part[a]))


The interpreter always crashes with a:

Syntax error - expected to see possibly ')', not '['
dist = sqrt((209+p[ix_part][a]-p[x_part][a])*(209[p[ix_part][a]-p[x_part][a])+
(138+p[iy_part][a]-p[y_part][a])*(138+p[iy_part][a]-p[y_part[a]))

Either I'm too dense or something, but I've checked it over a dozen times and
can't find any problem.

Jeremy *argh*

new topic     » topic index » view message » categorize

2. Re: Yagl update(again) + coding problem.

Jeremy Peterson wrote:

The last part should read...

 p[y_part][a]))

You left out a ']' after 'y_part'

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view message » categorize

3. Re: Yagl update(again) + coding problem.

Thanks Derek.  After fixing that and another bug, I have this:
dist =
sqrt((209+p[ix_part][a]-p[x_part][a])*(209+[p[ix_part][a]-p[x_part][a])+(138+p[iy_part][a]-p[y_part][a])*(138+p[iy_part][a]-p[y_part][a]))


And it errors again with:

Syntax error - expected to see an expression, not '['
dist =
sqrt((209+p[ix_part][a]-p[x_part][a])*(209+[p[ix_part][a]-p[x_part][a])+(138+p[iy_part][a]-p[y_part][a])*(138+p[iy_part][a]-p[y_part][a]))

		                                                  ^

Strange, I can't see anything wrong with (138 + p[iy_part][a] - p[y_part][a]))

Jeremy

new topic     » goto parent     » topic index » view message » categorize

4. Re: Yagl update(again) + coding problem.

Jeremy Peterson wrote:
> 
> Thanks Derek.  After fixing that and another bug, I have this:
> }}}
<eucode>
> dist =
> sqrt((209+p[ix_part][a]-p[x_part][a])*(209+[p[ix_part][a]-p[x_part][a])+(138+p[<font
> color="#330033">iy_part][a]-p[y_part][a])*(138+p[iy_part][a]-p[y_part][a]))
> </eucode>
{{{

> 
> And it errors again with:
> 
> Syntax error - expected to see an expression, not '['
> 		dist =
> sqrt((209+p[ix_part][a]-p[x_part][a])*(209+[p[ix_part][a]-p[x_part][a])+(138+p[iy_part][a]-p[y_part][a])*(138+p[iy_part][a]-p[y_part][a]))
> 
> 		                                                  ^
> 
> Strange, I can't see anything wrong with (138 + p[iy_part][a] - p[y_part][a]))
> 
> Jeremy

you have a '[' before t p in " 209+[p[ix_part][a]-p[x_part][a]) " ... see

nb. theese sorts of equations are best writen like so...
dist = sqrt(
    (209+p[ix_part][a]-p[x_part][a]) *
    (209+[p[ix_part][a]-p[x_part][a]) + -- now you can see the extra '['
    (138+p[iy_part][a]-p[y_part][a]) *
    (138+p[iy_part][a]-p[y_part][a]) )

> 


Hayden McKay...

new topic     » goto parent     » topic index » view message » categorize

5. Re: Yagl update(again) + coding problem.

Thanks Hayden, that fixed it.

Jeremy

new topic     » goto parent     » topic index » view message » categorize

6. Re: Yagl update(again) + coding problem.

On Mon, 07 Aug 2006 12:09:01 -0700, Jeremy Peterson
<guest at RapidEuphoria.com> wrote:

>My problem has to do with this piece of code:
>
>}}}
<eucode>
>dist = sqrt((209+p[ix_part][a]-p[x_part][a])*(209[p[ix_part][a]-p[x_part][a])+
>(138+p[iy_part][a]-p[y_part][a])*(138+p[iy_part][a]-p[y_part[a]))
></eucode>
{{{

As someone else has probably already said, error is in "*(209[p["
part, which should be "*(209+p[". At the end of the expression you
will also find "p[y_part[a]))" which is missing a closing "]".

However, there is a more grave error here in style. I rewrote that
code firstly as follows (factoring out the common subscripts):
object pixa, pxa, piya, pya
    pixa = p[ix_part][a]
    pxa = p[x_part][a]
    piya = p[iy_part][a]
    pya = p[y_part][a]
dist = sqrt((209+pixa-pxa)*(209+pixa-pxa)+
(138+piya-pya)*(138+piya-pya))
</eucode
And immediately repeated with the new common expressions:
}}}
<eucode>
object pixa, pxa, piya, pya
object x,y
    pixa = p[ix_part][a]
    pxa = p[x_part][a]
    piya = p[iy_part][a]
    pya = p[y_part][a]
    x = 209+pixa-pxa
    y = 138+piya-pya
    dist = sqrt(x*x+ y*y)
</eucode
Now, I know what you are thinking - it'll be slower. No it will not!
In fact I predict it will be nearly twice as fast because there are
six expressions there now calculated once, not twice.

Internally the compiler converts complex expressions into simpler code like the above which uses "hidden" temporary work variables that behave exactly the same as any you explicitly create.

As well as the code being easier to write, easier to read, and faster, it will also be easier to debug because trace()/ex.err can show you a bit more directly what is happening.

Note that you should use atoms or integers rather than objects where possible, but maybe you can't here [?]. Obviously, I've used names such as pixa because I don't really know what the code is doing, (of course I have a much clearer idea after the rewrites), but you should be able to pick better & more meaningful names as well.

Regards, Pete }}}

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu