iovxw

Nim语言尝试

几乎没人用

从solidot看到,稍微尝试了一下

打开官网后,第一感想是:

诶这个代码高亮的配色不错

然后看了语法什么的,觉得还算顺眼,就把首页的所有链接全部点开了

第一个版本发布的日期是2008-08-22,比go还早一点,但是没什么人用。(果然还是得拼爹啊)

教程方面,只有Tutorials栏里的两个是最新版本的,其他都是旧版

语法层面还没深入研究,就不说了

不过有两个比较有意思的特性,大体介绍一下

首先是各种命名方法可以互相兼容

就是说不管你是喜欢帕斯卡命名法还是驼峰命名法,都一样用

比如标准库里的system.hostOS,你在使用的时候可以写成system.host_os或者system.host_OS再或者system.h_Os_tOS都是可以的。除了首字母以外其他地方都不区分大小写,而下划线只要不是首尾字母,其他地方也是可以随便插入的

然后是foo(bar)可以写成bar.foo() (这个我还没用到,但是好像会很有用?)

至于编辑器支持方面,不要去看官网FAQ里的,那里面也是好久没更新了

可以直接看github上的wiki https://github.com/Araq/Nim/wiki/Editor-Support

最新更新的就是emacs的插件和官方的IDE Aporia

emacs的插件我怎么弄自动补全也没搞定,虽然有提供一个ac-nim.el

Aporia的master分支里的完全不能用!有很多严重问题。比如这个,还有自动补全和定义转跳完全不起作用(以及里面的nimrod还没有更名为nim,虽然官方开了一个分支修改名字吧)。不知道是我配置问题还是怎么着(也根据提示设置nim路径了),开发者有一个答复是nim的idetools本身挂掉了,看了下Aporia的源码照着打了几句nim idetools命令也没什么输出

去翻更新记录找到了https://github.com/nim-lang/nimsuggest这个东西,好像是0.10.3以后会用它代替idetools。于是开始折腾

先是升级nim和Aporia到0.10.3开发版,然后用nimble install nimsuggest来安装nimsuggest。但是出现错误提示~/.nimble/pkgs/compiler-0.10.3/compiler/nimfix/prettybase.nim(10, 7) Error: cannot open 'ast'

重试几遍无果,手动编译了一下compiler,发现没问题啊

浪费掉十几分钟后发现是编译器没有读取cfg?直接把源码扔到compiler文件夹里编译,成功。

我激动的打开Aporia开始尝试语义转跳,刚按下快捷键

……

Error: unhandled exception: 拒绝连接 [OSError]

窗口吡的一下就关掉了!

关!掉!了!

我还没有放弃,手动开启nimsuggest服务

再试

Traceback (most recent call last)
nimsuggest.nim(197)      nimsuggest
nimsuggest.nim(187)      handleCmdLine
nimsuggest.nim(149)      mainCommand
nimsuggest.nim(132)      serve
nimsuggest.nim(106)      action
modules.nim(203)         compileProject
modules.nim(151)         compileModule
passes.nim(197)          processModule
passes.nim(137)          processTopLevelStmt
sem.nim(450)             myProcess
sem.nim(419)             semStmtAndGenerateGenerics
semstmts.nim(1340)       semStmt
semexprs.nim(893)        semExprNoType
semexprs.nim(2196)       semExpr
importer.nim(171)        evalImport
importer.nim(161)        myImportModule
modules.nim(164)         importModule
modules.nim(151)         compileModule
passes.nim(197)          processModule
passes.nim(137)          processTopLevelStmt
sem.nim(450)             myProcess
sem.nim(419)             semStmtAndGenerateGenerics
semstmts.nim(1340)       semStmt
semexprs.nim(893)        semExprNoType
semexprs.nim(2196)       semExpr
importer.nim(171)        evalImport
importer.nim(161)        myImportModule
modules.nim(164)         importModule
modules.nim(151)         compileModule
passes.nim(197)          processModule
passes.nim(137)          processTopLevelStmt
sem.nim(450)             myProcess
sem.nim(419)             semStmtAndGenerateGenerics
semstmts.nim(1340)       semStmt
semexprs.nim(893)        semExprNoType
semexprs.nim(2189)       semExpr
semstmts.nim(1134)       semProc
semstmts.nim(1074)       semProcAux
transf.nim(788)          transformBody
transf.nim(773)          processTransf
transf.nim(761)          transform
transf.nim(104)          transformSons
transf.nim(706)          transform
transf.nim(472)          transformFor
lambdalifting.nim(1022)  liftForLoop
ast.nim(941)             []
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
*** Error in `aporia': free(): invalid pointer: 0x00007f1f16667700 ***
SIGABRT: Abnormal termination.

我仿佛已经知道十万只草泥马在心中奔腾而过的感觉了

可能永远也不会续的未完待续