Generic swap: Difference between revisions

J: more concise (and more J-like) approach for swapping values of names
(J: more concise (and more J-like) approach for swapping values of names)
Line 1,597:
A generic destructive swap of named values would instead require reference to the locations being destroyed. Here's an implementation of that:
 
<lang J>destructiveSwap=:4 {{ EMPTY[ (m;n)=:0 n ,&<&do m }}</lang>
t=. do y
(y)=: do x
(x)=: t
i.0 0 NB. result is meaningless
)</lang>
 
Example use:
6,951

edits