使用 Factor 源树之外的代码

发布于 2025-01-06 01:28:20 字数 1902 浏览 1 评论 0原文

我正在尝试开始玩因子。

到目前为止,我已经:

  • 下载了 OSX 磁盘映像
  • 将因子目录复制到 $INSTALL/factor
  • 通过运行 $INSTALL/factor/factor 启动调试器

这似乎是跑得很好。

按照编写第一个因子程序的说明,我注意到scaffold-vocab 在我的 $INSTALL/factor/work 目录中生成文件。我现在可以使用它,但总的来说,我喜欢保留单独的 $INSTALL 目录树和 $CODE 目录树。

因此,我尝试按照 “使用外部代码”中的说明进行操作Factor 目录树”文档 将其他目录添加到用于将代码加载到 factor 可执行文件的路径中,但我运气不佳。

首先,我尝试设置一个 FACTOR_ROOTS 环境变量:

% export FACTOR_ROOTS=.:$CODE/Factor:$INSTALL/factor
% $INSTALL/factor/factor
( scratchpad ) "work" resource-path .
"/usr/local/src/factor/work"
( scratchpad ) ^D

然后,我尝试创建一个 ~/.factor-roots 文件

% echo . > ~/.factor-roots
% echo $CODE/Factor >> ~/.factor-roots 
% echo $INSTALL/factor >> ~/.factor-roots
% $INSTALL/factor/factor        
( scratchpad ) "work" resource-path .
"/usr/local/src/factor/work"
( scratchpad ) ^D

然后我检查它是否应该是 ./.factor-roots 相反:

% mv ~/.factor-roots .
% $INSTALL/factor/factor
( scratchpad ) "work" resource-path .
"/usr/local/src/factor/work"
( scratchpad ) ^D

最后,我尝试手动添加它:

% $INSTALL/factor/factor
( scratchpad ) "." add-vocab-root            
( scratchpad ) "$CODE/Factor" add-vocab-root ! no, I didn't actually use an environment variable here :)
( scratchpad ) "work" resource-path .
"/usr/local/src/factor/work"
( scratchpad ) ^D

看来我在这里缺少一些基本的东西。

如何在 $INSTALL/factor 目录树之外编写代码并在 Factor 中使用它?如何告诉 scaffold-vocab 在我的 $CODE/Factor 目录中构建脚手架?

I'm trying to get started playing with factor.

So far, I've:

  • downloaded the OSX disk image
  • copied the factor directory into $INSTALL/factor
  • started up the debugger by running $INSTALL/factor/factor

Which seems to be running great.

Following the instructions for writing your first factor program, I noticed that scaffold-vocab generated files in my $INSTALL/factor/work directory. Which I can use for now, but in general, I like to keep a separate $INSTALL directory-tree and $CODE directory-tree.

So I'm trying to follow the instructions from the "Working with code outside of the Factor directory tree" documentation to add other directories to the path used to load code into the factor executable, but I'm not having much luck.

First, I tried to set a FACTOR_ROOTS environment variable:

% export FACTOR_ROOTS=.:$CODE/Factor:$INSTALL/factor
% $INSTALL/factor/factor
( scratchpad ) "work" resource-path .
"/usr/local/src/factor/work"
( scratchpad ) ^D

Then, I tried to create a ~/.factor-roots file

% echo . > ~/.factor-roots
% echo $CODE/Factor >> ~/.factor-roots 
% echo $INSTALL/factor >> ~/.factor-roots
% $INSTALL/factor/factor        
( scratchpad ) "work" resource-path .
"/usr/local/src/factor/work"
( scratchpad ) ^D

Then I checked to see if it should be ./.factor-roots instead:

% mv ~/.factor-roots .
% $INSTALL/factor/factor
( scratchpad ) "work" resource-path .
"/usr/local/src/factor/work"
( scratchpad ) ^D

Lastly, I tried adding it manually:

% $INSTALL/factor/factor
( scratchpad ) "." add-vocab-root            
( scratchpad ) "$CODE/Factor" add-vocab-root ! no, I didn't actually use an environment variable here :)
( scratchpad ) "work" resource-path .
"/usr/local/src/factor/work"
( scratchpad ) ^D

It seems I'm missing something fundamental here.

How do I write code outside of the $INSTALL/factor directory-tree and use it in factor? How can I tell scaffold-vocab to build scaffolding in my $CODE/Factor directory?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林迷了鹿 2025-01-13 01:28:20

好吧,由于 slava 和 的热心帮助,我能够找出我做错了什么erg #concatenative

简而言之,资源路径 不是测试因子根的方法。就像文档所说的那样,它“解析相对于 Factor 源代码位置的路径”。

更有效的测试就是 vocab-roots get,它将获取当前的词汇词根列表。

"/path/to/wherever" add-vocab-root 会将 /path/to/wherever 添加到您的词汇根列表中,并允许您执行 "/path/to/wherever" "project"scaffold-vocab 这样您就可以在所需的位置构建脚手架。

正如尔格所说:

我通常会造另一个词,比如
:scaffold-games ( vocab -- ) [ "/home/erg/games" ] diffscaffold-vocab ;
“扫雷”脚手架游戏

Ok, I was able to work out what I was doing wrong thanks to the earnest help of slava and erg on #concatenative.

Simply put, resource-path is not a way to test your factor roots. Like the docs say it "resolve[s] a path relative to the Factor source code location."

A more effective test is simply vocab-roots get, which will fetch the current list of vocab roots.

"/path/to/wherever" add-vocab-root will add /path/to/wherever to your list of vocab-roots, and allow you to do "/path/to/wherever" "project" scaffold-vocab so you can build scaffolding in the desired location.

As erg said:

i usually make another word, like
: scaffold-games ( vocab -- ) [ "/home/erg/games" ] dip scaffold-vocab ;
"minesweeper" scaffold-games

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文