Howdy folks,

Factor, PostScript and a few other stack-oriented languages have literal
syntax for blocks of code- Factor calls these "quotations". I've been
puzzling over how I might go about building a similar facility in GForth.
I'd like to define { and } to delimit an inline word and leave an XT on the
stack. So, for example, if I executed a word like:

    : test   54 { 27 . } execute . ;

It would simply print "27 54". Here's my first try at { and } :

    : {   postpone ahead noname create latestxt ; immediate
    : }   postpone exit >r postpone then r> postpone literal ; immediate

{ lays down an unresolved forward branch, defines an anonymous word to be
the body of the quotation and then stashes its XT on the stack.
} terminates the body with an EXIT, resolves the forward branch and lays
down a literal containing the XT we stashed earlier.

Could someone explain why this approach doesn't work? Did I miss a simple
detail or is my thinking totally crazy?

Thanks,

-John Earnest

Reply via email to