Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a words string representation on the data stack in Forth (gforth)?

Tags:

forth

gforth

In gforth I can see a word's definition with see wordname and even get its execution token with ' wordname and also some information with the see subwords such as ' wordname seecol

I have not been able to find a way to get the output of see wordname into a string. I have tried fiddling with stdout and stdin words but cant find the right words.

Can anyone help me please?

like image 810
Bots Fab Avatar asked Sep 05 '25 03:09

Bots Fab


1 Answers

Gforth provides a word >string-execute ( i*x xt – j*x c-addr u ) that redirects the output of type and emit to a string.

Interactive usage examples

"see wordname" ' evaluate >string-execute type

' see >string-execute wordname type

"wordname" ' see ' execute-parsing >string-execute type

' wordname ' xt-see >string-execute type

Helper words

: dis-xt ( xt -- sd.disforth )
  ['] xt-see >string-execute 
;
: dis-word ( sd.name -- sd.disforth )
  ['] see ['] execute-parsing >string-execute
;

The datatype symbol sd means a character string represented by a cell pair ( c-addr u ).

Helper words usage examples

' traverse-wordlist dis-xt type
"traverse-wordlist" dis-word type
like image 133
ruvim Avatar answered Sep 08 '25 01:09

ruvim