scala REPL 的启动脚本 [英] Startup script for scala REPL

查看:66
本文介绍了scala REPL 的启动脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

scala REPL 的启动脚本的名称是什么.例如以下内容:

What is the name of startup script for the scala REPL. For example something along the lines of the following:

~/.scalarc 

推荐答案

您可以尝试以下操作:

$ alias scala='scala -i ~/.scalarc '

注意尾随空格——如果你省略它,你的别名将忽略参数.

Note the trailing space—if you omit it your alias will disregard parameters.

进一步使用scala"(一旦定义了别名)将按预期对 REPL 起作用.如果您使用别名来启动已编译的程序,'~/.scalarc' 将被忽略.

Further use of 'scala' (once the alias is defined) will work as expected for REPL. If you use the alias for launching compiled programs, '~/.scalarc' will simply be ignored.

编辑:似乎以这种方式使用-i"会导致显着的减速.
以下虽然有些令人费解(警告:前面的 bashism),但运行速度更快:

edit: It seems using '-i' in this way causes a significant slowdown.
The following, though somewhat convoluted (warning: bashism ahead), works faster:

$ scala -i <( cat ~/.scalarc foo.scala)

这会将您的代码(例如foo.scala")与.scalarc"连接起来,并在启动时评估所有内容,让您留在 REPL.
我不认为这是一个令人满意的解决方案,但值得一提.

This concatenates your code (e.g. 'foo.scala') with '.scalarc' and evaluates everything on startup, leaving you at the REPL.
I don't think it's a satisfactory solution, but worth mentioning.

这篇关于scala REPL 的启动脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