erlang

List is conceived as integer by length function

I'm trying to learn Erlang using the Karate Chop Kata. I translated the runit test supplied in the kata to an eunit test and coded up a small function to perform the task at hand. -module(chop). -export([chop/2]). -import(lists). -include_lib("eunit/include/eunit.hrl"). -ifdef(TEST). chop_test_() -> [ ?_assertMatch(-1, chop(3, []))...

Parse MIME messages

Hi, For my new project which has email module.i need to show all the email information on web.when i m making a call to server i m getting the base64 encoded mime data. after applying base64 decoding technique i m getting the mime data as follows: /*****************Mime data start *******************************/ From prashant.n@geode...

Using Map on a list of tuples and print it as flat string in Erlang

I have a list of tuples: X = [{"alpha","beta"},{"gamma","theta"}]. I want to print X as a flat string using, io_lib:format("~s", [X]) in the following format: [{"x":"alpha", "y":"beta"}, {"x":"gamma", "y":"theta"}] How do I achieve this? I started using Map to do transform the list. But I was not able to print it as a string...(ga...

Erlang style - case vs function pattern matching

I've got to the stage where I've written quite a bit of Erlang code now, and I can see some style (bad or good) creeping into the way I've been writing it. This particular idiom I'd like some opinion on - is it better (more readable/faster/whatever) to convert case style statements to function pattern matching? E.g. Compare (a contrive...

Please walk me through this "Erlang Programming" recursive sample

From page 90 of Erlang Programming by Cesarini and Thomson, there is an example that has no detailed discussion. I'm quite the newbie to functional programming and recursive thinking, so I'm not familiar in solving problems this way. "For example, the following function merges two lists (of the same length) by interleaving their values...

unimportant question about erlang and functional programming

I stumbled upon this question and i realized i forgot a lot of stuff from my nonprocedural programming class. As I was trying to understand the code it seemed to me that it's terribly long-winded, so i attempted to shorten it. Does this do the same thing that the original code does? merge([X|Xs], Ys) -> [X | merge(Ys, Xs)]; merge([], [...

Hidden Features of Erlang

In the spirit of: Hidden Features of C# Hidden Features of Java Hidden Features of ASP.NET Hidden Features of Python Hidden Features of HTML and other Hidden Features questions What are the hidden features of Erlang that every Erlang developer should be aware of? One hidden feature per answer, please. ...

Unique constraint in Mnesia

I am developing an Erlang application which requires a LOT of DB writes. My schema has, in addition to the primary key, another attribute with a unique constraint enforced. Say I have an ID, an unique_constraint_field, and some other fields. I need to now update a row in the DB corresponding to the unique ID, given that no other row sh...

Erlang File Append mode

Hi, I m trying to write some content in file using append mode in erlang but it giving error as bad argument. Syntax used: file:write_file("/tmp/test1.txt","Abhimanyu","append"). error:{error,badarg} thank you ...

Parsing JSON in Erlang

I have a piece of JSON string, which I want to parse in Erlang. It looks like: ({ id1 : ["str1", "str2", "str3"], id2 : ["str4", "str5"]}) I looked at mochijson2, and a couple of other JSON parsers, but I really could not figure out how to do it. Any help greatly appreciated! ...

immutable java

immutability, any good sources on writing immutable programs in a functional way with java? shifting over to erlang - scala - clojure is not a possibility. ...

Header parsing + MIME

Hi, While parsing MIME using Erlang, I'm able to extract header, body and attachment. So now I have to parse all these parts separately. Header structure: Header-tag : header-value\n Example: Delivered-To: [email protected]\nReceived: by 1.gnu.geodesic.net (fdm 1.5, account "mail");\n\tFri, 03 Jul 2009 16:56:03 +0530\n so from abo...

Using native MySQL driver in Erlang

I am using native MySQL driver (http://code.google.com/p/erlang-mysql-driver/) with mochiweb. When I tried that MySQL driver in shell mode, all woked fine. But when I write some code with Mochiweb, it reported me the following error: =CRASH REPORT==== 4-Jul-2009::04:44:29 === crasher: initial call: mochiweb_socket_server:acceptor_...

An Erlang written in Ada?

Another thread had this quote Erlang VM BEAM and HiPE is written mostly in C. Linked-in drivers are written mostly in C. (They are plugged to VM and serves communication with outside world.) I've read some opinions that Ada's strong typing, modularity, run-time checking, parallel processing etc. etc. are better than tha...

Graduate Courses on Large Scale Web Applications

I recently came across Erlang, the programming language, and I've become interested in developing large scale real-time browser based web-applications. I'd like to know if there are any graduate courses, anywhere in the US, which will teach me about writing scalable web-aplications or something similar. ...

How to write a simple receive loop in Erlang

Let's suppose that I have 2 processes in Erlang, and each process has a receive loop running. I want to send a signal from ProcessB to ProcessA but ProcessA doesn't actually need to do anything with it. ProcessA only needs to know that ProcessB sent the message. Here's how I have it implemented currently: receive {message_...

Does using a lot of tail-recursion in Erlang slow it down?

I've been reading about Erlang lately and how tail-recursion is so heavily used, due to the difficulty of using iterative loops. Doesn't this high use of recursion slow it down, what with all the function calls and the effect they have on the stack? Or does the tail recursion negate most of this? ...

What is the IDE of choice for Erlang development?

I want to get into Erlang programming, specifically some yaws stuff. (Currently, I use Eclipse for Java development.) What is the IDE of choice for Erlang development? ...

In Erlang, when do I use ; or , or .?

I've been trying to learn Erlang and have been running into some problems with ending lines in functions and case statements. Namely, when do I use a semicolon, comma, or period inside my functions or case statements? I've gotten stuff to work, but I don't really understand why and was looking for a little more information. ...

How can I sanitize Erlang input?

I was playing around with the erlang shell today and noticed that I could do command injections, something like the following: io:get_chars("Cmd> ", 3). Cmd> Dud List=[3,4,5]. io:get_line("I just took over your shell!"). Is there a way to sanitize the get_chars function's input so this isn't possible? ...