erlang

Erlang: How to access CLI flags (arguments) as application environment variables?

How does one access command line flag (arguments) as environment variables in Erlang. (As flags, not ARGV) For example: RabbitMQ cli looks something like: erl \ ... -sasl errlog_type error \ -sasl sasl_error_logger '{file,"'${RABBITMQ_SASL_LOGS}'"}' \ ... # more stuff here If one looks at sasl.erl you see the line: get_sasl_error_lo...

<< and >> symbols in Erlang

First of all, I'm an Erlang rookie here. I need to interface with a MySQL database and I found the erlang-mysql-driver. I'm trying that out, and am a little confused by some of the syntax. I can get a row of data from the database with this (greatly oversimplified for brevity here): Result = mysql:fetch(P1, ["SELECT column1, column2 ...

How to make the wxNotebook to expand?

(I have tagged this question as Python as well since I understand Python code so examples in Python are also welcome!). I want to create a simple window in wxWidgets: I create a main panel which I add to a form I associate a boxsizer to the main panel (splitting it in two, horizontally). I add LeftPanel to the boxsizer, I add RightPanel...

Simplest way to implement backend server for multiplayer JavaScript game? (COMET/longpolling)

I've been writing a game in JavaScript, and it's time to make it multiplayer. I would like to use AJAX long-polling to get the current game state, as well as implement the lobby. The server just needs to perform basic functions, like store the gamestate in the mysql database, retrieve the gamestate, and format the scoreboard. I think...

How do I create a temp filename in Erlang?

I need to put data in a file since my other function takes a file as input. How to I create a uniq filename in Erlang? Something like unix "tempfile", do it exist? ...

Building an XMERL document in Erlang

Hello - Can anyone show me how to build a simple XML document using XMERL? The documentation only shows how to append to a current XML document that is read from a file. I want to create a new XML document from scratch. For example, I want to write a simple structure like this out to an XML file: Data = {myNode,[{foo,"Foo"},{bar,"Bar"...

Debugging ErlyDB and MySQL

I am experimenting with ErlyDB in a non-erlyweb environment and I am not having much luck. I have a 'Thing' table for testing, and a corresponding Thing module: -module(thing). -export([table/0, fields/0]). table() -> thing. fields() -> [name, value]. The module itself works - I can query the database fine using ([Thing] = ...

BeepBeep and ErlyDB integration issue

Further to my adventures with Erlang and ErlyDB. I am attempting to get ErlyDB working with BeepBeep My ErlyDB setup works correctly when run outside of the BeepBeep environment (see Debugging ErlyDB and MySQL). I have basically take the working code and attempted to get it running inside BeepBeep. I have the following code in my contr...

Add Path to Erlang Search Path?

I recently installed Erlang RFC4627 (JSON-RPC) with the debian package. I ran the test server using: sudo erl -pa ebin and then at the prompt: test_jsonrpc:start_httpd(). returned ok I tested with http://:5671/ and got the success messages. When I try to run rabbitmq-http2 however, I get the errors that the readme says are cau...

Determining IP address and port of an incoming TCP/IP connection in Erlang

I would like to fetch the IP address and port number of an incoming TCP/IP connection. Unfortunately gen_tcp's accept and recv functions only give back a socket, while gen_udp's recv function also gives back the address information. Is there a straightforward way to collect address information belonging to a socket in Erlang? ...

How to format a number with padding in Erlang

I need to pad the output of an integer to a given length. For example, with a length of 4 digits, the output of the integer 4 is "0004" instead of "4". How can I do this in Erlang? ...

Is there a rigorous general introduction to event-based programming in textbook or monograph form?

I've been looking at the selection on Amazon and "The Power of Events: An Introduction to Complex Event Processing in Distributed Enterprise Systems" sounds like it has way too much fluff, but the other choices like: "Event-Based Programming: Taking Events to the Limit" sound too much like a cookbook and tie you to particular framewo...

Faster/more concise way to figure out proper size needed to store signed/unsigned ints?

Is there a faster way (possibly bit manipulation?) to find the size needed for an integer of a given value? Here's what I've got: uint_length(Value) -> if Value < 256 -> 1; Value < 65535 -> 2; Value < 4294967295 -> 4 end. sint_length(Value) -> if Value < 128 andalso Value >= 0 -> 1; Value < 32767 andalso Value >= 0 -> 2; Va...

Time zone list issue

For my application, I'm importing the calendar event from google calendar. The only problem which I'm facing is Time zone list. I'm getting the timezone as output from google calendar xml, which I have to check with time zone list and add time accordingly... so from where I can get this standard time zone list.. or some other alternati...

Designing for EWGI compatibility

I'm trying to understand how one should design middlewares for EWGI compatibility. Given that there is no EWGI compliant web server yet, I can only ask for your opinion. If I understand the spec. correctly, a middleware receives an #ewgi_context{} record as input, and returns another record of the same type. Question is, is the middlew...

Query an Erlang process for its state?

A common pattern in Erlang is the recursive loop that maintains state: loop(State) -> receive Msg -> NewState = whatever(Msg), loop(NewState) end. Is there any way to query the state of a running process with a bif or tracing or something? Since crash messages say "...when state was..." and show the crashed process...

Can't get a gen_server to crash from a spawn_linked process crash

From what I've read in the docs, gen_servers don't trap exits. Moreover, my understanding is that if a process starts another process with spawn_link, and the child process crashes, the parent crashes too. However, this is not what I'm seeing. I've got a gen_server that spawn_links a process. I set up a function in the child process lik...

Why Erlang variable is unused?

Why does compiling this code: triples( [], _,_,_)-> []; triples( Self, X, Y, none )-> [ Result || Result = { X, Y, _} <- Self ]. report: ./simple_graph.erl:63: Warning: variable 'X' is unused ./simple_graph.erl:63: Warning: variable 'Y' is unused ./simple_graph.erl:64: Warning: variable 'X' is unused ./simple_graph.erl:64: Warn...

Installing Erlang on Windows XP

I have tried installing Erlang 13B through to 12B to follow the tutorials. Everytime I get to c(tut), I get an error instead of (ok, tut), so it seems like there are no modules installed, can anyone point me in the right direction? I've tried e-macs but I don't really know how to use it and haven't even got close to getting the erlang...

How do you parameterize a gen_server module?

EDIT: I'm not looking to use parameters as a general purpose way to construct Erlang programs--I'm still learning the traditional design principles. I'm also not looking to emulate OOP. My only point here is to make my gen_server calls consistent across server instances. This seems more like fixing a broken abstraction to me. I can imag...