Author |
Topic: SWAP (Read 695 times) |
|
mohsen
New Member
member is offline


Gender: 
Posts: 39
|
 |
SWAP
« Thread started on: Nov 20th, 2008, 9:49pm » |
|
I was surprised to find out that:
Code:
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%
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
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.
|
|
Logged
|
|
|
|
mohsen
New Member
member is offline


Gender: 
Posts: 39
|
 |
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:
|
|
Logged
|
|
|
|
mohsen
New Member
member is offline


Gender: 
Posts: 39
|
 |
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.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
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.
|
|
Logged
|
|
|
|
mohsen
New Member
member is offline


Gender: 
Posts: 39
|
 |
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.
|
|
Logged
|
|
|
|
|