我遇到了一些Erlang代码,我试图将其转换为Elixir,以帮助我学习这两种语言并理解其中的差异.宏观和元编程一般是我仍然试图解决的话题,所以希望你能理解我的困惑.
Erlang代码
-define(p2(MAT, REP),
p2(W = MAT ++ STM) -> m_rep(0, W, STM, REP))
% where m_rep is a function already defined.
Run Code Online (Sandbox Code Playgroud)
对我来说,似乎在上面的代码中,有两个单独的p2宏定义映射到一个名为的私有函数m_rep.但是在Elixir中,似乎只能有一个模式匹配定义.Elixir也有可能有不同的吗?
lambda函数在Python 2和3之间的工作方式是否发生了变化?我在python 2中运行了代码,但工作正常,但在python 3中却失败了,为了尝试利用第三方模块,我试图将代码移植到其中。
pos_io_tagged = map(lambda ((word, pos_tag), io_tag):
(word, pos_tag, io_tag), zip(zip(words, pos_tags), io_tags))
Run Code Online (Sandbox Code Playgroud)
我已经研究#2多个问题,并宣读了几个如文章本,但仍然无法找到答案。我可以查看任何资源吗?
我是[noob]玩凤凰框架的乐趣和建立一个小的推特克隆.我工作的一切,但是,我想按updated_at字段(升序)订购推文.正如你在tweet_controller中看到的那样,我已经尝试过使用order_by子句,但这对我没有任何帮助.
题
我该如何实现这一目标?在EEx内或tweet_controller本身内?
鸣叫/ index.html.eex
<div class="row">
<%= for tweet <- @tweets do %>
<h4><%= tweet.tweet %></h4>
<% end %>
</div>
Run Code Online (Sandbox Code Playgroud)
控制器/ tweet_controller.ex
...
alias TodoApp.Tweet
def index(conn, _params) do
tweets = Repo.all(Tweet, order_by: tweet)
render(conn, "index.html", tweets: tweets)
end
...
Run Code Online (Sandbox Code Playgroud)