Jump to content

Photo

Brain lapse


22 replies to this topic

#1 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • 10,179 posts
  • Location:Hustisford, WI

Posted Thu Nov 15, 2018 5:28 PM

I'm having a brain lapse right now... please assist!

 

This first piece of code fails with a syntax error.  The second functions as expected.

 

 

Thanks!

 

 
10 CALL CLEAR :: FOR T=110 TO 880 STEP 110 :: IF T=770 THEN S=834 ELSE S=T :: CALL SOUND(200,220,1,440,1,S,1):: NEXT T :: GOTO 10
 
 
 
10 CALL CLEAR
20 FOR T=110 TO 880 STEP 110
30 IF T=770 THEN S=834 ELSE S=T
40 CALL SOUND(200,220,1,440,1,S,1)
50 NEXT T
60 GOTO 10
 

 



#2 FarmerPotato OFFLINE  

FarmerPotato

    Chopper Commander

  • 173 posts
  • Location:Austin, TX

Posted Thu Nov 15, 2018 5:50 PM

I'm having a brain lapse right now... please assist!

 

This first piece of code fails with a syntax error.  The second functions as expected.

 

 

Thanks!

 
10 CALL CLEAR :: FOR T=110 TO 880 STEP 110 :: IF T=770 THEN S=834 ELSE S=T :: CALL SOUND(200,220,1,440,1,S,1):: NEXT T :: GOTO 10
 
 
 
10 CALL CLEAR
20 FOR T=110 TO 880 STEP 110
30 IF T=770 THEN S=834 ELSE S=T
40 CALL SOUND(200,220,1,440,1,S,1)
50 NEXT T
60 GOTO 10
 

Everything after the ELSE is part of the ELSE statement2.

 

You would need to start a new line after S=T.

 

Or embed the comparison in a formula like this:

10 CALL CLEAR :: FOR T=110 TO 880 STEP 110 :: S=T-(T=770)*64 :: CALL SOUND(200,220,1,440,1,S,1):: NEXT T :: GOTO 10


#3 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • Topic Starter
  • 10,179 posts
  • Location:Hustisford, WI

Posted Thu Nov 15, 2018 6:05 PM

Balls, that's clever.

I don't fully get the T=770 within the parenthesis multiplied by 64, but it works.

Care to break it down a bit for me?

#4 Lee Stewart OFFLINE  

Lee Stewart

    River Patroller

  • 3,832 posts
  • Location:Silver Run, Maryland

Posted Thu Nov 15, 2018 6:13 PM

Balls, that's clever.

I don't fully get the T=770 within the parenthesis multiplied by 64, but it works.

Care to break it down a bit for me?

 

I should give Erik a chance to answer, but (T=770) is a logical relational expression that evaluates to TRUE (-1) or FALSE (0).  You can do the rest of the math, I think.  [See Erik’s (FarmerPotato’s) post below.]

 

...lee



#5 Opry99er OFFLINE  

Opry99er

    Quadrunner

  • Topic Starter
  • 10,179 posts
  • Location:Hustisford, WI

Posted Thu Nov 15, 2018 6:24 PM

Interesting. Mongo only pawn, in game of life.

#6 FarmerPotato OFFLINE  

FarmerPotato

    Chopper Commander

  • 173 posts
  • Location:Austin, TX

Posted Thu Nov 15, 2018 6:44 PM

Balls, that's clever.

I don't fully get the T=770 within the parenthesis multiplied by 64, but it works.

Care to break it down a bit for me?

 

From page 41 of the XB manual

RELATIONAL EXPRESSIONS

 Relational expressions are most often used in the IF-THEN-ELSE statement, but may be used anywhere that numeric expressions are allowed. 
A relational expression has a value of -1 if it is true and a value of 0 if it is false

Evaluate S=T-(T=770)*64

 

T    T=770  *64   T-that
===  =====  ===   =====
660    0      0     660
770   -1    -64     834
880    0      0     880




#7 HOME AUTOMATION OFFLINE  

HOME AUTOMATION

    Chopper Commander

  • 173 posts

Posted Thu Nov 15, 2018 6:58 PM

This is as much as I think I know.

  (1+1=1)+(1+1=2)=1 or AND logic TRUE
  (1+1=1)*(1+1=2)=0 or OR  logic FALSE

     I hope I got this right. :roll:



#8 Lee Stewart OFFLINE  

Lee Stewart

    River Patroller

  • 3,832 posts
  • Location:Silver Run, Maryland

Posted Thu Nov 15, 2018 7:08 PM

This is as much as I think I know.

  (1+1=1)+(1+1=2)=1 or AND logic TRUE
  (1+1=1)*(1+1=2)=0 or OR  logic FALSE

     I hope I got this right. :roll:

 

Backwards.  :)

 

...lee



#9 HOME AUTOMATION OFFLINE  

HOME AUTOMATION

    Chopper Commander

  • 173 posts

