Jump to content

Odd word problem: Difference between revisions

→‎{{header|Quackery}}: removed test for end of string
(Added Quackery.)
(→‎{{header|Quackery}}: removed test for end of string)
Line 2,261:
It is not possible to comply with the requirements of this task ''to the letter'' as the task presumes the existence of an ''implicit'' stack, e.g. a stack frame storing state information during subroutine calls, including recursive calls. In Quackery such information is stored on a second stack (usually referred to as ''the stack'') which is ''explicit''.
 
Also, there is no character-at-a-time input stream mechanism implemented in Quackery. ToInstead, approximatethe this,code uses the word <code>behead</code> which equivalently returns successive characters from a string., Comparingone theat string to an empty string is equivalent to testing fora end-of-input-streamtime.
 
Therefore this solution is in the spirit of the requirements, if not the letter.
 
<lang Quackery>[ upper dup lower != ] is letter ( c --> b )
 
forward is backwords ( $ --> $ )
 
[ [ behead
[ dup $ "" = if done
[ behead dup letter while
emit again ]
dup emit
emit backwords ] is forwords ( $ --> $ )
char . !=
emitif backwords ] is forwords ( $ --> $ )
 
[ [ behead
[ dup $ "" = if done
[ behead dup letter while
swap recurse
rot emit ]
dup emit
emit forwords ] resolves backwords ( $ --> $ )
char . !=
emitif forwords ] resolves backwords ( $ --> $ )
 
[ forwords drop cr ] is oddwords ( $ --> )
 
$ "we,are;not,in,kansas;any,more." oddwords
1,462

edits

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