Initial prompt: Provide an ANS Forth word that takes a string and character, and returns index of first position of character or -1 if not found. Generated code: : CHAR-INDEX ( c-addr u char -- n ) >R \ save character on return stack 0 \ initialize index counter BEGIN DUP 2 PICK U< \ check if index < string length WHILE DUP 2 PICK + \ calculate address of current character C@ R@ = \ compare with target character IF NIP NIP \ remove string address and length R> DROP \ clean up return stack EXIT \ return with index THEN 1+ \ increment index REPEAT DROP 2DROP \ clean up stack (index, addr, len) R> DROP \ clean up return stack -1 \ return -1 (not found) ; This doesn't work in gforth. I pasted in the error messages and it gave me a new word which works: : CHAR-INDEX ( c-addr u char -- n ) >R \ save target character 0 \ start index at 0 BEGIN DUP 2 PICK U< \ index < length? WHILE DUP 3 PICK + C@ \ get char at string[index] R@ = \ equal to target? IF NIP NIP \ remove addr and len R> DROP \ clean return stack EXIT \ return index THEN 1+ \ increment index REPEAT 2DROP \ drop addr and len DROP \ drop index R> DROP \ clean return stack -1 \ not found ; Tests: S" Hello World" CHAR H CHAR-INDEX . \ prints 0 S" Hello World" CHAR W CHAR-INDEX . \ prints 6 S" Hello World" CHAR Z CHAR-INDEX . \ prints -1