Odd word problem: Difference between revisions

Content added Content deleted
(Added Quackery.)
(→‎{{header|Quackery}}: removed test for end of string)
Line 2,261: 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''.
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. To approximate this, the word <code>behead</code> returns successive characters from a string. Comparing the string to an empty string is equivalent to testing for end-of-input-stream.
Also, there is no character-at-a-time input stream mechanism implemented in Quackery. Instead, the code uses the word <code>behead</code> which equivalently returns successive characters from a string, one at a time.


Therefore this solution is in the spirit of the requirements, if not the letter.
Therefore this solution is in the spirit of the requirements, if not the letter.


<lang Quackery>[ upper dup lower != ] is letter ( c --> b )
<lang Quackery>[ upper dup lower != ] is letter ( c --> b )


forward is backwords ( $ --> $ )
forward is backwords ( $ --> $ )


[ [ behead
[ dup $ "" = if done
[ behead dup letter while
dup letter while
emit again ]
emit again ]
dup emit
emit backwords ] is forwords ( $ --> $ )
char . !=
if backwords ] is forwords ( $ --> $ )


[ [ behead
[ dup $ "" = if done
[ behead dup letter while
dup letter while
swap recurse
swap recurse
rot emit ]
rot emit ]
dup emit
emit forwords ] resolves backwords ( $ --> $ )
char . !=
if forwords ] resolves backwords ( $ --> $ )


[ forwords drop cr ] is oddwords ( $ --> )
[ forwords drop cr ] is oddwords ( $ --> )


$ "we,are;not,in,kansas;any,more." oddwords
$ "we,are;not,in,kansas;any,more." oddwords