j
: Next unread message k
: Previous unread message j a
: Jump to all threads
j l
: Jump to MailingList overview
I'm trying to implement the -> word for setting variables, but it is not working as I hoped. Everything seems find until I reach the first eval word. At that point the evaluated string should make a new word. For some reason, the eval word says that the word can't be found. Here is the code:
\ compile time: 4 -> cat \ run time: 4 set-cat \ : set-cat cat ! ;
\ sets values for local variables : -> ( x - ) parse-word
\ creates a copy of the variable's name 2dup strdup 2dup strdup 2dup strdup
\ creates the new variable setting word " : set-" 2swap $cat2
2swap " ! ;" $cat2
" " 2swap $cat2
$cat2 eval
\ sets up the new word to be called in place of -> " set-" 2swap $cat2
" postpone " 2swap $cat2 eval ; immediate
\ combines two strings together : $cat2 ( $1 $2 -- $3 ) 2 pick over + dup >r alloc-mem >r 2swap tuck r@ swap move ( $2 $1-len ) r@ + swap move ( ) r> r> ;
Anybody know what I could be doing wrong?
Attachments:
You should get in the habit of putting stack diagram comments on every line of code - it will help you keep track of what you are playing with. By convention, a stack diagram starting with $ indicates a addr,len string pointer, which you should use in this code for clarity.
As best I can tell without stack diagrams, you are generating strings of the form "foo: set-foo foo ! ; foo", and it's probably barfing on "foo:" . I'm not sure what this is supposed to accomplish.
Replace the "eval" with a "type" and you should be able to see what it's generating.