开发者

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 ] <quo开发者_如何学JAVAttuple>
    call-quot drop ;

MAIN: main


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