Posted Thu Nov 15, 2018 7:21 PM

I thought you meant backwards so the answer is still right... than I reevaluated!

Hence...

 

  (1+1=1)+(1+1=2)=1 or OR   logic TRUE
  (1+1=1)*(1+1=2)=0 or AND  logic FALSE

 

    I took a pill... am I doing any better now. :lol:



#10 Lee Stewart OFFLINE  

Lee Stewart

    River Patroller

  • 3,832 posts
  • Location:Silver Run, Maryland

Posted Thu Nov 15, 2018 7:25 PM

I should add that any non-zero value is considered TRUE.  A relational expression that is true always evaluates to -1 (all bits on), so if you expanded your example to (1+1=1)+(1+1=2)+(1+2=3) = 0+(-1)+(-1), it would evaluate to -2, which is still considered true even though it does not evaluate to -1—simply because it is not 0.  If you want results that evaluate only to -1 when true, you would need to use the logical operators (OR,AND) on the relational expressions instead of the arithmetic operators (+,*).

 

...lee



#11 TheBF OFFLINE  

TheBF

    Dragonstomper

  • 821 posts
  • Location:The Great White North

Posted Thu Nov 15, 2018 7:41 PM

I thought you meant backwards so the answer is still right... than I reevaluated!

Hence...

 

  (1+1=1)+(1+1=2)=1 or OR   logic TRUE
  (1+1=1)*(1+1=2)=0 or AND  logic FALSE

 

    I took a pill... am I doing any better now. :lol:

 

I'm not very smart so I always like to get the machine's opinion on the matter. :-)

Attached Files



#12 HOME AUTOMATION OFFLINE  

HOME AUTOMATION

    Chopper Commander

  • 173 posts

Posted Thu Nov 15, 2018 8:01 PM

I started to fault your math... but had to hit backspace over and over again... that's pretty good mathing :)  I'm more procedural...

 

expanded expressions... (1+1=1)+(1+1=2)+(1+2=3) = OVERFLOW

 

Months back wrote a 100 line program to calculate the number of steps it took to drive a dot on an 8 x 8 matrix by counting down in reverse (many steps-very slow-unsteady). When my mind was clearer I realized about 10 lines with some multiply instructions would rocket. :)



#13 TheBF OFFLINE  

TheBF

    Dragonstomper

  • 821 posts
  • Location:The Great White North

Posted Thu Nov 15, 2018 8:09 PM

I started to fault your math... but had to hit backspace over and over again... that's pretty good mathing :)  I'm more procedural...

 

expanded expressions... (1+1=1)+(1+1=2)+(1+2=3) = OVERFLOW

 

Months back wrote a 100 line program to calculate the number of steps it took to drive a dot on an 8 x 8 matrix by counting down in reverse (many steps-very slow-unsteady). When my mind was clearer I realized about 10 lines with some multiply instructions would rocket. :)

 

I took my math from your post, so the credit is all yours.

 

Like I said, I'm not that smart.  :-D



#14 HOME AUTOMATION OFFLINE  

HOME AUTOMATION

    Chopper Commander

  • 173 posts

Posted Thu Nov 15, 2018 8:22 PM

Sorry, late post... I got bumped off the net...

 

I was responding to lee... :P



#15 InsaneMultitasker OFFLINE  

InsaneMultitasker

    River Patroller

  • 2,298 posts

Posted Thu Nov 15, 2018 8:27 PM


This first piece of code fails with a syntax error. 

 
10 CALL CLEAR :: FOR T=110 TO 880 STEP 110 :: IF T=770 THEN S=834 ELSE S=T :: CALL SOUND(200,220,1,440,1,S,1):: NEXT T :: GOTO 10

The syntax error is the result of using a IF/THEN conditional with the FOR/NEXT in the same line.  This is not allowed* under normal operation.

 

