我可以用rvm安装任何ruby,我总是得到这个,在linux linux(manjaro)
[anquegi@manjaro-pc ~]$ rvm install 2.1.6 --autolibs=packages
ruby-2.1.6 - #removing src/ruby-2.1.6..
Searching for binary rubies, this might take some time.
No binary rubies available for: manjaro/16.06-pre1/x86_64/ruby-2.1.6.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for manjaro.
Requirements installation successful.
Installing Ruby from source to: /home/anquegi/.rvm/rubies/ruby-2.1.6, this may take a while depending on your cpu(s)...
ruby-2.1.6 - #downloading ruby-2.1.6, this may take a while depending on your connection...
ruby-2.1.6 - #extracting …
Run Code Online (Sandbox Code Playgroud) 如果我在 raku 中有以下程序,它运行良好:
trabajando-en-piensa-en-raku on ? master [?] via v2.6.5
? cat factorial.raku
sub factorial( $n ) {
[*] 1 .. $n;
}
sub postfix:<!>( $n ) {
[*] 1 .. $n;
}
my $n = 5;
say "El factorial de $n es {factorial $n}";
say "Si calculamos $n! obtenemos {$n!}";
trabajando-en-piensa-en-raku on ? master [?] via v2.6.5
? raku factorial.raku
El factorial de 5 es 120
si calculamos 5! obtenemos 120
Run Code Online (Sandbox Code Playgroud)
但是如果我在 raku REPL 中定义这个函数,我会得到:
> * * &factorial …
Run Code Online (Sandbox Code Playgroud) 使用常见的lisp你可以添加许多文档字符串,例如:
CL-USER> (defun foo ()
"doc string for foo"
nil)
FOO
CL-USER> (documentation 'foo 'function)
"doc string for foo"
CL-USER> (describe 'foo)
COMMON-LISP-USER::FOO
[symbol]
FOO names a compiled function:
Lambda-list: ()
Derived type: (FUNCTION NIL (VALUES NULL &OPTIONAL))
Documentation:
doc string for foo
Source form:
(SB-INT:NAMED-LAMBDA FOO
NIL
"doc string for foo"
(BLOCK FOO NIL))
; No value
Run Code Online (Sandbox Code Playgroud)
所以最后我可以读回文档字符串,但是使用符号和变量我无法通过文档获取它:
CL-USER> (defparameter bar 3 "doc string for bar")
BAR
CL-USER> (describe 'bar)
COMMON-LISP-USER::BAR
[symbol]
BAR names a special variable:
Value: 3 …
Run Code Online (Sandbox Code Playgroud) 我编写了一个用于监视 Rest API 的 shell 脚本,当它关闭时,shell 脚本会发送两封邮件,一封发送给开发人员,另一封发送给经理。问题是我需要这个频率:
\n\n工作日办公时间(9-18 小时)每 15 分钟运行一次,并向经理和开发人员发送邮件
工作日下午 6 点至 9 点以及 18 点至 24 点每小时运行并向经理发送邮件。
每晚 00:00 至 6:00 每 3 小时运行一次,节假日发送邮件给经理
\xc2\xbf节假日和工作日之间如何丢弃?
\n我想结合两个列表的所有可能组合,为此我使用mapcar
CL-USER> (mapcar #'(lambda (x) (mapcar #'(lambda (y) (list x y)) '(aa bb cc dd))) '(a b c))
(((A AA) (A BB) (A CC) (A DD)) ((B AA) (B BB) (B CC) (B DD))
((C AA) (C BB) (C CC) (C DD)))
Run Code Online (Sandbox Code Playgroud)
答案是正确的,但我得到一个嵌套列表,我该如何解决这个问题.我不想将该列表压平一层,我对mapcar的使用很糟糕,但我无法弄清楚如何解决这个问题
我正在使用sbcl 1.4.6,我有这种行为:
* (trace string<)
(STRING<)
* (string< "hola" "pato")
0: (STRING< "hola" "pato")
0: STRING< returned 0
0
* (defun test-without-cond (str)
(string< "hola" str))
TEST-WITHOUT-COND
* (test-without-cond "pato")
0
Run Code Online (Sandbox Code Playgroud)
如果函数已在公共lisp中定义,则在用户定义的函数内使用时,我无法使用跟踪.如果我定义函数,这不是问题
* (defun my-string< (str) (string< str "hello"))
MY-STRING<
* (trace my-string<)
(MY-STRING<)
* (defun test-2 (str) (my-string< str))
TEST-2
* (test-2 "gato")
0: (MY-STRING< "gato")
0: MY-STRING< returned 0
0
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
我有以下数组:
a
=> ["http://dominio-1-736865.com/path1",
"http://dominio-2-570941.com/path2",
"http://102.160.194.146/path4",
"http://142.231.2.110",
"http://142.231.2.110/path/inventado",
"http://dominio-3-468658.com/path2",
"http://dominio-3-468658.com/path2/path1",
"http://dominio-3-468658.com/path2/path2",
"http://subdominio.dominio-3-468658.com/path2",
"http://www.dominio-3-468658.com/path2",
"http://este-se-repite.re/AP-448055"]
Run Code Online (Sandbox Code Playgroud)
然后我需要像这样分组:
fqdns
=> ["dominio-1-736865.com", "dominio-2-570941.com", "102.160.194.146", "142.231.2.110", "dominio-3-468658.com", "subdominio.dominio-3-468658.com", "este-se-repite.re"]
Run Code Online (Sandbox Code Playgroud)
得到这个=
["http://dominio-1-736865.com/path1"]
["http://dominio-2-570941.com/path2"]
["http://102.160.194.146/path4"]
["http://142.231.2.110", "http://142.231.2.110/path/inventado"]
["http://dominio-3-468658.com/path2", "http://dominio-3-468658.com/path2/path1", "http://dominio-3-468658.com/path2/path2", "http://www.dominio-3-468658.com/path2"]
["http://subdominio.dominio-3-468658.com/path2"]
["http://este-se-repite.re/AP-448055"]
Run Code Online (Sandbox Code Playgroud)
问题在于subdominio.dominio-3-468658.com和dominio3-468658.com,这可能是两个但我只需要在有子域的情况下见面.如何在红宝石中实现这一点
[25] pry(#<Notifications::Notification>)> a.map{|d| d.match(fqdns[1])}
=> [nil, #<MatchData "dominio-2-570941.com">, nil, nil, nil, nil, nil, nil, nil, nil, nil]
[26] pry(#<Notifications::Notification>)> a.map{|d| d.match(fqdns[0])}
=> [#<MatchData "dominio-1-736865.com">, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
[27] pry(#<Notifications::Notification>)> a.map{|d| d.match(fqdns[2])}
=> [nil, nil, #<MatchData "102.160.194.146">, …
Run Code Online (Sandbox Code Playgroud) 在ruby中你可以重新启动,这样的多个例外:
begin
...
rescue Exception1, Exception2
...
rescue Exception1
...
rescue Exception2
...
end
Run Code Online (Sandbox Code Playgroud)
但我不知道如何提出多个例外:
1] pry(main)> ? raise
From: eval.c (C Method):
Owner: Kernel
Visibility: private
Signature: raise(*arg1)
Number of lines: 13
With no arguments, raises the exception in $! or raises
a RuntimeError if $! is nil.
With a single String argument, raises a
RuntimeError with the string as a message. Otherwise,
the first parameter should be the name of an Exception
class (or an object that returns …
Run Code Online (Sandbox Code Playgroud) 我有一个列表,可以有一个字符串或选项[字符串]
像这样
val a = List("duck","dog","cat")
a.mkString(:)
duck:dog:cat
val b = List(Some("duck"), "dog", None)
Run Code Online (Sandbox Code Playgroud)
我的输出应该是
“鸭:狗”
我该怎么做,我得到了一些近似值:
scala> a.map{ x =>
| x match {
| case x:String => x
| case Some(x:String) => x
| case None => null}}
List[String] = List(duck, dog, null)
scala> res.filter(_!=null).mkString(":")
res24: String = duck:dog
Run Code Online (Sandbox Code Playgroud)
有更好的方法吗?