小编Pee*_*ger的帖子

在Erlang中,如何编写BFS Tree Search来查找特定节点

我想编写一个函数来在 BFS 树搜索中查找特定节点。

在 Erlang 中怎么做?

erlang

3
推荐指数
1
解决办法
690
查看次数

如何在Erlang中加载thrift客户端

我希望使用scribe从Erlang应用程序中导出一些数据,但我在运行Thrift客户端时遇到问题.我在erlang lib目录中安装Thrift.我正在使用:thrift-0.6.1

我找到了一些示例代码,用于从erlang通过thrift连接到scribe:

{ok, C} = thrift_client:start_link("localhost", 1463, scribe_thrift, 
                                     [{strict_read, false}, 
                                      {strict_write, false}, 
                                      {framed, true}]),
Run Code Online (Sandbox Code Playgroud)

但是erlang返回了这个错误:

** exception error: undefined function thrift_client:start_link/4
Run Code Online (Sandbox Code Playgroud)

当我尝试运行时application:start(thrift),我看到一些代码完成thrift*

7> thrift_client:
   call/3         close/1        module_info/0  module_info/1  new/2          
   send_call/3   
Run Code Online (Sandbox Code Playgroud)

而且没有方法start_link.

erlang thrift scribe

3
推荐指数
1
解决办法
2005
查看次数

如何在erlang中测试gen服务器?

我是erlang的初学者,我写了一个基本的gen服务器程序如下,我想知道,如何测试服务器让我知道它运行良好.

-module(gen_server_test).
-behaviour(gen_server).
-export([start_link/0]).
-export([alloc/0, free/1]).
-export([init/1, handle_call/3, handle_cast/2]).
start_link() ->
    gen_server:start_link({local, gen_server_test}, ch3, [], []).
alloc() ->
    gen_server:call(gen_server_test, alloc).
free(Ch) ->
    gen_server:cast(gen_server_test, {free, Ch}).
init(_Args) ->
    {ok, channels()}.
handle_call(alloc, _From, Chs) ->
    {Ch, Chs2} = alloc(Chs),
    {reply, Ch, Chs2}.
handle_cast({free, Ch}, Chs) ->
    io:format(Ch),
        io:format(Chs),
        Chs2 = free(),
    {noreply, Chs2}.

free() -> 
        io:format("free").
channels() ->
        io:format("channels").
alloc(chs) -> 
        io:format("alloc chs").
Run Code Online (Sandbox Code Playgroud)

BTW:该程序可以编译,它不是一个好程序,我只想打印一些东西,以确保它的工作:)

erlang gen-server

3
推荐指数
1
解决办法
1480
查看次数

有没有办法改变error_logger tty输出格式

有没有办法将格式error_logger打印消息更改为控制台或文件.

我明白了

=INFO REPORT==== 8-Jun-2011::18:46:15 ===
This is my info report. 
Run Code Online (Sandbox Code Playgroud)

我想得到这个

INFO:8-Jun-2011::18:46:15: This is my info report.
Run Code Online (Sandbox Code Playgroud)

示例是info,但它应该是错误,警告等

erlang

3
推荐指数
1
解决办法
346
查看次数

不使用`exit_status`选项时,open_port不起作用

当我exit_status在下面的例子中没有调用open_port时它是不可用的:

