Forth and macros/code generation
From
danilomendoncaoliveira@gmail.com@21:1/5 to
All on Tue Apr 3 08:09:06 2018
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)
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)