BBC BASIC for Windows
« SWAP »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:59pm



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: SWAP  (Read 696 times)
mohsen
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 39
xx SWAP
« Thread started on: Nov 20th, 2008, 9:49pm »

I was surprised to find out that:

Code:
A%=1 : A=2
SWAP A% , A 


will fail with a "Type mismatch" error.

Also the following will not be accepted:

Code:
DIM A% 255
$A%="one"
B$="two"
SWAP B$ , $A% 



In the last example, one need to change it to:
Code:
DIM A% 255
$A%="one"
B$="two"
C$=$A%
SWAP B$ , C$ 


This restriction is not clear in the Manual.

I didn't check the RECTANGLE SWAP.

By the way, BASIC V accepts the above examples. However, in case a string variable is stored in a DIMed memory which is not large enough to accepted the new swapped string (as in the 2nd example above), the interpreter will crash with a Data Abort ;) somthing like:

Code:
DIM A% 3
$A%="one"
B$="two and three"
SWAP B$, $A% 


User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: SWAP
« Reply #1 on: Nov 20th, 2008, 10:16pm »

Quote:
By the way, BASIC V accepts the above examples.

Really? If BASIC 5 allows you to swap an integer variable and a real variable, what happens if the real variable doesn't contain an integer value? Does it truncate?

I'd be very unhappy for SWAP to alter one of the values. In BBC BASIC for Windows SWAP can only exchange two variables of the same type.

This is certainly a case where I think BB4W gets it right, and BASIC 5 gets it wrong!

Richard.
User IP Logged

mohsen
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 39
xx Re: SWAP
« Reply #2 on: Nov 20th, 2008, 10:47pm »

Yes, it does truncate when swapping a real with an integer.

Example:

Code:
A%=1
B=1.5
PRINT A% , B
SWAP A% , B
PRINT A% , B 

will give the output:

Code:
       1       1.5
       1         1 
User IP Logged

mohsen
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 39
xx Re: SWAP
« Reply #3 on: Nov 20th, 2008, 10:57pm »

Note that the BB4W Manual currently only states that in the case of SWAPping two arrays, they need to be of the same type. It does not state that this restriction also applies to numeric variables, string variables, and structures. The first paragraph on page 416 would need an update/correction.

User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: SWAP
« Reply #4 on: Nov 21st, 2008, 09:01am »

Quote:
Yes, it does truncate when swapping a real with an integer.

Awful! I suggest you complain to Sophie Wilson!

Acorn BASICs often behave inconsistently (I would say wrongly) when mixing integer and real variables. Try this on an Acorn version and compare it with BB4W:

Code:
      A% = 2^30
      A = A% + A%
      B = A% * 2
      PRINT A
      PRINT B 
Richard.
User IP Logged

mohsen
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 39
xx Re: SWAP
« Reply #5 on: Nov 21st, 2008, 4:56pm »

BASIC V (Acorn) can't handle such large numbers correctly. I assume the old original BASIC 4 had the same restrictions.

In that respect BB4W is far superior.

The question about the SWAP carries from the logic that integer and real assignments can be intermixed in BB4W and one can do A%=A or A=A%. So it was expected that SWAP would allow that, which it does not.

Any way, it is clear that this is intended correct operation of the SWAP keword although the Manual does not state that.

Programs originally written for BASIC V should be aware of this.
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