gforth
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem with creating word


From: Anton Ertl
Subject: Re: problem with creating word
Date: Fri, 10 Apr 2020 09:12:06 +0200
User-agent: NeoMutt/20170113 (1.7.2)

On Fri, Apr 10, 2020 at 08:40:24AM +0200, Robert Sander wrote:
> Hello,
> 
> I want to create a word and store a generated id and a string in the
> datafield.
> 
> I have the following words:
> 
> variable ma#
> 68 ma# ! \ just to find the value in the memoy
> 
> : ma: ( -- )
>         1 ma# +! \ increment ma# - is there a better way?
>         create ma# @ , \ reserve space and store the value of ma#
>         parse-name 2, \ get next word and store addr and length
>         does> ( -- u) @ ;
> 
> 
> With the following definition:
> 
> ma: robert rs
...
> Now I want to see the string "rs":
> 
> ' robert >body 1 cells + 2@ type  c ok
> 
> but this does not work.
> 
> What am I doing wrong?

PARSE-NAME just points into the input buffer.  The result is only
valid until the text interpreter switches to the next line.  You can
make the name permanent (until the end of the session) with SAVE-MEM (
c-addr1 u -- c-addr2 u ), i.e.:

: ma: ( -- )
        1 ma# +! \ increment ma# - is there a better way?
        create ma# @ , \ reserve space and store the value of ma#
        parse-name save-mem 2, \ get next word and store addr and length
        does> ( -- u) @ ;

- anton



reply via email to

[Prev in Thread] Current Thread [Next in Thread]