Eshell V5.7.5  (abort with ^G)
1>  P = open_port({spawn, "cat >bar"}, [stream, use_stdio]).
#Port<0.498>
2> port_command(P, "hello\n").
** exception error: bad argument
     in function  port_command/2
        called as port_command(#Port<0.498>,"hello\n")
Run Code Online (Sandbox Code Playgroud)

但是,当我只是添加exit_status 并保留所有相同的工作时:

Eshell V5.7.5  (abort with ^G)
1> P = open_port({spawn, "cat >bar"}, [stream, use_stdio, exit_status]).
#Port<0.498>
2> port_command(P, "hello\n").
true
Run Code Online (Sandbox Code Playgroud)

从文档中我不了解行为的差异.

erlang

3
推荐指数
1
解决办法
858
查看次数

HTTP POST多部分与命名文件

我需要发送一个(多部分)HTTP请求,其中包含一个名为的文件.这似乎比我想象的更难实现...我试图找到一种方法来使用HTTPoison,但我不能让它使用"文件"以外的名称.我已经尝试过直接使用Hackney,但似乎没有一个选项,并且肯定没有对其中任何一个显示此功能的测试.我也看了一下ibrowse和HTTPotion,但找不到任何看似有用的东西(我的Erlang非常有限,请注意).这是我想要做的一个例子,使用Ruby库Curb(注意Curl :: PostField.file采用名称和文件路径).

这是一件奇怪的事吗?或者我错过了一些明显的东西...任何建议都非常感谢.

谢谢!

http elixir phoenix-framework

3
推荐指数
1
解决办法
1701
查看次数

在Elixir应用程序中加载Erlang项目

我正在构建一个使用hackneyErlang项目的Elixir应用程序,我无法使用hackney提供的方法.我mix.exs看起来像这样:

defmodule Connecter.Mixfile do
  use Mix.Project

  def project do
    [app: :connecter,
     version: "0.0.1",
     elixir: "~> 1.2-dev",
     build_embedded: Mix.env == :prod,
     start_permanent: Mix.env == :prod,
     deps: deps]
  end

  # Configuration for the OTP application
  #
  # Type "mix help compile.app" for more information
  def application do
    [applications: [:logger]]
  end

  # Dependencies can be Hex packages:
  #
  #   {:mydep, "~> 0.3.0"}
  #
  # Or git/path repositories:
  #
  #   {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"}
  #
  # Type "mix help …
Run Code Online (Sandbox Code Playgroud)

elixir-mix elixir

3
推荐指数
1
解决办法
343
查看次数

如何使bbmustache与Elixir一起使用?

我正在尝试使用带有Elixir 的bbmustache包.调整从Erlang到Elixir的文档我尝试了多次调用,但似乎没有一个工作.

:bbmustache.render("name: {{name}}", %{"name" => "hoge"})
# => "name: "

:bbmustache.render("name: {{name}}", %{name: "hoge"})
# => "name: "

:bbmustache.render("name: {{name}}", [{:name, "hoge"}])
# => "name: "

:bbmustache.render("name: {{name}}", [{"name", "hoge"}])
# => "name: "
Run Code Online (Sandbox Code Playgroud)

可能还有一些关于字符串和二进制文件或其他内容的东西.

如果有人知道如何使它工作,那将是很棒的:-)

谢谢!

elixir mustache

3
推荐指数
1
解决办法
195
查看次数

Elixir/Phoenix处理erlang错误

我正在使用System.cmd命令来处理文件.但是,如果系统上未找到的文件,它提出了引发ArgumentError,具体Erlang error: :enoent.如何使用案例功能处理此错误?到目前为止,这是我的代码:

case System.cmd(generate_executable(settings), ["start"]) do
  {output, 0} ->
    IO.inspect("Start successful")
  {output, error_code} ->
    IO.inspect("Start failed")
end
Run Code Online (Sandbox Code Playgroud)

这种情况适用于OS的错误(无论是否开始),但不适用于erlang错误,导致凤凰告诉我:enoent. 在此输入图像描述

error-handling elixir phoenix-framework

3
推荐指数
1
解决办法
174
查看次数

摆脱科学记数法

我需要做一些计算但是我遇到的问题是非常低的值,例如,我需要获得0.005%的2.7%而我最终得到1.3500000000000003e-4这不是我想要的,我只需要知道如何获得这些值的准确感知,我现在正在做的是<value> * 2.7 / 100对整数或大于0.05的浮点数有效.

例如,我需要的那个是0.005%的0.005,需要显示为0.000135.

elixir

2
推荐指数
1
解决办法
768
查看次数