erlang

Erlang/ets: reset ets table after getting a "bad argument"?

I've been learning how to use ets, but one thing that has bothered me is that, occasionally*, ets:match throws a bad argument… And, from them on, all subsequent calls (even calls which previously worked) also throw a bad argument: > ets:match(Tid, { [$r | '$1'] }, 1). % this match works... % Then, at some point, this comes up: ** excep...

What should a software engineer (web) start by learning - Erlang, Haskell, Python, C++, F#

What would you suggest what will be the next choice of language that could benefit an engineer in his career utmost? I am a Software Engineer and almost everything I engineered is for WWW. I have decided to learn a language and keep it learning parallel. I'm fluent in C# and JavaScript. But, apart from it I want to learn a language whic...

What is the correct usage of the Nitrogen Auth API?

Just wanting to confirm the usage of the Nitrogen Authentication and Authorization API. The description of the API is: wf:user() -> User or 'undefined' Return the user value that was previously set by wf:user(User) wf:user(User) -> ok Set the user for the current session. wf:clear_user() -> ok Same as wf:user(undefined). wf:role(Role...

string to abstract syntax tree

I would like to convert a string containing a valid Erlang expression to its abstract syntax tree representation, without any success so far. Below is an example of what I would like to do. After compiling, alling z:z(). generates module zed, which by calling zed:zed(). returns the result of applying lists:reverse on the given list. -m...

Detecting HTTP close using inet

In my mochiweb application, I am using a long held HTTP request. I wanted to detect when the connection with the user died, and I figured out how to do that by doing: Socket = Req:get(socket), inet:setopts(Socket, [{active, once}]), receive {tcp_closed, Socket} -> % handle clean up Data -> % do someth...

Erlang: erl shell hangs after building a large data structure

As suggested in answers to a previous question, I tried using Erlang proplists to implement a prefix trie. The code seems to work decently well... But, for some reason, it doesn't play well with the interactive shell. When I try to run it, the shell hangs: > Trie = trie:from_dict(). % Creates a trie from a dictionary % ... the trie is...

Does it make sense to use a pool of Actors?

I'm just learning, and really liking, the Actor pattern. I'm using Scala right now, but I'm interested in the architectural style in general, as it's used in Scala, Erlang, Groovy, etc. The case I'm thinking of is where I need to do things concurrently, such as, let's say "run a job". With threading, I would create a thread pool and a...

How do you unwire an action in Nitrogen?

In Nitrogen, the Erlang web framework, you wire actions like this: wf:wire(send_message, #event { type=click, postback=send_message }) but if after that you run wf:wire(send_message, #event { type=click, postback=send_message2 }), then you get the action wired twice. How do you unwire the previous action or all actions of an eleme...

Are events always run in the same process in Nitrogen?

I'm taking about event function in Nitrogen, the Erlang web framework, in a web module that is run when you get a postback. Does event always run in the same process for the same web client (that is, browser window or frame). I've recall at least one case in which that didn't happen, but I can't reproduce it. ...

How to efficiently set one bit at a time in an Erlang binary whithout going imperative?

As an exercise I am working on a parallel implementation of the Sieve of Eratosthenes. As part of that I am implementing a sequence of bitmaps, using one bit per number to save memory. Reading bits one at a time appear to work fine, but setting them is slow, especially when I use large binaries. getBit(Bin, N, Size)-> R=Size-N-1, ...

How to keep track of a process per browser window and access it at each event in Nitrogen?

In Nitrogen, the Erlang web framework, I have the following problem. I have a process that takes care of sending and receiving messages to another process that acts as a hub. This process acts as the comet process to receive the messages and update the page. The problem is that when the user process a button I get a call to event. How d...

Optimizing performance on Erlang processes

Hi all, In a test I'm building here my goal is to create a parser. So I've built a concept proof that reads all messages from a file, and after pushing all of them to memory I'm spawning one process to parse each message. Until that, everything is fine, and I've got some nice results. But I could see that the erlang VM is not using all ...

How many cpus before Erlang faster than single threaded Java

I am currently using java and have read a lot about Erlang on the net and I have 2 big questions: How much slower (if any) will Erlang be over simple Java. I'm assuming here that Java is going to be faster from the shootout benchmarks on the net (Erlang doesn't do that well). i.e. How many more cpus am I going to need to make the Erl...

Two quick consecutive calls to wf:insert_bottom end up in the reverse order

Using Nitrogen, the Erlang web framework, I have the following method that receives messages and adds them to the bottom of an html element: receive_messages() -> receive Message -> io:format("~p received ~p", [self(), Message]), wf:insert_bottom(messages, [#p{}, #span { text=io_lib:format("~p", [Message]) }]) end, ...

Erlang: How is distel for emacs "reload" command supposed to work?

Here is what I do, based on how I thought reload should work. I start an erlang node. I connect to that node in distel. I edit a buffer whose beam file is in the node from step 1's beam paths. That means it's loaded, right? I edit an erlang buffer which represents a module loaded in a step one's node. I add a function. I run reload in ...

Convert a string into a fun

I'm trying to get around a problem with file:consult/1 not allowing tuples with fun in them like in this example: {add_one, fun(X) -> X+1 end}. To get around this I'm considering writing the fun inside a string and evaluating it {add_one, "fun(X) -> X+1 end"}. The question is. How do I convert the string into a fun? ...

Compile forms with included header files

I'm trying to compile a module from forms, with included header files. First, if I have the module in a source file, everything works fine. user.hrl -record(user, {name :: string()}). zed.erl -module(zed). -export([f/1]). -include("user.hrl"). f(User) -> User#user.name. shell 1> compile:file(zed, [return]). {ok,zed,[]} 2> rr...

Why an epmd process doesn't exit ?

Is it a bug or a feature that epmd process still exists after I exit from an erlang shell ? ...

How to create global variables in Erlang

Hi, I am writing an ejabberd module to filter packets. I need to get the hostname to pull some configs using gen_mod:get_module_opt() . I have 4 important functions : start(Host, _Opt) : This is an ejabberd function to load my module. I get the 'Host' atom here filter_packet({From, To, XML}) : This is my packet filter hook. I cannot...

Unflash a message with Nitrogen

I have a login page for my Nitrogen based web app. If user authentication fails I wf:flash a message to the user to let them know. However if the user continues to supply bad credentials these flash message keep building up. Is there a way to first clear the flashed messages before posting a new one? ...