Sort three variables: Difference between revisions
m
→{{header|Forth}}: correct 'lang' tag solves strike-through text issue
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
SqrtNegInf (talk | contribs) m (→{{header|Forth}}: correct 'lang' tag solves strike-through text issue) |
||
Line 1,137:
typically be used directly from the stack by a subsequent operation in the
program.
<
VARIABLE X VARIABLE Y VARIABLE Z
Line 1,146:
2DUP < IF SWAP THEN ;
: SORT3INTS ( a b c -- c b a) ?SWAP >R ?SWAP R> ?SWAP ;</
Testing is done using the Forth console using '?' to view VARIABLE contents
Line 1,161:
==={{header|Strings}}===
Strings require extending the language but the primitives needed are part of ANS/ISO Forth.
<
: BUFFER: ( n -- ) CREATE ALLOT ;
Line 1,186:
\ non-destructive print 3 counted-strings from data stack
: .STRS ( caddr1 caddr2 caddr3 -- caddr1 caddr2 caddr3) \ order is dependant
3 0 DO ROT DUP CR COUNT TYPE LOOP ; </
With these extensions we can do the same testing at the Forth console and
examine the string order with '.STRS'.
|