Jump to content

Sort three variables: Difference between revisions

m
→‎{{header|Forth}}: correct 'lang' tag solves strike-through text issue
m (syntax highlighting fixup automation)
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.
<LANGsyntaxhighlight lang="forth" lines>\ sort 3 integers
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 ;</LANGsyntaxhighlight>
 
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.
<LANGsyntaxhighlight lang="forth" lines>DECIMAL
: 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 ; </LANGsyntaxhighlight>
With these extensions we can do the same testing at the Forth console and
examine the string order with '.STRS'.
2,392

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.