Whoops, sorry Bernd- I meant to reply to the list. ---------- Forwarded message ---------- From: John Earnest <[email protected]> Date: Tue, Dec 4, 2012 at 9:11 PM Subject: Re: [gforth] anonymous inline word definitions To: Bernd Paysan <[email protected]>
Thanks guys- that's a big help. I should've known someone had already implemented a feature like this, but at least it was a good exercise for familiarizing myself with some of the differences between GForth and other Forth dialects I've worked with. I'll study quotations.fs. In a semi-related note, has anyone tried building callable words in dynamically allocated (non-dictionary space) memory? For context, I've implemented a system in my own Forth dialect which allows "currying" onto quotations, which makes it possible to provide partial application and closure-like functionality. The way I do this is to create dynamically allocated "thunks" which wrap around XTs and either chain them together or push a constant value onto the stack before calling the XT. By making the thunks dynamically allocated I can free them in any order, and automatically deallocate them via reference counting or a garbage collector. If the thunks have to reside in dictionary space I'm limited to some sort of mark...forget system where I deallocate them all at once. Doing all this was fairly simple in my Forth because I could make a lot of assumptions about the underlying representation of words, but naturally these don't apply in GForth. Any thoughts about how one would go about doing that portably? With a little sugar and a fairly significant amount of plumbing it would be possible to provide lexical capture of local variables surrounding quotations via such a mechanism. -John On Tue, Dec 4, 2012 at 7:16 PM, Bernd Paysan <[email protected]> wrote: > Am Dienstag, 4. Dezember 2012, 18:30:46 schrieb John Earnest: > > 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. > > Just look at the file quotations.fs in the development version, it's > already > implemented ;-). There has been some discussion about the name, and as { } > are already used for locals, we ended up with [: and ;] to start and end > quotations. > > http://git.bernd-paysan.de/?p=gforth.git;a=blob;f=quotations.fs > > It's slightly more work, as we want to have a separate locals scope inside > the > quotation - we can't access the outer locals, as we don't know when the > quotation is executed. > > -- > Bernd Paysan > "If you want it done right, you have to do it yourself" > http://bernd-paysan.de/ >
