Page 1 of 1

How to make a swap function ??

Posted: Fri Oct 07, 2016 6:19 am
by Operator
I tried to make a swap function, but
it only works if the variables to swap
stay the same...
Is there a way to make a "general" swap
function (without prior knowing which
variables to swap)?

x = 1
y = 2
swap(x,y)
DEF swap(a,b)
temp = a
.x = b
.y = temp
END DEF

Re: How to make a swap function ??

Posted: Sat Oct 08, 2016 8:17 am
by Henko
I fear it's not possible because single numeric variables are passed "by value" to functions. With "pointers", like in C, it would be no problem, but i guess mr. K. doesn't like to introduce an explicit pointer feature in SB, too tricky.

Re: How to make a swap function ??

Posted: Sat Oct 08, 2016 8:30 am
by Mr. Kibernetik
Henko is right, currently there are no means to perform this task as a function.

Re: How to make a swap function ??

Posted: Sat Oct 08, 2016 7:39 pm
by Operator
Thanks for the explanation. Now clear.