How to create words in a Forth definition

I am using Gforth and I want to create a word in a definition. On the cmd Gforth line, I can type:

create foo
ok

Or, more specifically, I defined an array function that expects a size on the stack and creates a word with an address in this array:

: array ( n -- ) ( i -- addr)
    create cells allot
        does> cells + ;

So, if I type 10 array foo, I can use foolater.

But if I wrote 10 array fooas part of another definition, he gave me a compilation error. I tried replacing foo with s" foo"one that compiles, but it explodes at runtime, saying:

Trying to use a zero-length string as a name

Is there any way to do this?

+4
source share
1 answer

gforth:

: bar   10 s" foo" ['] array execute-parsing ;

-, . http://pfe.sourceforge.net/words/w-header-015.html

Standard Forth, :

: bar   10 s" array foo" evaluate ;
+3

All Articles