gforth
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gforth] anonymous inline word definitions


From: John Earnest
Subject: [gforth] anonymous inline word definitions
Date: Tue, 4 Dec 2012 18:30:46 -0500

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

[Prev in Thread] Current Thread [Next in Thread]