有什么不同?为什么我只获得列表中的第一个元素?
-module(hello).
-export(quicksort/1,
lc_quicksort/1]).
quicksort([]) -> [];
quicksort([Pivot|Rest]) ->
quicksort([x || x <- Rest, x =< Pivot])
++[Pivot]
++ quicksort([y || y <- Rest, y > Pivot]).
lc_quicksort([]) -> [];
lc_quicksort([Pivot|Rest]) ->
lc_quicksort([Smaller || Smaller <- Rest, Smaller =< Pivot])
++ [Pivot] ++
lc_quicksort([Larger || Larger <- Rest, Larger > Pivot]).
1> c("hello.erl").
{ok,hello}
2> hello:quicksort([3, 1, 4, 2, 5, 9]).
[3]
3> hello:lc_quicksort([3, 1, 4, 2, 5, 9]).
[1,2,3,4,5,9]
Run Code Online (Sandbox Code Playgroud)
我错过了什么?发布这个以了解我在学习时错过的erlang功能.
谢谢.
ruby是否支持使用以下代码的语法:
class Test
def test
#some code here
else
#some code here
end
end
Run Code Online (Sandbox Code Playgroud)
我发现这个语法是有效的,并且ruby解释器没有为此标记任何异常.如果这是有效的,任何人都可以解释此语法的用法.
目前使用Ruby 2.1.1
I am using this snippet code (just delete first line with ed). I wanna know if i can make something like this in vim. I wrote the script and passed the file as an argument.
file:
# This is a comment #
foo bar
Run Code Online (Sandbox Code Playgroud)
edit with ed:
ed $1 << EOF
1/^[ ]*$/d
w
q
EOF
Run Code Online (Sandbox Code Playgroud)
I tried with vim:
vi $1 << EOF
dd
w
q
EOF
> Vim: Warning: Input is not from a …Run Code Online (Sandbox Code Playgroud) 我不确定为什么我的查询在localhost上运行但在服务器上失败.当我尝试创建一个路由到QuizzesController #new的测验时会发生这种情况
# GET /quizzes/new
def new
@quiz = current_user.quizzes.new
end
Run Code Online (Sandbox Code Playgroud)
这是查询:
SELECT COUNT(*) FROM "questions" INNER JOIN "question_categories" ON "question_categories"."question_id" = "questions"."id" WHERE "questions"."deleted_at" IS NULL AND (`question_categories`.`category_id` IN (87,1))
(1.0ms) ROLLBACK
Completed 500 Internal Server Error in 58ms (ActiveRecord: 13.4ms)
Run Code Online (Sandbox Code Playgroud)
我得到了一个错误.
ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR: syntax error at or near "." LINE 1: ...s"."deleted_at" IS NULL AND (`question_categories`.`category...
Run Code Online (Sandbox Code Playgroud)
quiz.rb在创建之前我会运行build_parts,它应该随机抓取问题并将它们放入测验中.class Quiz <ActiveRecord :: Base belongs_to:user belongs_to:subject has_many:quiz_categories has_many:categories,through :: quiz_categories has_many:quiz_parts
accepts_nested_attributes_for :categories
accepts_nested_attributes_for :quiz_parts
validates :user, :subject, :number_of_questions, presence: …Run Code Online (Sandbox Code Playgroud) 我正在使用我的Rails应用程序中的任何计划。在gem的文档中,我找不到如何在每周的第二个星期二和星期五运行cronjobs。
这就是我现在正在做的正确吗?
every [:tuesday, :friday], at: '12:00am', :roles => [:my_role] do
runner "User.notify"
end
Run Code Online (Sandbox Code Playgroud) 我想用Go语言编写一个Web应用程序。
运行时:
go run myscript.go
Run Code Online (Sandbox Code Playgroud)
它工作正常,我使用过“ net / http”模块,这是我在go脚本中所做的事情:
http.ListenAndServe(":8081", nil)
Run Code Online (Sandbox Code Playgroud)
我现在想与Nginx合作。我已经读过我应该将nginx置于代理模式。这意味着,当nginx在80 http端口上收到http请求时,它将代理它做8081端口。
我如何自动优化并重新启动“运行”过程?
如何在Ruby中求和
[1, 2, nil, 4]
Run Code Online (Sandbox Code Playgroud)
同
[nil, 2, nil, 4]
Run Code Online (Sandbox Code Playgroud)
并有
[1, 4, nil, 8]
Run Code Online (Sandbox Code Playgroud)
?
I have the first name and last name which both link to the users profile:
= link_to (@post.user.fname), user_path(@post.user_id)
= link_to (@post.user.lname), user_path(@post.user_id)
Run Code Online (Sandbox Code Playgroud)
These are two separate links. When I hover the mouse over the first name it only highlights the first name. And vice versa. (Example is just a randomly generated name)
How do I make the first name and last name one single link_to so it underlines the full name?
我想检查日期2017-09-21 15:30:00 -0400是否在本周范围内.
这是下面的代码:我试图输出true或false但它没有输出正确的答案.理论上这应该有效.
dateTime = Time.new(2017, 9, 21, 15, 30) => 2017-09-21 15:30:00 -0400
Range.new((Date.today), (Date.today+7.days)).include?(dateTime)
Run Code Online (Sandbox Code Playgroud)
基本上我试图检查dateTime变量是否在本周内.但我使用Time.new初始化它
我一直在寻找如何将接口转换为结构,但我不知道我怎么做不到。
我会尽力解释我的问题。
type Result struct {
Http_code int
Http_msg string
Response interface{}}
Run Code Online (Sandbox Code Playgroud)
该结构由向服务器发出 HTTP 请求的函数返回,另一方面,我有不同类型的结构来包装响应。
这是我想要转换接口的结构。
type ResHealth struct {
Type string
Get_health struct {
Healthy bool
}}
Run Code Online (Sandbox Code Playgroud)
我的问题是,当我尝试做出断言时,我总是遇到段冲突或程序无法编译。
工作流程是:
package test
type Result struct {
Http_code int
Http_msg string
Response interface{}
}
type ResHealth struct {
Type string
Get_health struct {
Healthy bool
}
}
func Do() Result {
var http_response Result
var health ResHealth
+++do something+++
http_response.Response = health
return http_response
}
package Test2
aux := post.Do()
aux.Response.(ResHealth) …Run Code Online (Sandbox Code Playgroud)