我使用不同的操作系统和Rails 3和4设置了三次Rails环境.它顺利进行,直到我打开一个控制台来输入一些Ruby,或用rails console或检查我的数据库rails dbconsole.我得到类似的东西:
$ rails console
/home/tobias/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/completion.rb:9:in `require': no such file to load -- readline (LoadError)
from /home/tobias/.rvm/rubies/ruby-1.9.2-p18080/lib/ruby/1.9.1/irb/completion.rb:9:in `<top (required)>'
from /home/tobias/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands/console.rb:3:in `require'
from /home/tobias/.rvm/gems/ruby-1.9.2-p180/gemsems/railties-3.0.9/lib/rails/commands/console.rb:3:in `<top (required)>'
from /home/tobias/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.commandsrb:20:in `require'
from /home/tobias/.rvm/gems/ruby-1.9.2-p180/gems/railsilties-3.0.9/lib/rails/commands.rb:20:in `<top (required)>'
from scriptt/rails:6:in `require'
from script/rails:6:in `<main>'
Run Code Online (Sandbox Code Playgroud)
这来自" 修复Ruby on Rails控制台的readline ".这解决了我的问题两次.
现在我使用的是Rails 4和Ruby 2,它运行良好,直到:
mto@mto-mint-vm ~/src/rpg $ rails console
/home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/completion.rb:9:in `require': /usr/local/lib/libreadline.so.6: undefined symbol: UP - /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/x86_64-linux/readline.so (LoadError)
from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/completion.rb:9:in `<top (required)>'
from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:3:in `require'
from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:3:in `<top (required)>'
from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:53:in …Run Code Online (Sandbox Code Playgroud) 我正在观看有关解析器的教程,包括haskell https://www.youtube.com/watch?v=9FGThag0Fqs.讲座从定义一些非常基本的解析器开始.这些将在以后一起用于创建更复杂的解析器.其中一个基本解析器是item.这用于从我们正在解析的字符串中提取字符.
所有解析器都具有以下类型:
type Parser a = String -> [(a, String)]
Run Code Online (Sandbox Code Playgroud)
解析器项定义如下:
item :: Parser Char
item = \inp -> case inp of
[] -> []
(x:xs) -> [(x,xs)]
Run Code Online (Sandbox Code Playgroud)
我不习惯这种语法,所以它看起来很奇怪.我会写的:
item' :: Parser Char
item' [] = []
item' (x:xs) = [(x,xs)]
Run Code Online (Sandbox Code Playgroud)
在ghci中测试它表明它们是相同的:
*Main> item ""
[]
*Main> item "abc"
[('a',"bc")]
*Main> item' ""
[]
*Main> item' "abc"
[('a',"bc")]
Run Code Online (Sandbox Code Playgroud)
讲师做了一个简短的评论,认为它看起来更清晰,但我不同意.所以我的问题是:
它们确实完全相同吗?为什么lambda版本更清晰?
我正在使用 rst 开发一个手册页。当我这样做时,我想要一种快速显示最终结果的方法。我目前这样做:
rst2man < the-man-page.rst > tmp
man ./tmp
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以在不创建临时文件的情况下使用一个班轮来做到这一点?我试图将输出直接通过管道传送到 man 命令。
我正在为一个实用程序编写一个 bash 选项卡完成文件,该文件有时需要表单上的完整 URL:protocol://host:port. 这包含两个冒号,已被证明对制表符补全有问题。这是因为冒号被视为分词符。我已阅读,我不应该改变COMP_WORDBREAKS直接,所以我想用_get_comp_words_by_ref和__ltrim_colon_completions为这里建议:如何重置COMP_WORDBREAKS,而不影响其他完成脚本?
这适用于单个冒号,但第二个冒号会导致一个小问题,如这个最小示例所示:
这个例子说明了这个问题。它出现在建议中的任意数量的冒号上。
[root@2e3e8853cc0c /]# cat /etc/bash_completion.d/foo
_foo()
{
local cur
COMPREPLY=()
_get_comp_words_by_ref -n : -c cur
COMPREPLY=( $(compgen -W "http://host:1234/aaa http://host:1234/bbb http://host:1234/ccc" -- ${cur}) )
__ltrim_colon_completions "$cur"
return 0
}
complete -F _foo foo
Run Code Online (Sandbox Code Playgroud)
foo成功完成公共部分后点击选项卡。之后点击两次 Tab 会产生以下建议:
[root@2e3e8853cc0c /]# foo http://host:1234/
1234/aaa 1234/bbb 1234/ccc
Run Code Online (Sandbox Code Playgroud)
想要的结果当然是:
[root@2e3e8853cc0c /]# foo http://host:1234/
http://host:1234/aaa http://host:1234/bbb http://host:1234/ccc
Run Code Online (Sandbox Code Playgroud)
之后,按 a、b 或 c 加选项卡按预期工作,它完成了完整的 URL。
关于如何产生正确输出的任何建议?我是否需要手动更改COMPREPLY变量,还是我只是使用了错误的函数?
我想在haskell中得到一个填充了硬编码值的矩阵.然而,由于haskell中的缩进规则,我设法做到这一点的唯一方法是将整个矩阵写在一条难以阅读的行上.
matrix = [
[1,0,0],
[0,2,0],
[0,0,3]
] --parse error (possibly incorrect indentation or mismatched brackets)
matrix = [ [1,0,0], [0,1,0], [0,0,1] ] --OK
Run Code Online (Sandbox Code Playgroud)
建议的方法是什么?