Ordered words: Difference between revisions

Content deleted Content added
Hansoft (talk | contribs)
Added Forth
Hansoft (talk | contribs)
m Fixed "Oops" in Forth
Line 768: Line 768:
begin s> dup r@ >= while type cr repeat
begin s> dup r@ >= while type cr repeat
2drop r> drop \ keep printing until shorter word
2drop r> drop \ keep printing until shorter word
; \ has been found</lang>
; \ has been found

: ordered ( --)
open-file s.clear read-file read-back close
; \ open file, clear the stack, read file
\ read it back and close the file
ordered</lang>
Since the longest word is on top of the stack, the only thing to be done is to pop
Since the longest word is on top of the stack, the only thing to be done is to pop
all words from the stack until a shorter word is encountered. Consequently, all
all words from the stack until a shorter word is encountered. Consequently, all