(If you turn off prescan you can get around this restriction; programmer beware. Heatwave uses this trick in a few places; I don't know what the true ramifications are, only that it is doable)



#16 RXB OFFLINE  

RXB

    River Patroller

  • 3,405 posts
  • Location:Vancouver, Washington, USA

Posted Fri Nov 16, 2018 11:39 AM

The syntax error is the result of using a IF/THEN conditional with the FOR/NEXT in the same line.  This is not allowed* under normal operation.

 

(If you turn off prescan you can get around this restriction; programmer beware. Heatwave uses this trick in a few places; I don't know what the true ramifications are, only that it is doable)

The result will be a non initialized variable and a crash of XB.

Now if the variable in question is already being used like X=11 and later it has FOR X=1 TO 10 it might work.

 

PRESCAN sets up variable names and locations, also Constants and looks for SYNTAX ERRORs or Illegal Line Numbers. 



#17 InsaneMultitasker OFFLINE  

InsaneMultitasker

    River Patroller

  • 2,298 posts

Posted Fri Nov 16, 2018 5:42 PM

The result will be a non initialized variable and a crash of XB.

Now if the variable in question is already being used like X=11 and later it has FOR X=1 TO 10 it might work.

 

PRESCAN sets up variable names and locations, also Constants and looks for SYNTAX ERRORs or Illegal Line Numbers. 

That might be true to some extent but as I mentioned, turning off prescan allows you to bypass the syntax error/restriction. I just don't know if there are any hidden issues as a result.  

 

Not only can you use the if/then with the for/next, you can have an extra NEXT statement under certain conditions. 

 

10 I,X=0

11 !@P-

100 FOR I=1 TO 10 :: IF I=5 then X=x+100 :: PRINT X;"I was 5" :: NEXT I

110 x=x+1 :: PRINT X :: NEXT I

 

I think Myarc's Advanced BASIC interpreter gets mucked up by doing this sort of thing.   I haven't encountered any ill effects with XB version 110. 



#18 RXB OFFLINE  

RXB

    River Patroller

  • 3,405 posts
  • Location:Vancouver, Washington, USA

Posted Fri Nov 16, 2018 8:17 PM

That might be true to some extent but as I mentioned, turning off prescan allows you to bypass the syntax error/restriction. I just don't know if there are any hidden issues as a result.  

 

Not only can you use the if/then with the for/next, you can have an extra NEXT statement under certain conditions. 

 

10 I,X=0

11 !@P-

100 FOR I=1 TO 10 :: IF I=5 then X=x+100 :: PRINT X;"I was 5" :: NEXT I

110 x=x+1 :: PRINT X :: NEXT I

 

I think Myarc's Advanced BASIC interpreter gets mucked up by doing this sort of thing.   I haven't encountered any ill effects with XB version 110. 

As I said PRESCAN looks for and sets up Variables so your example followed exactly what I said thanks.



#19 InsaneMultitasker OFFLINE  

InsaneMultitasker

    River Patroller

  • 2,298 posts

Posted Fri Nov 16, 2018 9:31 PM

As I said PRESCAN looks for and sets up Variables so your example followed exactly what I said thanks.

I disagree. The FOR/NEXT error has nothing to do with variable scanning and setup.  Two separate issues altogether.



#20 RXB OFFLINE  

RXB

    River Patroller

  • 3,405 posts
  • Location:Vancouver, Washington, USA

Posted Sat Nov 17, 2018 1:51 AM

I disagree. The FOR/NEXT error has nothing to do with variable scanning and setup.  Two separate issues altogether.

 

Really just because it says SYNTAX ERROR in 12 even though there is no SYNTAX ERROR.

 

11 !@P-

12 I,X=0

100 FOR I=1 TO 10 :: IF I=5 then X=X+100 :: PRINT X;"I was 5" :: NEXT I

110 X=X+1 :: PRINT X :: NEXT I

 

So why do you think it says SYNTAX ERROR in LINE 12???

 

Yet if you delete LINE 11 it finds the real SYNTAX ERROR IN 100? (NEXT AT THE END OF A IF THEN)

 

Now take out the :: NEXT I at end of the IF THEN

 

And magically it now works? HUH? What do you think is going on?

100 FOR I=1 TO 10 :: IF I=5 then X=x+100 :: PRINT X;"I was 5" :: NEXT I

110 x=x+1 :: PRINT X :: NEXT I



#21 HOME AUTOMATION OFFLINE  

HOME AUTOMATION

    Chopper Commander

  • 173 posts

Posted Sat Nov 17, 2018 2:11 AM

At least for us there's always more to know!!!

 

Others must keep reinventing what they already have...



#22 InsaneMultitasker OFFLINE  

InsaneMultitasker

    River Patroller

  • 2,298 posts

Posted Sat Nov 17, 2018 6:20 AM

 

Really just because it says SYNTAX ERROR in 12 even though there is no SYNTAX ERROR.

The point is that in Owen's original post,the syntax error was caused by incorrect placement of the NEXT statement. My example program /as written/ was meant only to share how one could fool XB into executing (and ignoring) the error; it does not generate an error in the assignment line nor does it contain a line 12. 



#23 RXB OFFLINE  

RXB

    River Patroller

  • 3,405 posts
  • Location:Vancouver, Washington, USA

Posted Sat Nov 17, 2018 6:33 PM

The point is that in Owen's original post,the syntax error was caused by incorrect placement of the NEXT statement. My example program /as written/ was meant only to share how one could fool XB into executing (and ignoring) the error; it does not generate an error in the assignment line nor does it contain a line 12. 

Very True, and what I said about PRESCAN is also true...which is why you had to bypass it. with !@P-

 

I know the inside of XB code pretty well and it does not do a great job of analyzing exaclty what the problem is so defaults to SYNTAX ERROR

 

Even when that is not the problem.


Edited by RXB, Sat Nov 17, 2018 6:37 PM.





0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users