Swap Function?

Carl Sassenrath, CTO
REBOL Technologies
26-May-2006 5:06 GMT

Article #0030
Main page || Index || Prior Article [0029] || Next Article [0031] || 13 Comments || Send feedback

Recently, I noticed that Cyphre implemented a swap function for series of graphics objects. The purpose was to quickly swap two values within a series (or between two series).

The idea of adding swap as a native function to REBOL has been suggested before (many years). Here is an example of what it would do:


v1: at series1 10
v2: at series2 20

would you prefer to do:

tmp: first v1
change/only v1 first v2
change/only v2 tmp


swap v1 v2

The function would also work within the same series.

A /part refinement could allow swapping of multiple values.

Question: should such a function be provided (at the native level it could be highly optimized compared to the above change code)? Is it really that useful for string series (seems like it would rarely get used) or just blocks?


Updated 24-Jun-2024 - Edit - Copyright REBOL Technologies -