Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Bug Reports / [U6RC2] For/Next strangeness

Author
Message
Benjamin
14
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 29th Mar 2006 18:32
Well, firstly I didn't know that for next loops call a function every iteration if used as a parameter, until today. After hearing this I decided to see whether it was true or not. In the process I found what seems to be a bug. It seems the function will get called twice an iteration, which seems unnecessary.

+ Code Snippet

Tempest - P2P UDP Multiplayer Plugin - 70%
Download the free version
blanky
13
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: ./
Posted: 29th Mar 2006 18:43 Edited at: 29th Mar 2006 18:43
I god he's right.



... installing gentoo ...

Attachments

Login to view attachments
re faze
12
Years of Service
User Offline
Joined: 24th Sep 2004
Location: The shores of hell.
Posted: 30th Mar 2006 00:24
that's probably quite a speed hit !

LeeBamber
TGC Lead Developer
17
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 31st Mar 2006 12:59
Fixed for U6 RC4:

* FOR NEXT loop step value must now be a literal value

"Small, smart, and running around the legs of dinosaurs to find enough food to survive, bedroom programmers aren't extinct after all "
IanM
Moderator
14
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 31st Mar 2006 14:26
Does that rule out variables or calculations too?

For free Plug-ins and source code http://www.matrix1.demon.co.uk
LeeBamber
TGC Lead Developer
17
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 31st Mar 2006 16:09
Yes, anything dynamic that is not known prior to compile time.

"Small, smart, and running around the legs of dinosaurs to find enough food to survive, bedroom programmers aren't extinct after all "
re faze
12
Years of Service
User Offline
Joined: 24th Sep 2004
Location: The shores of hell.
Posted: 31st Mar 2006 16:32
this isnt for while loops too is it?

Cryptoman
13
Years of Service
User Offline
Joined: 24th Nov 2003
Location: Utah Mountains
Posted: 31st Mar 2006 17:04
Wow, that could really ruin dynamic coding, actually writing different functions for different step loops.


LeeBamber
TGC Lead Developer
17
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 31st Mar 2006 17:09
No, just FOR NEXT loop. You could argue that giving the step direction choice to the user for the benefit of speed in preferable to heavy handed assumption that every for next loop must carry dynamic handling code for a generic solution

"Small, smart, and running around the legs of dinosaurs to find enough food to survive, bedroom programmers aren't extinct after all "
IanM
Moderator
14
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 31st Mar 2006 19:20
I really thing that you need to rethink this particular fix ...

When I saw this bug originally, I thought the fix would be to stop the double-call of the function, not to remove all ability to supply expressions completely.

What do we do if the lower or upper limit of the loop is not known until runtime? So I can no longer do this?

for i=0 to array count( MyArray() )

No other language that I'm aware of has this limitation. You may as well remove the for/next construct completely if you do this.

For free Plug-ins and source code http://www.matrix1.demon.co.uk
spooky
14
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 31st Mar 2006 19:52
We absolutely MUST be able to use variables as either the 'from' or 'to' parameter. These will not be known at compile time.

for f=1 to 10
for g=1 to f
print f;" ";g
next g
next f
wait key

@Lee - You talk lots about the 'step' value in your 'fix' but that is not the problem being talked about.

Boo!
empty
14
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 31st Mar 2006 19:53 Edited at: 31st Mar 2006 19:54
I believe there is a litte misunderstanding on both sides.
From Lee's quote "* FOR NEXT loop step value must now be a literal value"
and his code
+ Code Snippet

it's about the step value (FOR i = startval TO endval STEP literal).
However, that wouldn't kill this particular bug.

LeeBamber
TGC Lead Developer
17
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 31st Mar 2006 21:07
To clarify, the only thing that has changed is that IF you specify the STEP command after FOR NEXT, the step value alone must be a compile-time literal, so all these are ok:

for i=0 to array count( MyArray() )
for g=1 to f
for x#=0.0 to MyFunction()
for t=1 to lee step 1
for t=10 to 1 step -1

