Search code examples
forthgforth

How do I access the program name / argv[0] in Forth?


The Gforth documentation say to access arguments by calling next-arg, but this omits the program name, which would be printed in a C-like language.

Since argv[0] seems to be automatically removed from the argument vector in Forth, is there a special function I can call that does return it?


Solution

  • sourcefilename gives the program's name, and n arg gets the arguments that were sent to gforth, including the gforth binary name.