gforth - 如何在 GForth 中保存程序/单词
问题描述
有没有办法将我定义的单词保存到文件中,以便以后继续试验?
到目前为止,我找到了从控制台复制+粘贴定义的唯一方法,如果它们仍然可见的话。
我是从头开始的,所以我犯了很多错误并在以后更正它们,我想保存我之前定义的单词并在下一个会话中重复使用它们。
这是一个简单的例子:
Gforth 0.7.3, Copyright (C) 1995-2008 Free Software Foundation, Inc.
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `bye' to exit
:hello ."hello";
:1: Undefined word
>>>:hello<<< ."hello";
Backtrace:
$7F29BBAB3A00 throw
$7F29BBAC9C98 no.extensions
$7F29BBAB3CC0 interpreter-notfound1
: hello ."hello";
:2: Undefined word
: hello >>>."hello";<<<
Backtrace:
$7F29BBAB3A00 throw
$7F29BBAC9C20 no.extensions
$7F29BBAB7338 compiler-notfound1
: hello ." hello"; ok
: 2hello hello hello ; ok
2hello hellohello ok
: hello ." hello "; \ added space to end redefined hello ok
2hello hellohello ok
: 2hello hello hello ; redefined 2hello ok
2hello hello hello ok
bye
现在我有工作hello
(最后有空格)和工作2hello
(使用编辑hello
) - 可以说,我有更多的麻烦来解决2hello
定义形式和定义hello
现在不在屏幕上。
- 有没有办法保存
hello
并保存2hello
到文件中,我可以在第二天使用它来制作更复杂的单词? - 它可以是文本文件吗,所以我可以使用一些编辑器(比如
vim
)来清理所有错误的定义并评论那些我想保留的?
我想以文件welcome.fth 结束:
: hello \ -- ; say hello and space at the end of word, to be able simply concatenate that
." hello ";
: 2hello \ -- ; repeats hello two times
hello hello ;
第二天就能来,继续发现
Gforth 0.7.3, Copyright (C) 1995-2008 Free Software Foundation, Inc.
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `bye' to exit
include welcome.fth ok
2hello hello hello ok
\ now I can continue with learning
解决方案
首先,gforth 将其历史记录保存在 ~/.gforth-history 文件中,任何文本编辑器都可以获取该文件以供我写作
其次,可以使用向上箭头访问历史记录,并使用编辑器保存文件,我可以爬回去并将我的输入保存到文件中。
只需将位置设置0 t
为第一行,将我的代码的最后一行添加到那里,在 as 之前插入新行i
并以这种方式填写所有其他行重新开始。insert
il
insert line
然后flush
将缓冲区写入磁盘,下次使用此文件use test.bl
并使用0 load
.
(或在编辑器中将块文件转换为普通文本include test.bl
)
我可以在不离开 gforth 的情况下做到这一点,所以它对我有用。
(最终我可以以某种方式改进它,因为它也写在了 :)
推荐阅读
- python - 在 Python 上绘制一个折线图,y 轴上有一个巨大的数字
- r - R:预测()函数产生的预测比规定的预测范围“h”更多。为什么?
- ajax - 尝试使用 Ajax 将数据数组传递给 Spring MVC 控制器
- amazon-web-services - 使用队列对异步 lambda 调用进行错误处理是一种好方法吗?
- mysql - 用从数据库中提取的值解析/替换 XML 属性/元素
- sql-server - PySaprk:spark-submit 无法执行所需的工作
- spring-cloud-stream - 如何使用 spring-cloud-stream 实现 Kafka 消费者以按需处理事件?
- java - 如果用户已经登录到 CAS,如何从 memcached 票证注册表中检查?
- c# - 找到乘以已知双精度数时将产生整数的最小整数
- python - 无法从正在运行的事件循环中调用 asyncio.run()