开发者

Importing Factor code without putting it in the work directory?

I like version controlling my code. It would be a pain to copy every Factor file from my git over to Factor's work directory and back.

Does Factor have an import command that works like Ruby's require, one that looks in the current director开发者_开发问答y for source code?


It's easy enough to write a macro that does this. Add the following to ~/.factor-rc:

! INCLUDING macro that imports source code files in the current directory

USING: kernel vocabs.loader parser sequences lexer vocabs.parser ;
IN: syntax

: include-vocab ( vocab -- ) dup ".factor" append parse-file append use-vocab ;

SYNTAX: INCLUDING: ";" [ include-vocab ] each-token ;

Which you can use like this (see Rosetta Code).

#! /usr/bin/env factor

INCLUDING: scriptedmain ;
USING: io math.parser ;
IN: test

: main ( -- ) meaning-of-life "Test: The meaning of life is " write number>string print ;

MAIN: main
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