but this is not from U6 onwards:

lee=-1
for t=10 to 1 step lee
next t

or:

lee=1
for t=1 to 10 step lee
next t

For this price, you get a faster FOR NEXT loop and a single call to the function per iteration.

"Small, smart, and running around the legs of dinosaurs to find enough food to survive, bedroom programmers aren't extinct after all "
IanM
Moderator
14
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 31st Mar 2006 21:09
Oh, well I guess we can live with that then I suppose

For free Plug-ins and source code http://www.matrix1.demon.co.uk
Teh Go0rfmeister
14
Years of Service
User Offline
Joined: 17th Aug 2003
Location:
Posted: 2nd Apr 2006 12:02
Quote: "Oh, well I guess we can live with that then I suppose "


yes, we certainly could

*cries in a corner*

*sniffle*, my beautiful code, ruined!!!!!!!

OSX Using Happy Dude
14
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 2nd Apr 2006 12:06
Cry baby!

It does however reduce the chance of dodgy programming, eg :

+ Code Snippet

for example, or

+ Code Snippet

Teh Go0rfmeister
14
Years of Service
User Offline
Joined: 17th Aug 2003
Location:
Posted: 2nd Apr 2006 12:17 Edited at: 2nd Apr 2006 12:20
ok, im confused, anyone care to explain a work around for the code below?

when w=16 and half=(w+2)/2 = 9

+ Code Snippet

i get the whole literal value majigger when i add the step

Lost in Thought
13
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 2nd Apr 2006 12:45
Quote: "ok, im confused, anyone care to explain a work around for the code below?"


Yes use DGSDK

Zeal
14
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 2nd Apr 2006 13:11
Quote: "Yes use DGSDK"


Booya!

All you need is zeal
IanM
Moderator
14
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Apr 2006 13:32
@Teh Go0rfmeister,

Yes, there are quite a few workarounds

+ Code Snippet

The only drawback with the alternate for/next loops is that the number of iterations is fixed ... but that's what a for/next loop is about isn't it?

For free Plug-ins and source code http://www.matrix1.demon.co.uk
Benjamin
14
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 2nd Apr 2006 13:46 Edited at: 2nd Apr 2006 14:06
Quote: " ok, im confused, anyone care to explain a work around for the code below?"

I think this is the kind of thing you need:

+ Code Snippet

I've tested it a bit, it seems to work as it should. If it wasn't for that damn divide by zero error that if statement wouldn't be necessary(of course, the calculation in it would still be).

Tempest - P2P UDP Multiplayer Plugin - 70%
Download the free version
Lost in Thought
13
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 2nd Apr 2006 13:47
Benjamin that code is legal. Only the step value must be literal.

Benjamin
14
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 2nd Apr 2006 13:50
Quote: "Only the step value must be literal"

Indeed.. what's your point? Have I missed something?

Tempest - P2P UDP Multiplayer Plugin - 70%
Download the free version
Lost in Thought
13
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 2nd Apr 2006 13:56
Or perhaps since I am a bit sleepy still, I have

Teh Go0rfmeister
14
Years of Service
User Offline
Joined: 17th Aug 2003
Location:
Posted: 2nd Apr 2006 14:03
heh

i preffered when i could use step >.<

Teh Go0rfmeister
14
Years of Service
User Offline
Joined: 17th Aug 2003
Location:
Posted: 2nd Apr 2006 14:18 Edited at: 2nd Apr 2006 14:22
+ Code Snippet

have i doneit correctly? i get a error saying array out of bounds, but i can't see why...

Philip
14
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 2nd Apr 2006 14:51
This seems to be a highly controversial fix.

Cheer if you like bears! Cheer if you like jam sandwiches!
Quote of the week: "I highly recommend Philip's Vector Tutorials" (RiiDii)
OSX Using Happy Dude
14
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 2nd Apr 2006 15:55
Indeed.

Gorfy - I would print all your values to a screen - its possible one or more are negative...

