Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can replace it, there are two (nearly 3) forths that replace it:

https://github.com/dan4thewin/FreeForth2/blob/master/ff.asm

which uses a double loop to lookup first macro words, and then immediate words

https://github.com/ablevm/able-forth/blob/current/forth.scr

Ableforth implements a defer/expand operation \ to effectively quote words. The basic loop is then simply parse a text word, look it up and execute it.

Both make use of macros (code generators) to implement deferred behaviour, as well as code inlining. Ultimately all these operations implement defer by manipulating the execution flow, something that algebraic effects also do.

I have a feeling that algebraic effects can be used in a Forth to implement DOES.



Also Chuck Moore's ColorForth doesn't have "create does>" at all. Probably he considered the complexity was not worth it. I don't have it in my interpreter either, and I don't miss it; for the few near-misses I just use regular literals and calls. For instance, for the textbook example of "self-indexing arrays":

    : index-array swap cells + ;
    create a1 10 cells allot
    create a2 20 cells allot
    : array1 a1 index-array ;
    : array2 a2 index-array ;
I used to use the "implementation-dependent" trick of popping the return address (in e.g. index-array) to get the data. Less verbose, a bit more efficient. But my implementation doesn't permit it anymore.

Recently I've found out that implementing "self/this" pseudo-value and pseudo-method calls much more useful. The relation with this and "create does>" is that latter can be seen as poor man's closure, or poor man's object [1].

[1] https://stackoverflow.com/questions/2497801/closures-are-poo...


Two forths is one half.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: