PDA

View Full Version : why this limitation ? SWAP function



DirectuX
20-12-2018, 19:30
Hi,

I come across this issue:


'---Script created on 12-20-2018 16:59:40 by

' help page : https://www.thinbasic.com/public/products/thinBasic/help/html/index.html?swap.htm


uses "console"

Type POINTAPI
x As Long
y As Long
End Type

type desk
dstart as POINTAPI
dstop as POINTAPI
end type

dim lab(10) as desk
dim uu as Long Value = 555
dim vv as Long Value = 111

lab(1).dstart.x=555
lab(2).dstart.x=111

'Simple swap of two variables, ok
printl "swap simple variables using swap"
printl uu,vv
printl "swapping"

swap uu,vv

PrintL uu,vv
printl "Press a key to next"
printl ""
WaitKey

'This was not working back in 2013 according to https://www.thinbasic.com/community/project.php?issueid=420#note2514
'But now it is ok
printl "swap UDT array element using swap"
printl lab(1).dstart.x , lab(2).dstart.X
printl "swapping"

swap lab(1),lab(2)

printl lab(1).dstart.x , lab(2).dstart.X
printl "Press a key to next"
printl ""
WaitKey

'This works thanks https://www.thinbasic.com/community/project.php?issueid=420#note2514
printl "swap udt variables using Memory_Swap"
printl lab(1).dstart.x , lab(2).dstart.X
printl "swapping"

Memory_Swap(VarPtr(lab(1).dstart.x), VarPtr(lab(2).dstart.x), SizeOf(Long))

printl lab(1).dstart.x , lab(2).dstart.X
printl "Press a key to next"
printl ""
WaitKey

'So why not this ? swap lab(1).dstart.x , lab(2).dstart.X
printl "swap udt variables using swap"
printl lab(1).dstart.x , lab(2).dstart.X
printl "swapping : here raise an error: Expected comma ',' but found something else."
printl "Press a key to error"
waitkey

swap(lab(1).dstart.x, lab(2).dstart.x)

printl lab(1).dstart.x , lab(2).dstart.X
printl "Press a key to next"

WaitKey



so, as seen, it is possible with memory_swap, then why swap comes with this limitation ?




:yes: https://www.thinbasic.com/community/showthread.php?12164-Idea-for-ordered-SWAP&p=89255&viewfull=1#post89255 this simple (1st post) order / rorder is a pleasant idea.