define "variable" word 
Author Message
 define "variable" word

Hi:

I'm a beginner in FORTH, But have some not understand.
Some people define bulti-in word 'variable' can re-defintion following :
/* define */
: variable ( -- ) create 1 cells allot ;
/* apply it */
variable NewVariable

The effect is as same as bulti-in word 'variable', and not no error message.
**************************************************************************
My first question is :
Why the 'create' not match the bulti-in system defintion, but it still work:

defintion of word 'create' : CREATE <NAME>
/* Why!? it can work */
: variable ( -- ) create 1 cells allot ;
                  ^^^^^^^^^^^^^
**************************************************************************I
My second question is :
I assume the system accepted, and then I expand the code in following:

create 1 cells allot NewVariable

BUT, I get an error message! Why???
**************************************************************************I

Thank you
Willow



Fri, 09 Sep 2005 00:49:05 GMT  
 define "variable" word

Quote:

> Some people define bulti-in word 'variable' can re-defintion following :
> /* define */
> : variable ( -- ) create 1 cells allot ;
> /* apply it */
> variable NewVariable
> The effect is as same as bulti-in word 'variable', and not no error message.

Yes.  What you get that way might not be as efficient as the built-in
VARIABLE but it will get the same final state.

Quote:
> My first question is :
> Why the 'create' not match the bulti-in system defintion, but it still work:
> defintion of word 'create' : CREATE <NAME>
> /* Why!? it can work */
> : variable ( -- ) create 1 cells allot ;

I'm not sure I understand your question.  Here's what I think you're
saying -- CREATE uses up the next word after it for the name of the
thing that gets created.  When it gets used inside VARIABLE it doesn't
use up the 1 that follows it, and you don't understand why.  Is that it?

Quote:
> My second question is :
> I assume the system accepted, and then I expand the code in following:
> create 1 cells allot NewVariable
> BUT, I get an error message! Why???

CREATE takes the very next word for the name of the thing it creates.
When you do it this way it will make something named "1" and then it
won't know what NewVariable is.

But when you compile CREATE into another definition then CREATE doesn't
look for the new word then.  It looks for it later, when the new word
executes.



Fri, 09 Sep 2005 05:08:06 GMT  
 define "variable" word

Quote:

> Hi:

> I'm a beginner in FORTH, But have some not understand.
> Some people define bulti-in word 'variable' can re-defintion following :
> /* define */
> : variable ( -- ) create 1 cells allot ;
> /* apply it */
> variable NewVariable

> The effect is as same as bulti-in word 'variable', and not no error message.
> **************************************************************************
> My first question is :
> Why the 'create' not match the bulti-in system defintion, but it still work:

> defintion of word 'create' : CREATE <NAME>
> /* Why!? it can work */
> : variable ( -- ) create 1 cells allot ;
>                   ^^^^^^^^^^^^^

\ initializing to 0, empty does-part
: VARIABLE CREATE 0 , DOES> ;
: VARIABLE CREATE 0 , ;

\ not initializing, empty does-part
: VARIABLE CREATE 1 CELLS ALLOT DOES> ;
: VARIABLE CREATE 1 CELLS ALLOT ;

\ variable always returns the same adress in memory
\ initializing to 0
: VARIABLE HERE 0 , CONSTANT ;
\ not initializing
: VARIABLE HERE 1 CELLS ALLOT CONSTANT ;

Quote:
> **************************************************************************I
> My second question is :
> I assume the system accepted, and then I expand the code in following:

> create 1 cells allot NewVariable

create NewVariable 1 cells allot

Quote:

> BUT, I get an error message! Why???

because CREATE takes "1" as the new word's name
And NewVariable is still undefined.
Try
1 .
after your code and you will see that 1 is not one but
an address.


Fri, 09 Sep 2005 13:21:56 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Variable "Variables"

2. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

3. Redesigning "define interface"

4. defining "|" as or in Poplog Prolog

5. Lets define "pointer"

6. Lets define "pointer"

7. Naming of "defined?"

8. defining "preferences" in cosmo with code

9. use defined PROTO in "Browser.createVrmlFromString"?

10. +define+unknown="'bx" chokes verilog

11. Defining "public" functions

12. "#define" and C2Ada

 

 
Powered by phpBB® Forum Software