How to make a swap function ??

Post Reply
Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

How to make a swap function ??

Post 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

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: How to make a swap function ??

Post 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.

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: How to make a swap function ??

Post by Mr. Kibernetik »

Henko is right, currently there are no means to perform this task as a function.

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Re: How to make a swap function ??

Post by Operator »

Thanks for the explanation. Now clear.

Post Reply