Groups | Search | Server Info | Login | Register
Groups > comp.lang.forth.mac > #50
| Newsgroups | comp.lang.forth.mac |
|---|---|
| Date | 2018-04-03 08:09 -0700 |
| Message-ID | <bb80d9a4-19e8-4cc5-8e58-a55afc54c335@googlegroups.com> (permalink) |
| Subject | Forth and macros/code generation |
| From | danilomendoncaoliveira@gmail.com |
I want some colon definition, let's say : mydef to take some string parameter from stack, let's say "something" (addr size) and automatically generate a set of related words something-a, something-b, etc. That's the way, for instance, the DEFSTRUCT macro works in Lisp. Calling this: (defstruct book title author subject book-id ) creates the book-title, book-author, ... functions. My only idea for doing this in Forth is by generating the functions as a string then calling EVALUATE. My questions: * Is it an acceptable way of doing this? * Can I do this using Forth's interpretation/compilation semantics and related words? * In general, is generating Forth code as string and evaluating it a bad programming practice (when postpone/immediate aren't of much help or leads to a difficult solution) ? (I could't even nest a :noname inside a colon definition. The most recent version of GForth (0.79) offers the [: ;] words to enable creating unnamed definitions inside a definition.) (I posted the same question in reddit/facebook groups, sorry if someone here already saw the same topic on those websites)
Back to comp.lang.forth.mac | Previous | Next | Find similar
Forth and macros/code generation danilomendoncaoliveira@gmail.com - 2018-04-03 08:09 -0700
csiph-web