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
How to make a swap function ??
-
- Posts: 814
- Joined: Tue Apr 09, 2013 12:23 pm
- My devices: iPhone,iPad
Windows - Location: Groningen, Netherlands
- Flag:
Re: How to make a swap function ??
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.
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: How to make a swap function ??
Henko is right, currently there are no means to perform this task as a function.
Re: How to make a swap function ??
Thanks for the explanation. Now clear.