BBC BASIC for Windows
« Just Thought I'd Mention... »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:53pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Just Thought I'd Mention...  (Read 745 times)
Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Just Thought I'd Mention...
« Thread started on: Sep 20th, 2010, 05:39am »

Reviewing another program someone had written, I found a little trick that I didn't know existed. It's a bonus with the +=, -=, etc. The use of it I have known since starting work with BB4W. But what I've just discovered is quite useful.

Original BBC Basic:
Code:
(1.) VARIABLE% = VARIABLE% + CONSTANT 
(There was no other way)

BB4W:
Code:
(1.) VARIABLE% = VARIABLE% + CONSTANT
(2.) VARIABLE% += CONSTANT 

Now, if VARIABLE% didn't exist in the first place command (1.) would error. However, command (2.) does not. This is useful when closing a window, for instance.

Code:
VARIABLE% += 0: IF VARIABLE% THEN [close window] 

Just thought I'd mention it. Well done Richard.

I know there must be thousands of other useful bonuses in the change from BBC Basic to BB4W, but I also wondered whether anyone else knew of anything little like this. Or is this just opening a whole box of bicuits?

Matt
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Just Thought I'd Mention...
« Reply #1 on: Sep 20th, 2010, 08:21am »

on Sep 20th, 2010, 05:39am, Matt wrote:
Code:
VARIABLE% += 0: IF VARIABLE% THEN [close window] 

Just thought I'd mention it.

Yes, many of my programs use that technique in their PROCcleanup routines. For example this in cpuspeed.bbc:

Code:
      DEF PROCcleanup
      pCPU% += 0  : IF pCPU%  SYS !(!pCPU%+8), pCPU%   : pCPU% = 0
      pEnum% += 0 : IF pEnum% SYS !(!pEnum%+8), pEnum% : pEnum% = 0
      pSvc% += 0  : IF pSvc%  SYS !(!pSvc%+8), pSvc%   : pSvc% = 0
      pLoc% += 0  : IF pLoc%  SYS !(!pLoc%+8), pLoc%   : pLoc% = 0
      SYS `CoUninitialize`
      ENDPROC 

It's specifically documented in the Wiki here:

http://bb4w.wikispaces.com/Forcing+a+variable+to+exist

Richard.
User IP Logged

knudvaneeden
Developer

member is offline

Avatar




Homepage PM


Posts: 32
xx Re: Just Thought I'd Mention...
« Reply #2 on: Sep 20th, 2010, 12:41pm »

on Sep 20th, 2010, 05:39am, Matt wrote:
Reviewing another program someone had written, I found a little trick that I didn't know existed. It's a bonus with the +=, -=, etc. The use of it I have known since starting work with BB4W. But what I've just discovered is quite useful.


This shorthand notation +=, *=, ... exists since 1969.
Ken Thompson and Dennis Ritchie of Bell Labs introduced it in their C language.
Nowadays used in several other computer languages, like C++, and also BBCBasic for Windows.
User IP Logged

knudvaneeden
Developer

member is offline

Avatar




Homepage PM


Posts: 32
xx Re: Just Thought I'd Mention...
« Reply #3 on: Sep 20th, 2010, 1:15pm »

Because C was a successor of e.g. the earlier B language, I checked if it maybe existed earlier than 1969, and found:

"Compound assignment operators, such as a += b to “add b to a” were popularized by the C and Pascal, but first available in ALGOL 68"
http://hhh.gavilan.edu/dvantassel/history/assignment.html#_Toc123623884

So it must have been used since about 1968.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Just Thought I'd Mention...
« Reply #4 on: Sep 20th, 2010, 4:28pm »

on Sep 20th, 2010, 12:41pm, knudvaneeden wrote:
This shorthand notation +=, *=, ... exists since 1969.

I don't think the OP was commenting on the existence or function of the += operator, but the fact that it can be used to create a variable. Just because other languages have the same operator it doesn't follow that it will have that behaviour.

Incidentally, BBC BASIC didn't have the += operator (and friends) until version 5, in around 1986.

Richard.
« Last Edit: Sep 20th, 2010, 4:37pm by admin » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls