BBC BASIC for Windows
Programming >> BBC BASIC language >> Obvious bug or I'm idiot
http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1337752606

Obvious bug or I'm idiot
Post by Endymion on May 23rd, 2012, 05:56am

Code:
      print fn_Func1(0)
      end
      
      def fn_Func1(Number%)
      print "Init"
      local Answer% = Number%
      print "Calc"
      = Answer% 


Why I don't see "Calc"?
Re: Obvious bug or I'm idiot
Post by admin on May 23rd, 2012, 08:29am

on May 23rd, 2012, 05:56am, Endymion wrote:
Code:
      print fn_Func1(0)
      end
      
      def fn_Func1(Number%)
      print "Init"
      local Answer% = Number%
      print "Calc"
      = Answer% 


Why I don't see "Calc"?

Because you're trying to initialise a variable in the LOCAL statement. I agree that it would be nice if you could, but BBC BASIC has never had that facility: you have to separate it into two statements as follows:

Code:
      PRINT FN_Func1(0)
      END
      
      DEF FN_Func1(Number%)
      PRINT "Init"
      LOCAL Answer%
      Answer% = Number%
      PRINT "Calc"
      = Answer% 

Now you know why it didn't work, it would be a useful exercise for you to work out why it didn't produce an error message (hint: a statement starting with an equals sign = is valid, and BBC BASIC doesn't always need a colon separating statements)!

Richard.
Re: Obvious bug or I'm idiot
Post by Endymion on May 23rd, 2012, 10:43am

In other words, BBC BASIC understand my code like this:

Code:
      print fn_Func1(0)
      end
      
      def fn_Func1(Number%)
      print "Init"
      local Answer%
      = Number%
 


Very funny. There is even a peculiar charm in such unexpected unobviousnesses, which has an own logic.