Hello!

  Why is it that I can't just store any with-... combinator in a SYMBOL, then 
use `SYMBOL get call`?
  I get it that we want to check the stack effects, but doesn't it break the 
idea of concatenativity?
  The fact that we inline all the with-... combinators -- is there a way around 
it?

  You'll want a use case, so I'll make one up.

  Let's say we have a hypothetical word, call it parse-lines-interactive:

: parse-lines-interactive ( lines -- quot/f )
    [ [ parse-lines ] with-ctrl-break
    ] with-compilation-unit ;

  And let's say we have another completely made up piece of code that does this:

        read-quot [
            '[ [ datastack _ with-datastack ] with-ctrl-break ]
            [ call-error-hook datastack ]
            recover
        ] [ return ] if*

  In both cases we use the `with-ctrl-break` combinator, which is `inline`.

  Let's say we have two implementations of it, which we want to dynamically 
switch. We begin by creating the two implementations and a SYMBOL like so:

: with-ctrl-break ( quot -- )
    enable-ctrl-break
    [ disable-ctrl-break ] [ ] cleanup ; inline

: with-no-ctrl-break ( quot -- )
    call( -- ) ; inline

SYMBOL: break-handler
[ with-no-ctrl-break ] break-handler set-global

  You can see that both `with-ctrl-break` and `with-no-ctrl-break` have the 
same stack effect: they consume one quotation.

  Now we update the code to dispatch on the SYMBOL:

: parse-lines-interactive ( lines -- quot/f )
    [ [ parse-lines ] break-handler get call( quot -- )
    ] with-compilation-unit ;

        read-quot [
            '[ [ datastack _ with-datastack ] break-handler get call( quot -- ) 
]
            [ call-error-hook datastack ]
            recover
        ] [ return ] if*

  Amazingly, this no longer works! Now, I'm asking you: where's the 
concatenativity in that?

---=====---
 Александр

------------------------------------------------------------------------------
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to