RosettaCodeData/Task/Sort-three-variables/M2000-Interpreter/sort-three-variables.m2000

32 lines
1.0 KiB
Plaintext

Module Sort3 {
Let X=77744, Y=-12, Z=0
Let X$ = "lions, tigers, and", Y$ = "bears, oh my!", Z$ = {(from the "Wizard of OZ")}
\\ & use for by reference pass
Module SortSome (&X$, &Y$, &Z$){
If Type$(X$)<>"String" Then {
Link X$,Y$, Z$ to X,Y,Z
Print3()
If Y>Z then Swap Y, Z ' both numeric in Swap
If X>Z then Swap X, Z
If X>Y then Swap X, Y
Print3()
} Else {
Print3Str()
If Y$>Z$ then Swap Y$, Z$ ' both strings in Swap
If X$>Z$ then Swap X$, Z$
If X$>Y$ then Swap X$, Y$
Print3Str()
}
}
SortSome &X, &Y, &Z
SortSome &X$, &Y$, &Z$
Sub Print3()
\\ double ,, used to insert a New Line
Print "X=",X,,"Y=",Y,,"Z=",Z
End Sub
Sub Print3Str()
Print "X$=",X$,,"Y$=",Y$,,"Z$=",Z$
End Sub
}
Sort3