如何在Vscode下搭建scheme学习环境
作为程序员是不应该带有偏见的人,因为我们是创造者,我们吸取好的,摒弃不好的,努力的站在他人的肩膀上,使用咒语展现魔法的魅力和力量,美丽这个世界。
搭建Scheme环境
安装Vscode
官方网站https://code.visualstudio.com/,下载对应需要安装的平台的软件,本教程是的平台是Win10。
安装Vscode中文插件Chinese (Simplified) Language Pack for Visual Studio Code,安装Scheme语法插件vscode-scheme
,设置Vscode自带的颜色主题Ctrl+k Ctrl+t
,选择Solarized Dark主题。
安装ChezScheme解释器
下载解释器
访问官网https://www.scheme.com/,点击Chez Scheme Github project page,进入官网下载对应的版本,这里下载的是Win10的版本,默认安装路径。
设置环境变量
打开ChezScheme安装的路径C:\Program Files\Chez Scheme 9.5\bin或C:\Program Files (x86)\Chez Scheme 9.5\bin,i3nt
和ti3nt
支持Inter的电脑,a6nt
和ta6nt
支持AMD的电脑,前面是支持32位,后面支持64位,根据自己电脑将相应的bin路径放入系统环境变量。
按装win下的scheme的打包tool
测试实例Code
1 | ;; A helloworld demo |
Unbunt16环境搭建
安装Linux依赖的文件
1 | sudo apt-get install libghc-x11-dev |
使用auto-apt 和 checkinstall跟踪make install文件
1 | #安装auto-apt和checkinstall |
安装chez scheme
Libiconv的undefine问题
产生原因可参考,解决办法如下
1 | # 让Gcc链接libiconv库的头文件时去链接/usr/include/iconv.h |
原因-对比两文件
Gcc优先查找的是/usr/local/include/iconv.h
文件,导致预编译中有函数名字添加了lib字段
1 | /* Allocates descriptor for code conversion from encoding ‘fromcode’ to |
1 | /* Allocate descriptor for code conversion from codeset FROMCODE to |
安装Linux下的scheme的打包tool
安装
1 | auto-apt run ./configure -m=ta6le LDFLAGS=-liconv |
测试chez Scheme程序
通过使用 make-boot-file 可以将 Chez Scheme 程序编译为单文件
文档如下:
procedure: (make-boot-file output-filename base-boot-list input-filename …)
returns: unspecified
libraries: (chezscheme)output-filename, input-filename, and the elements of base-boot-list must be strings.
make-boot-file writes a boot header to the file named by output-filename, followed by the object code for each input-filename in turn. If an input file is not already compiled, make-boot-file compiles the file as it proceeds.
The boot header identifies the elements of base-boot-list as alternative boot files upon which the new boot file depends. If the list of strings naming base boot files is empty, the first named input file should be a base boot file, i.e., petite.boot or some boot file derived from petite.boot.
Boot files are loaded explicitly via the –boot or -b command-line options or implicitly based on the name of the executable (Section 2.9).
See Section 2.8 for more information on boot files and the use of make-boot-file.
1 | ;; lib/b.ss |
1 | # 编译 |
打包发布 Chez Scheme 程序
Chez Scheme 程序编译为单文件, 不过仍然需要 Chez Scheme 或者是 Petite Chez Scheme 才能运行,发布的时候把 Chez Scheme 打包进去。
Chez Scheme 依赖两个文件,petite.boot 和 scheme.boot, 如果用的是Petite Chez Scheme就只依赖petite.boot,.boot
文件请参考Section 9.15. Fasl Output
对于 Chez Scheme, 这两个文件的搜索路径是 ~/lib/csv%v/%m /usr/lib/csv%v/%m /usr/local/lib/csv%v/%m
具体的路径得看你安装在哪
如果 make 的时候没有指定, 那就在 /usr/lib/csv%v/%m
%v 和 %m 分别代表了 Chez Scheme 的版本和安装的 machine-type
获取版本用 scheme –version, 而获取 machine-type, 可以直接打开scheme,调用(machine-type)
比如我这里就是 /usr/lib/csv9.5/ta6le/petite.boot 和 /usr/lib/csv9.5/ta6le/scheme.boot
可以通过 –boot 或 -b 参数来加载这俩文件
然后把这几个 .boot 文件和 scheme 程序 libconvi动态库,再加个启动脚本打包分发就行了
启动脚本很简单
1 |
|
参考
使用Docker测试
1 | docker pull matace/matace-dockerfile-pri-build:scheme |