News for hackers. Stuff that matters.
Re:Implementing DOES> in Forth, the entire reason I started ... by pyinstallwoes on Tuesday June 10, 2025 @01:32AM (#44232902)
Okay, so what's the significance of it and what's the boon?

Surprised so little public forth's implement it.

Re:Implementing DOES> in Forth, the entire reason I started ... by sph on Tuesday June 10, 2025 @02:46AM (#44233439)
All the most common Forth I know implement CREATE DOES>

What’s funny, is that I used to know how it works, now any time I come across these kind of articles I get more and more confused and further away from understanding. It’s like reading those convoluted explanations of what a monad is.

Re:Implementing DOES> in Forth, the entire reason I started ... by spc476 on Tuesday June 10, 2025 @02:55AM (#44233510)
It only briefly goes into what it does, this article goes into how it's done for a particular implementation.
Re:Implementing DOES> in Forth, the entire reason I started ... by alexisread on Tuesday June 10, 2025 @04:21AM (#44234058)
It implements defining words ie. Additional compiler words.

It does this by doing something now, and later (you could read create does> as now later>)

So for

: CONSTANT CREATE , >DOES @ ;

This makes the defining word CONSTANT, which when run (now) compiles the next word

So CONSTANT myvar will compile myvar. Myvar, when run (later) will get it's value and push it to the datastack.

Re:Implementing DOES> in Forth, the entire reason I started ... by anthk on Tuesday June 10, 2025 @04:06AM (#44233967)
Even EForth under Sublex/Muxleq implements it.
Re:Implementing DOES> in Forth, the entire reason I started ... by throwaway77699 on Tuesday June 10, 2025 @04:52AM (#44234255)
Re:Implementing DOES> in Forth, the entire reason I started ... by oneearedrabbit on Tuesday June 10, 2025 @09:34AM (#44236630)
Decades ago, a closure in Forth was especially innovative with DOES>:

  : COUNTER
    CREATE ,
    DOES> DUP 1 SWAP +! @ ;
  0 COUNTER PK
  PK .  \ => 1
  PK .  \ => 2
A semi-equivalent in Javascript is:

  const counter = init => {
    let x = init;
    return () => { x += 1; return x; };
  };
  const pk = counter(0);
  console.log(pk());  // => 1
  console.log(pk());  // => 2