« The coolest app you never knew was on your hard drive | Main | Adding Concurrency to Our Erlang Program »

April 16, 2007

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83451c41c69e200d8341d572d53ef

Listed below are links to weblogs that reference A First Erlang Program:

Comments

Ola Bini

Nice writeup, Dave.

I've always been fond of Erlang, and it's great that you're publishing this book. Looking forward to reading it.

Just a nitpick; regard the http:request call, you say that = is a pattern matching operator, but isn't it more true to say it's doing unification in the Prolog manner, than pattern matching?

Cheers

Dave Thomas

Ola:

Yes, I believe the two are similar, although Prolog takes it a lot further in terms of backtracking and the like.

I use the phrase "pattern matching" because that's what Joe uses :)

JEG2

At one point the article refers to ranks.rb, but I believe you meant ranks.erl. You also miscapitalize XPath as XPAth in one instance.

Good example though. Thanks for sharing!


Dave says: both fixed--thanks.

Giulio Piancastelli

There still an instance of ranks.rb in the last line before the listing of the whole Erlang program.

(Dave says: thanks--fixed)

I found quite thrilling that some behavior of Erlang is similar to Prolog. Less things to grasp for folks coming from a logic programming background like myself.

Shashy

Great article. I was working with CouchDb (http://couchdb.com) and a Ruby client yesterday. I'll try CouchDb and an Erlang client today for a full Erlang experience.

lninyo

just got my beta pdf. This a great short tutorial on Erlang. Thanks for publishing the Erlang book!

Ross

Dave - the sample code for the amazon_url_for function has a real SubscriptionId rather than the your_id placeholder. Did you mean to do this?

Dave says: sigh....

Tobbe

Nice writeup!
Just a few comments:

1. You don't need the '++' in the BASE_ULR macro. The compiler will concatenate successive strings automatically.

2. Regarding Unification, Erlang reguire that the right-hand-side of the pattern-match operation is fully bound. With Unification you may have Unbound variables on both sides, resulting in interesting effects... :-)

Cheers, Tobbe

g

The photo is Felix Klein, yes? Ho ho.

Tom

#xmlText{value=Rank} looks strange to me. Why is the unbound variable on the right?

Tobbe

Perhaps a bit confusing, but the record syntax is just some sugar for Erlang tuples, so this:

[ #xmlText{value=Rank} ] = xmerl_xpath:string("//SalesRank/text()", Xml),

actually mean something like this:

[{xmlText,_,Rank,_}] = xmerl_xpath:string("//SalesRank/text()", Xml),

I say something since I don't remember the correct number of elements in the xmlText tuple and which element that corresponds to the Rank value.
The record syntax helps you to focus on the important part though.

acechase

It's really great to hear a mainstream voice in the software industry touting the virtues of Erlang. I'm interested to see how this plays out as, just six months ago, I was discussing Erlang with one of the "visionaries of our field" and his response to the benefits of Erlang was that it is too foreign for the average developer to take hold of. I'm hoping that proves untrue, and I think a good introductory book is a good start towards that end.

One style note in regards to the example: Where you're matching only on the "ok" response from http:request(URL) and letting an "error" response generate a bad match, I think it is clearer to match on the error and then return it unmodified. This approach still fits with the fail early philosophy of Erlang, but it provides a more direct indication of what the error was, rather than the more opaque matching error.

alex

Ola, in typical use of terminology, unification is working in both directions, whereas pattern matching only tries to match lhs with rhs.

So unification would bind X to 1 and Y to 2 for {X, 1} = {2, Y}, whereas (pattern) matching would complain about an unbound Y on the rhs.

So that's why it is actually correct to say that Erlang's = is a pattern matching operator:

1> {X, 1} = {2, Y}.
** 1: variable 'Y' is unbound **

Ivan

As acechase wrote, this language looks very strange. For me as I'm an average developer has very ugly syntax and I think that mainstream stays untouched.

john

great article, it might have been better to use a free service as opposed to amazon so its easier for people to follow. I dont want to signup for an amazon key to test this code out. :(

Rafael de F. Ferreira

Excellent tutorial. I took the liberty of translating the code to Scala, I hope you don't mind. My translation is here: http://blogs.sun.com/rafaelferreira/entry/pragmatic_scala .

George

Erlang has beautiful syntax, to me at least.

cbmeeks

Very interesting read!

I am trying to learn Erlang at the moment and it's hard to find practical examples.

I hope to create an Amazon AWS library (S3, EC2, etc) in Erlang as an exercise in learning Erlang.

cbmeeks
http://codershangout.com

wasiq

thanks for a nice tutorial

i get the following error when try to execute

3> ranks:fetch_title_and_rank("0977616630").
** exception exit: {noproc,{gen_server,call,
[httpc_manager,
{request,{request,undefined,,0,http, {"webservices.amazon.com",80}, "/onca/xml", "?Service=AWSECommerceService&SubscriptionId=XXXXXXXXXXXXXXXXX&Operation=ItemLookup&ResponseGroup=SalesRank,Small&ItemId=0977616630",
get,
{http_request_h,undefined,"keep-alive",undefined,undefined,
undefined,undefined,undefined,undefined,undefined,...},
{[],[]},
{http_options,"HTTP/1.1",infinity,true,[],undefined,false},
"http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&SubscriptionId=1QKKA9Z4JR3MCE2DKZ02&Operation=ItemLookup&ResponseGroup=SalesRank,Small&ItemId=0977616630",
[],none,[]}},
infinity]}}
in function gen_server:call/3
in call from http:handle_request/6
in call from ranks:fetch_title_and_rank/1

Tom

You are missing an initial inets:start(). Just enter that once in your Erlang console before calling ranks:fetch....

The comments to this entry are closed.

Now in Beta

  • Programming Ruby, 3rd Edition
    Third Edition, Covering Ruby 1.9, now available
My Photo

Pragmatic Stuff

Photos

  • www.flickr.com
    This is a Flickr badge showing public photos from pragdave tagged with pragdave_badge. Make your own badge here.