Teh Go0rfmeister
14
Years of Service
User Offline
Joined: 17th Aug 2003
Location:
Posted: 2nd Apr 2006 16:00
ok it's all under control now, still getting used to it though

cheers people

IanM
Moderator
14
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Apr 2006 19:27
Quote: "This seems to be a highly controversial fix"


I agree too. It's not often that you'll want to change the step value mid-loop, but it does happen. Goorfs code is one example, a sort routine I have is another.

It's also a bit strange that for loops check the step value twice - once to update the counter, and once to ...? maybe to check the loop direction? Can't think of another reason, but why wouldn't you cache the result in a spare register or on the stack and reuse it?

I've knocked together this C++ code to show that there is no need to calculate either the final value or the step value more than once per loop. The assembly that it generates is fairly tight, but it puts the TempStep variable on the stack, when it could probably be kept in EAX while it is needed.

+ Code Snippet

For free Plug-ins and source code http://www.matrix1.demon.co.uk
Cryptoman
13
Years of Service
User Offline
Joined: 24th Nov 2003
Location: Utah Mountains
Posted: 2nd Apr 2006 20:51
No, its crap, even the TRS80 model 1 could use variable in the step value. CoCo 1,2,3 basic written by microsoft for tandy was the best bug free basic around and which many basics evolved around their structure. If the core would function like the COCO extended basic then many simple bugs would be eliminated. The basic core of BASIC should never change, only add unto the base.


Philip
14
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 2nd Apr 2006 22:17
I think maybe Lee should be invited to reconsider.

Cheer if you like bears! Cheer if you like jam sandwiches!
Quote of the week: "I highly recommend Philip's Vector Tutorials" (RiiDii)
xtom
14
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Ireland
Posted: 2nd Apr 2006 22:44
Yeah, it's going to cause problems when someone trys to use a variable and doesn't know why it's not working. I'd rather have the initial bug than this fix, I know that's probably not good for everyone but.

Cryptoman
13
Years of Service
User Offline
Joined: 24th Nov 2003
Location: Utah Mountains
Posted: 2nd Apr 2006 22:50
Here is a disassembly of the microsoft interpreter, for the COCO, book for anyone that is interested.


Attachments

Login to view attachments
OSX Using Happy Dude
14
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 2nd Apr 2006 22:51
It should be noted that on the C64, the STEP value wasn't allowed to change, once it was in the loop. In this case, I do feel that the new action is correct, mainly because it stops various programming problems from creeping in.

HowDo
14
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 2nd Apr 2006 22:59
however stops you making a function with a for next loop in where you send it different values to use.

+ Code Snippet
I would have thought it should have been that we canot use a function in a for next loop; but get the answer before the loop eg-
+ Code Snippet

I'm not getting you down am I, Ho Look! another fancy Door?
OSX Using Happy Dude
14
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 2nd Apr 2006 23:05
Quote: "however stops you making a function with a for next loop in where you send it different values to use."

Precisely - it stops you having to debug problems, where the function returns 0, or a negative number...

LeeBamber
TGC Lead Developer
17
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 3rd Apr 2006 16:59
Fixed for U6 RC5:

* FOR NEXT loop step value now codes a fast ASM for literal step values and a slower, double-expression ASM for dynamic step values

"Small, smart, and running around the legs of dinosaurs to find enough food to survive, bedroom programmers aren't extinct after all "
adr
14
Years of Service
User Offline
Joined: 21st May 2003
Location: Job Centre
Posted: 3rd Apr 2006 17:15
Cmon Lee... I know you were dying to say "There! Happy now?" at the end of that post?

It's kinda like a long road trip with the parents... "If you kids don't stop squabling, there'll be no U6 for anyone!"

[center]
iv tryed everything!!!!!!!!!! could u please just add The gun and shooting Code thats All!!!!!!!!!
Teh Go0rfmeister
14
Years of Service
User Offline
Joined: 17th Aug 2003
Location:
Posted: 6th Apr 2006 01:52
WOW!!! THANKS LEE!!!!

