Cameron Esfahani wrote:
> 
> I think I've figured out my problem.  The documentation for 'cold is, 
> at least to me, misleading.

I have now added "of an image" in the docs, resulting in the sentence

|You can add your own initialization to the startup sequence of an image
|through the deferred word @code{'cold}.

> So this begs the question, how do people write forth programs that are 
> run with gforth, using the standard gforth.fi image file, and yet 
> handle command line arguments?

Just execute a word in your file that accesses the arguments, then
leave gforth (otherwise Gforth's command-line processing will try to
interpret the arguments).  E.g.:

-----------------
\ call this with "gforth xxx.fs arg1 arg2"

: echo
    argc @ 2 +do
        i arg type
    loop ;

echo bye
------------------

When I do

gforth xxx.fs foo bar boing

this outputs

foobarboing

A disadvantage of this method is that you don't know reliably where
the arguments that interest you are starting.  (If people are really
interested in this kind of stuff, we might add a method to do this).

However, what I usually do for scripting is passing arguments through
-e, either on the stack or through parsing the Gforth command line.

Here's an example of passing arguments on the stack:

---- yyy.fs ---------
: .base36 ( n -- )
    base @ >r
    36 base !
    u.
    r> base ! ;

.base36 bye
---------------------

gforth -e 123456789 yyy.fs

prints

21I3V9

Here's an example of using the Gforth command line:

---- zzz.fs ------
: echo-word ( -- )
    parse-word type ; \ use NAME instead of PARSE-WORD on older gforths
------------------

gforth zzz.fs -e "echo-word bla bye"

prints

bla

- anton


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to