首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在因子中的Shell脚本之外持久化更改目录?

如何在因子中的Shell脚本之外持久化更改目录?
EN

Stack Overflow用户
提问于 2016-10-27 14:51:38
回答 1查看 93关注 0票数 2

我在文件中有以下因素代码:

代码语言:javascript
运行
复制
IN: set-work-dir
USING: shell ;
CONSTANT: work-dir "/code" ! I also tried "c:/code" and "c:\\code"--same error
work-dir cd 

当我试图从因子运行脚本时,我会得到以下错误:

代码语言:javascript
运行
复制
C:\>/usr/bin/factor/factor /usr/bin/factor/work/set-work-dir.factor
Generic word absolute-path does not define a method for the fixnum class.
Dispatching on object: 47
(U) Quotation: [ c-to-factor => ]
    Word: c-to-factor
(U) Quotation: [ [ (get-catchstack) push ] dip call => (get-catchstack) pop* ]
(O) Word: command-line-startup
(O) Word: run-script
(O) Word: set-current-directory
(O) Method: M\ object absolute-path
(O) Word: no-method
(O) Method: M\ object throw
(U) Quotation: [
        OBJ-CURRENT-THREAD special-object error-thread set-global
        current-continuation => error-continuation set-global
        [ original-error set-global ] [ rethrow ] bi
    ]

我可以让它运行,如果不是USING: shell ;,而是有USING: io.files.private,但是目录更改不会在脚本运行之外保留下来。我假设使用shell会导致目录更改持续存在--我意识到这可能是一个错误的假设。如何编写一个脚本来更改目录,并使目录更改在脚本之外持久存在?

Windows 7(是的,我知道Windows上的dir分隔符通常是\,我也尝试了'\‘。但是/实际上也能在Windows上工作。此外,当我使用io.files.private时,路径也能工作)。

因子0.98x86.64(1788年,heads/master-e187d63d3c,Tue Oct 18 02:14:22 2016)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-30 18:23:29

cd的工作存在于两种声音中。哪一个cd将调用取决于您是什么USING:。如果shell,则调用shell:cd,如果调用io.files.private,则调用io.files.private:cd。当然,您也可以使用完全限定的名称。

不过,用户代码不应该使用io.files.private:cd这个词,因为该词汇表的名称以.private结尾,这表明该单词不是公共接口的一部分。而是使用set-current-directory

代码语言:javascript
运行
复制
IN: scratchpad "/tmp" set-current-directory
IN: scratchpad "." absolute-path .
"/tmp"

在“因素”处理终止后,更改不会持续。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40287797

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档