RosettaCodeData/Task/Generic-swap/Slate/generic-swap-1.slate
2023-07-01 13:44:08 -04:00

10 lines
410 B
Text

x@(Syntax LoadVariable traits) swapWith: y@(Syntax LoadVariable traits) &environment: env
"A macro that expands into simple code swapping the values of two variables
in the current scope."
[
env ifNil: [error: 'Cannot swap variables outside of a method'].
tmpVar ::= env addVariable.
{tmpVar store: x variable load.
x variable store: y variable load.
y variable store: tmpVar load} parenthesize
].