5

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
Matthew Lundberg
  • 42,009
  • 6
  • 90
  • 112
Randy Voet
  • 3,670
  • 4
  • 29
  • 36

1 Answers1

5

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
Randy Voet
  • 3,670
  • 4
  • 29
  • 36
  • You can use `infer` to get the stack effect of a quotation whose stack effect may not be known at compile time. – cat Apr 09 '16 at 02:08