概述
最近准备学习SICP,需要配置一个Scheme的开发环境,浏览了网上的一些博客后决定采用如下环境:
操作系统:Windows10
解释器:Chez Scheme(官网,如果下载慢的话可以直接下载我上传的windows安装程序https://download.csdn.net/download/weixin_43972675/12529778)
编辑器:Visual Studio Code(需要配置插件vscode-scheme,Code Runner)
环境变量配置
安装Scheme后,配置环境变量,在Path中加入
C:\Program Files\Chez Scheme 9.5\bin\ta6nt #64位windows
C:\Program Files (x86)\Chez Scheme 9.5\bin\ti3nt #32位windows
保存后在CMD中输入Scheme即可进入Scheme交互执行环境
C:\Users\shadowgully>scheme
Chez Scheme Version 9.5
Copyright 1984-2017 Cisco Systems, Inc.
> (define pow (lambda (x) (* x x))) #定义求幂函数
> (define xdof (lambda (f x) (f x))) #定义一个以参数x调用f的函数
> (xdof pow 7) #对7求幂
49 #结果正确
> (exit) #退出交互器
VSCode配置
在Extensions中输入scheme,选择vscode-scheme并点击install。
完成后再在Extensions中输入code runner,选择code runner并点击install。
code runner安装好后需要进行必要的配置。
点击VScode左下角的齿轮,选择setting,(如果是图形界面,点击右上角的Open Settings(JSON)) ,并编辑设置文件,由于我之前用vscode写过python,配置文件里已经有部分内容
{
"python.pythonPath": "C:\\Python\\Python38\\python.exe"
}
我们需要加入的内容为
{
"code-runner.runInTerminal": true,
"code-runner.executorMapByFileExtension": {
".ss": "scheme"
}
}
加入后的格式如下(两个配置之间需要逗号间隔):
{
"python.pythonPath": "C:\\Python\\Python38\\python.exe",
"code-runner.runInTerminal": true,
"code-runner.executorMapByFileExtension": {
".ss": "scheme"
}
}
但是此时我们运行.ss后缀的scheme代码显示如下错误:
PS D:\Desktop\lisp\scheme> csi -script "d:\Desktop\lisp\scheme\try.ss"
csi : 无法将“csi”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
所在位置 行:1 字符: 1
+ csi -script "d:\Desktop\lisp\scheme\try.ss"
+ ~~~
+ CategoryInfo : ObjectNotFound: (csi:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
scheme的命令行参数并不是期待的scheme而是csi -script,该怎么办呢,在刚刚的settings.json中输入"code-runner.executorMap"会自动弹出一系列不同语言的命令行配置,找到"scheme":“csi -script”,将其修改为"scheme":"scheme"并保存,即可通过vscode运行.ss后缀的scheme代码了
{
"python.pythonPath": "C:\\Python\\Python38\\python.exe",
"code-runner.runInTerminal": true,
"code-runner.executorMapByFileExtension": {
".ss": "scheme"
},
"code-runner.executorMap": {
"javascript": "node",
"java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"php": "php",
"python": "python -u",
"perl": "perl",
"perl6": "perl6",
"ruby": "ruby",
"go": "go run",
"lua": "lua",
"groovy": "groovy",
"powershell": "powershell -ExecutionPolicy ByPass -File",
"bat": "cmd /c",
"shellscript": "bash",
"fsharp": "fsi",
"csharp": "scriptcs",
"vbscript": "cscript //Nologo",
"typescript": "ts-node",
"coffeescript": "coffee",
"scala": "scala",
"swift": "swift",
"julia": "julia",
"crystal": "crystal",
"ocaml": "ocaml",
"r": "Rscript",
"applescript": "osascript",
"clojure": "lein exec",
"haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
"rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
"racket": "racket",
"scheme": "scheme",
"ahk": "autohotkey",
"autoit": "autoit3",
"dart": "dart",
"pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
"d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
"haskell": "runhaskell",
"nim": "nim compile --verbosity:0 --hints:off --run",
"lisp": "sbcl --script",
"kit": "kitc --run",
"v": "v run",
"sass": "sass --style expanded",
"scss": "scss --style expanded"
}
}
示例代码:
(define pow (lambda (x) (* x x)))
(display (pow 49))
(exit)
Ctrl+Alt+N运行,控制台结果如下:
PS D:\Desktop\lisp\scheme> scheme "d:\Desktop\lisp\scheme\a.ss"
Chez Scheme Version 9.5
Copyright 1984-2017 Cisco Systems, Inc.
2401
成功了~,接下来就可以开始Lisp的奇妙旅程啦!