<<huggle>>

Mnemonix
14
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: Skaro
Posted: 7th Apr 2006 19:47
Im glad you reconsidered that particular fix Lee
Im sure the pitchforks wont be brought to the next convention now.

WE SHALL BECOME ALL POWERFUL! CRUSH THE LESSER RACES! CONQUER THE GALAXY! UNIMAGINABLE POWER! UNLIMITED RICE PUDDING ! ! ! ETC. ! ! ! ETC.! ! !
Green Gandalf
12
Years of Service
User Offline
Joined: 3rd Jan 2005
Location: Cornwall UK
Posted: 7th Apr 2006 22:05
Quote: "Im glad you reconsidered that particular fix Lee"


Where, when?

Quote: "Im sure the pitchforks wont be brought to the next convention now."


No need, we're quite used to contriving suitable workarounds ...
Takis76
12
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 7th Apr 2006 22:52
Very strange this code worked perfet in my pc.


Quote: "
for x=1 to MyFunction()
print x
next x

wait key
end

function MyFunction()
print "test"
endfunction 5
"

Attachments

Login to view attachments
Green Gandalf
12
Years of Service
User Offline
Joined: 3rd Jan 2005
Location: Cornwall UK
Posted: 8th Apr 2006 01:56
Quote: "Very strange this code worked perfet in my pc."


Not strange at all - it was one of the things that Lee fixed.
musty
11
Years of Service
User Offline
Joined: 6th Apr 2006
Location: Istanbul
Posted: 9th Apr 2006 10:47
HÝ everyone. First of all I have to admit that I couldn't examine all of your snippet codes. If Lee wasn't kind enough to allow use of dynamic step value usage there would still be many ways around that problem. One of them is obviously to redesign the whole program or code block . One other way is to use while do loops and some other methods that you have previously mentioned in this thread. I would like to offer another one just for mind gymnastics' sake (I don't know if such a term even exists in English). You can set a fixed step value and control the actual iteration number of your code's action within the loop itself. For example the code I have given will print all the values of x in its first run but the second time around it will only print even values of x. You could increase the value of x by 1 and in its third running the loop will print x values which are multiples of 3. etc. I know this is a useless post but I feel I have to make a few posts every now and then. Happy coding to all of you.
Vues3d on Kalimee
13
Years of Service
User Offline
Joined: 12th May 2004
Location: NYON (SWITZERLAND)
Posted: 9th Apr 2006 12:17
So, really sorry for my dumbness...

If I understood, resuming the concept, intead of having

For a= 1 to 10 step 2
do something
next a

We have to write now:

value=2
for a=1 to 10 step VALUE
do something
next a

Right?????

If this is right... I will have days to correct this fix...
In my code I have tons of for next step.....


I have no doubts that this would be an interesting change, but it's really a pain to correct a huge code.
Some hours of pain in perspective....

(Right now I'm crying behind my screen!!!)

Lost in Thought
13
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 9th Apr 2006 12:44
You may need to re-read this thread. Where in the world did you get that idea from

Vues3d on Kalimee
13
Years of Service
User Offline
Joined: 12th May 2004
Location: NYON (SWITZERLAND)
Posted: 9th Apr 2006 15:23
it cames from the fact that I updated & any of my For next function works... I get messages that tells I need to put "letters" instead of numbers.

If I haven't understood well, what have I to do in order to make the for next step working again?

Lost in Thought
13
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 9th Apr 2006 15:26
Both of those codes you posted work here in U6 RC6. If you post the ones that don't work we can help you understand why or confirm it is a bug or not.

Chris Franklin
12
Years of Service
User Offline
Joined: 2nd Aug 2005
Location: UK
Posted: 9th Apr 2006 15:39 Edited at: 9th Apr 2006 15:40
Worked here as well in rc6

Edit: Tgc's First HOT bug?!?!?!

Theme park simulator wip

Login to post a reply

Server time is: 2017-08-22 12:17:16
Your offset time is: 2017-08-22 12:17:16