Hi, John!
 
The trouble in my case is -- I'd have to specify the stack effect for a call that's hidden deep inside the bi@ implementation.
 
I'm trying to refrain from inventing my own implementation of `bi@(`.
 
Is there a way to tell the compiler about the effect of a quotation on stack, so it would perform the run-time check, and take that into consideration for the further analysis? Something like this:
 
vert? [ x ] [ y ] ? check-effect( a -- b ) bi@
 
Is there a way to teach the compiler that both input quotations to the `?` have the same stack effect, therefore it wouldn't matter for the analysis which one is selected.
 
Bjourne?
 
04.02.2017, 03:42, "John Benediktsson" <[email protected]>:
You just need to tell Factor the expected stack effect.
 
See, this fails to compile, because the quotation is only selected at run-time and the compiler isn't smart enough to examine both:
 
    : foo ( seq -- seq' )
        dup length even? [ 1 - ] [ 2 + ] ? map ;
 
But, you can always do something like this where you tell Factor to call the quotation with the expected stack effect:
 
    : foo ( seq -- seq' )
        dup length even? [ 1 - ] [ 2 + ] ?
        '[ _ call( elt -- elt' ) ] map ;
 
I think that might incur some run-time performance penalties because it would check the stack effect on every call, which doesn't matter for your use-case, but might if it was inside a hot loop.
 
Best,
John.
 
 
On Fri, Feb 3, 2017 at 4:25 PM, Alexander Ilin <[email protected]> wrote:
Hello!

  I'm developing my chart gadget. I want to achieve this:

ALIAS: x first
ALIAS: y second

: chart-axes ( chart -- seq )
    [ dim>> ] [ axes>> ] bi [
        nip
    ] [
        [ 0 swap 2array ] map
    ] if* ;


M: axis draw-gadget*
    dup parent>> dup chart? [| axis chart |
        axis vertical?>> :> vert?
        chart dim>> :> dim
        dim chart chart-axes vert? [ [ x ] bi@ ] [ [ y ] bi@ ] if
        ! etc...
    ] [ 2drop ] if ;

  I thought I found a clever way to simplify that `if` there:

        dim chart chart-axes vert? [ x ] [ y ] ? bi@

  But the compiler says that I can't use `call` on runtime-computed quotations. Is there a way to work around that, like, by using a MACRO: or something?

  Or is this a hard limitation on the available abstraction of the computation?

  Basically, depending on a boolean flag I need to either take the first or the second element of the two arrays on the stack, and place the taken elements on the stack in the same order.

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

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk
,

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot

,

_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

 
 
---=====---
Александр
 
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to