erlang-shell

Erlang case statement

为君一笑 提交于 2019-12-24 04:22:14
问题 I have the following Erlang code and it is giving the warning as follows, when i try to compile it, but that make sense. function need two arguments, but i need to patten match "everything else" rather x, y or z. -module(crop). -export([fall_velocity/2]). fall_velocity(P, D) when D >= 0 -> case P of x -> math:sqrt(2 * 9.8 * D); y -> math:sqrt(2 * 1.6 * D); z -> math:sqrt(2 * 3.71 * D); (_)-> io:format("no match:~p~n") end. crop.erl:9: Warning: wrong number of arguments in format call. I was

REST API implementation using Yaws

六月ゝ 毕业季﹏ 提交于 2019-12-22 10:13:06
问题 I'm trying to build a REST API using the Yaws web server but I'm unable to get Yaws to dispatch requests to my module. -module(rest). -include_lib("stdlib/include/qlc.hrl"). -include_lib("yaws/include/yaws_api.hrl"). -export([out/1, addAirport/4, handle/2]). -compile(export_all). -define(RECORD_TYPE, airport). -define(RECORD_KEY_FIELD, code). -record(airport, {code, city, country, name }). start() -> application:start(mnesia). do_this_once() -> mnesia:create_table(airport, [{attributes,record

How to run a set of TWEANN benchmarks in Erlang correctly?

别来无恙 提交于 2019-12-13 02:37:32
问题 I've been reading Gene I Sher's Handbook to neuroevolution through Erlang and trying to replicate all the experiments described there. And it all worked, until I came to chapter 19, which read Having set everything up, we execute the benchmark for every noted experimental setup, and run it to completion. To do this, we simply modify the constraints used in our benchmarker module, and then execute benchmarker:start(Experiment_Name) , for every of our experimental setups. There are 14

Can I use an existing OTP application inside another application or module?

扶醉桌前 提交于 2019-12-12 19:56:26
问题 I'm building a system that needs to use a previously built OTP application (lets call it X). If I want to build a new OTP application / module, how can I use the application that already exists from a module, for instance? I assumed I could call start , since it follows the application behaviour, and so I built a minimalistic application Y that has the following code: y.erl: -module(y). -behaviour(application). start(_StartType, _StartArgs) -> io:format("going to call x_app~n"), {ok, _} = x

Erlang trying to evaluate a string

坚强是说给别人听的谎言 提交于 2019-12-12 02:48:37
问题 I'm trying to dynamically evalutate Erlang terms Start up Erlang basho-catah% erl Erlang R16B03 (erts-5.10.4) [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] Eshell V5.10.4 (abort with ^G) Create a term 1> {a,[b,c,d]}. {a,[b,c,d]} Try to scan in the same term 2> {ok, Tokens, _ } = erl_scan:string("{a,[b,c,d]}"). {ok,[{'{',1}, {atom,1,a}, {',',1}, {'[',1}, {atom,1,b}, {',',1}, {atom,1,c}, {',',1}, {atom,1,d}, {']',1}, {'}',1}], 1} 3> Tokens. [{'{',1}, {atom,1,a}, {','

Erlang MapReduce on Riak database giving exception

别等时光非礼了梦想. 提交于 2019-12-11 03:14:23
问题 I am going through the tutorials of riak and Erlang, I have stored data in riak by the riak-erlang-client and i did the following: 1> {ok,Pid} = riakc_pb_socket:start_link("127.0.0.1", 8087). {ok,<0.34.0>} 2> Val1 = [1,2,3]. [1,2,3] 3> MyBucket = <<"numbers">>. <<"numbers">> 4> Obj1 = riakc_obj:new(MyBucket,<<"ott">>,Val1). 5> riakc_pb_socket:put(Pid,Obj1). ok 6> {ok, Fetched} = riakc_pb_socket:get(Pid,MyBucket,<<"ott">>). {ok,{riakc_obj,<<"numbers">>,<<"ott">>, <<107,206,97,96,96,96,204,96

How do you unbind variables in an interactive Erlang session?

不打扰是莪最后的温柔 提交于 2019-12-09 07:46:38
问题 In the Erlang interactive shell you can bind variables to values. If I would like to clear everything and start from scratch without exiting the session and starting a new one, how do I do that? And if I just wanted to re-use a single variable, is it possible to re-bind? 回答1: Use f() and f(Var): 1> A = 1, B = 2. 2 2> f(A). ok 3> A. * 1: variable 'A' is unbound 4> B. 2 5> f(). ok 6> B. * 1: variable 'B' is unbound 7> Shell commands are actually functions in the 'c' module: http://www.erlang

REST API implementation using Yaws

不打扰是莪最后的温柔 提交于 2019-12-05 20:22:08
I'm trying to build a REST API using the Yaws web server but I'm unable to get Yaws to dispatch requests to my module. -module(rest). -include_lib("stdlib/include/qlc.hrl"). -include_lib("yaws/include/yaws_api.hrl"). -export([out/1, addAirport/4, handle/2]). -compile(export_all). -define(RECORD_TYPE, airport). -define(RECORD_KEY_FIELD, code). -record(airport, {code, city, country, name }). start() -> application:start(mnesia). do_this_once() -> mnesia:create_table(airport, [{attributes,record_info(fields,airport)},{index, [country]}]), mnesia:stop(). out(Arg) -> Method = method(Arg) , io

how to execute system command in erlang and get results - unreliable os:cmd/1

血红的双手。 提交于 2019-12-05 03:14:36
问题 When I try to execute following command that returns error or doesn't exit on Windows - I always get empty list instead of error returned as string so for example: I get: [] = os:cmd("blah"). instead of something like "command not found" = os:cmd("blah"). In linux - everything works as expected so I get "/bin/sh: line 1: blah: command not found\n" Therefore I cannot rely on that function when I need to know how execution finished etc. Please suggest some general way how to execute command and

Erlang remote shell not working

做~自己de王妃 提交于 2019-11-29 09:57:32
I have some strange behaviour on my docker containers (CentOS). When I SSH into it there's a running instance of Erlang VM (api@127.0.0.1) I can't connect to it with -remsh argument, however I can ping it. My Erlang node (api@127.0.0.1) works correctly though. bash-4.2# ./bin/erl -name 'remote@127.0.0.1' -remsh 'api@127.0.0.1' Eshell V6.1 (abort with ^G) (remote@127.0.0.1)1> node(). 'remote@127.0.0.1' (remote@127.0.0.1)2> net_adm:ping('api@127.0.0.1'). pong (remote@127.0.0.1)3> erlang:system_info(system_version). "Erlang/OTP 17 [erts-6.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe]