Search code examples
factor-lang

Keeping quotations as tuple members in Factor


I want to keep a quotation as a member of a tuple in Factor. But when I try to execute 'call' on it I get the error 'cannot apply call to a run-time computed value'. Note that marking the functions as 'inline' does nothing.

Sample code:

USING: accessors kernel ;
IN: stackoverflow

TUPLE: quottuple quot ;
C: <quottuple> quottuple

: call-quot ( quottuple -- result )
    quot>> call ; inline

: main ( -- )
    [ 1 ] <quottuple>
    call-quot drop ;

MAIN: main

Solution

  • The answer is the 'call(' word. That word requires you to specify the stack effect of the quotation, but as a result the quotation doesn't need to be known at compile time.

    USING: accessors kernel ;
    IN: stackoverflow
    
    TUPLE: quottuple quot ;
    C: <quottuple> quottuple
    
    : call-quot ( quottuple -- result )
        quot>> call( -- result ) ;
    
    : main ( -- )
        [ 1 ] <quottuple>
        call-quot drop ;
    
    MAIN: main