41 lines
1.3 KiB
Plaintext
41 lines
1.3 KiB
Plaintext
;sort three variables: x, y, z
|
|
|
|
;Macro handles any of the native types, including integers, floating point, and strings
|
|
;because the variable types are not declared but substituted during each instance of the macro.
|
|
;The sorting is in ascending order, i.e. x < y < z.
|
|
Macro sort3vars(x, y, z)
|
|
If x > y: Swap x, y: EndIf
|
|
If x > z: Swap x, z: EndIf
|
|
If y > z: Swap y, z: EndIf
|
|
EndMacro
|
|
|
|
;Macro to perform the sorting test for each variable type, again by substitution.
|
|
Macro test_sort(x, y, z)
|
|
PrintN("Variables before sorting: " + #CRLF$ + x + #CRLF$ + y + #CRLF$ + z + #CRLF$)
|
|
sort3vars(x, y, z)
|
|
|
|
PrintN("Variables after sorting: " + #CRLF$ + x + #CRLF$ + y + #CRLF$ + z + #CRLF$)
|
|
EndMacro
|
|
|
|
|
|
;Define three sets of variables each with a different type for testing
|
|
Define.s x, y, z ;string
|
|
x = "lions, tigers, and"
|
|
y = "bears, oh my!"
|
|
z = ~"(from the \"Wizard of OZ\")" ;uses an escaped string as one way to include quotation marks
|
|
|
|
Define x1 = 77444, y1 = -12, z1 = 0 ;integer
|
|
|
|
Define.f x2= 5.2, y2 = -1133.9, z2 = 0 ;floating point
|
|
If OpenConsole()
|
|
PrintN("Sort three variables" + #CRLF$)
|
|
test_sort(x, y, z) ;strings
|
|
|
|
test_sort(x1, y1, z1) ;integers
|
|
|
|
test_sort(x2, y2, z2) ;floating point
|
|
|
|
Print(#CRLF$ + "Press ENTER to exit"): Input()
|
|
CloseConsole()
|
|
EndIf
|