15 Minutes of Fame

Holy cow!  I decided to check my Google Analytics account to see what the impact of my If You Like X You Might Like Perl.  I thought it might, maybe, double the visitors to this page.  I was quite wrong, here is how wrong:

Screen_shot_2010-10-17_at_12
So I started looking around at what drove this traffic.  It turns out that perlgeek posted my article to reddit.  When I followed the referring links I found a few interesting things.  Apparently the article is the 16th most controversial at the moment.  It is below whether ads are like reality, but above some insult against redit users, some act that played out in the war in Afghanistan, and the POTUS's policy on cannabis:

Screen_shot_2010-10-17_at_12
It is also 24th on top scoring links in the programming category, but there aren't any interesting juxtapositions so I'm not providing a screenshot.  Honestly, I find the whole thing so amusing that I don't mind that the link has received more negative votes than positive ones or that 4 of the 5 comments are either negative, useless, or both.  The fifth is asking if one of the other commenters actually read the article, which is really neither positive nor negative.

The Unity Model

I'm reading Parallel Programming Design:  A Foundation by Chandy and Misra for a master's class and am finding it very interesting.  The book covers the Unity Model as an approach towards parallel programming.  The language used to model solutions to a problem isn't meant to be directly implemented as a language (though it has been incarnated as PCN) but instead to be used as a model for implementing the solution in some other language.  It is a fun language and hopefully now that I don't have a presentation looming over my head I can explore it independently and post some example.

The language is broken up into several parts:

  1. Declare - used for declaring variables
  2. Always - used for defining functions
  3. Initially - used for initializing variables
  4. Assign - the main portion of the code

The reason why initialization doesn't happen in the main portion of the code is that there is no guarantee that it would happen when you would want or that it would only happen once.  In fact, the assignment section of the program has very weak promises.  It only guarantees that when the program is executing any given line that any other line will eventually be executed if the program is run forever.  Other than that it just randomly picks statements to execute. 

By the way, the book has been out of print for a while now, so it isn't the easiest to find for cheap and is impossible to find new.  I ordered it three times used from third parties before someone finally actually had it in stock and shipped it to me.

7 Languages in 7 Weeks in St. Louis

One of the guys at the Genome Center mentioned he wanted to get a 7 Languages in 7 Weeks group started in St. Louis to go through the languages.  I thought that was a neat idea, but I also realized it was very simple and may not require a group.

If you look at the list that Tate provides for Tate's book, he lists these languages:

  1. Ruby
  2. Io
  3. Scala
  4. Erlang
  5. Clojure
  6. Haskell
  7. Prolog

If you look at SLUUG's St. Louis Event Calendar you find that:

  1. Ruby - Meets 2nd Monday of the Month
  2. Io
  3. Scala
  4. Erlang - Is now dead due to lack if interest, but could be resurected (I know since I ran it :) )
  5. Clojure - Meets 4th Thursday of the month
  6. Haskell - Had its first social, maybe it can take off with meetings soon
  7. Prolog

 

Sadly, we don't have a Scala, Io, or Prolog group that I know.  However, I bet that we could get people to volunteer for such talks in Lambda Lounge.

As an addendum, if STLRUBY didn't want to do a session I'm sure St. Louis Perl Mongers would be willing to shift around their schedule to do a talk on dynamic typing and meta programming.

 

If You Like X, You Might Like Perl

Objective-C - You'd probably like Moose's concept of roles if you like categories.  Roles also provide the ability to require methods exist on classes so you could use them for interfaces too, but when you consume a role you can't guarantee it won't add functionality.

Clojure - If you were willing to play with Perl 6 you'd probably like the many of its lazy aspects.  The common example being binding an infinitely long fib sequence to a list (my @fib := 0,1,*+*...* ).  Perl 6 also supports multi-method dispatching and pattern matching.  I don't know about Clojure's pattern matching abilities, but I do know that Perl 6's is weaker than Erlang's, so be aware of that.

If you don't want to try Perl 6 you should look at the Higher Order Perl book.  It focuses on functional Perl and steals heavily from Lisp.  In fact, the author states very early on that of the 7 things that make Lisp different, Perl has 6.  It is available free online or from a book store.  The author is currently boycotting Amazon though, so while they sell it you may want to buy from someone else. 

Ruby - I haven't gotten around to learning Ruby.  For what it's worth, there are a lot of people I know that like both Ruby and Perl so I have to assume there are some good similarities.  If you are looking for method_missing it is called autoload.  Besides that, Moose::Exporter is great for making keywords for DSLs.  You can use Perl 5's prototypes, but that gets a little more complicated.  You can also use Devel::Declare if you just want to take the parser over altogether which, of course, is gets more complicated.

Feel free to add more in the comments or tell me where I'm wrong, I'll update the body of the post as the conversation goes along.

Perl 6 Talk - Sneak Peak

This week's post is late and a copout.  Instead of actually writing an article I'm posting the slides to the talk I'll be giving this Thursday.  I will be a speaker at Strange Loop 2010 in beautiful St. Louis, MO.  The talk will be about Perl 6 and will be predominantly geared towards people who do not know Perl 5 or Perl 6 but are interested in exploring new languages. My intent is to give people a brief history lesson and then show them enough neat features about the language that they'll want to go pick up more.  More info here.

If you have any comments, criticism or suggestions please don't hesitate to post them.  I would greatly appreciate it.

 

Perl 6: Exciting Method Invocation

Perl 6 provides many new and interesting approaches to method invocation.  New constructs in the language allow the developer to define how many matching methods are called, how they are called, as well as a few other things.

In Line Mutators

Perl 6 supports the idea of inline mutators.  In Perl 5 it isn't too uncommon to see code like this:

@array = sort @array

It is common enough in the Perl community to see "assign this mutated value back into the variable it came from" that Perl 6 gives a cleaner way.  The same code in Perl 6 could be written:

@array .= sort

The line above says to take @array, sort it, and put the values back in @array all in one fluid motion.  Of course, there is one motion that developers go through that is so common most probably don't think about it:

my SVG $svg_serializer = SVG.new;

Thankfully, .= can use used here to assign a value into $svg_serializer more cleanly:

my SVG $svg_serializer .= new;

Invoking Multiple Matched Methods

In Perl5 (and other languages) one often finds code litered with statements like this:

$foo->frobinicate() if $foo->can('frobinicate');

That gets old after a while.  Perl 6 solves this, and a few other problems, with a new approach to method calls that allows the developer to request 0 or 1, 1, 1 or more, or any number of methods be called at a time.  So, for example, the Perl6 equivalent of above is:

$foo.?frobinicate;

The above code will invoke the frobinicate method on $foo if one exists.  However, if no method exists that matches that criteria then nothing will be executed and instead of dying the statement simply returns Nil.

As I mentioned there are other options here also, for example if the developer wanted to execute all of the 'frobinicate's that existed within the inheritance hierarchy of $foo they could do either:

$foo.*frobinicate;

$foo.+frobinicate;

As readers can probably guess '.*' will invoke 0 or more methods named 'frobinicate' on $foo returning Nill if none exist.  That leaves '.+' to invoke 1 or more matching methods, the line dies if it finds no matching methods.

Here is an example of the above:

class Dog {

   method talk { 'bark' }

}

class TalkingDog is Dog {

   method talk { 'Hello' }

}

my TalkingDog $td .= new;

$td.talk # returns 'Hello'

$td.?talk # returns 'Hello'

$td.*talk # returns ('Hello', 'bark')

$td.+talk # also returns ('Hello', 'bark')

$td.*calculate_pi # returns Nil

$td.+calculate_pi # dies

$td.?calculate_pi # returns Nil

$td.calculate_pi # dies

Parallel Invokation

Perl 6 has an incredibly exciting new operator called the hyperoperator.  The hyperoperator indicates that the methods being invoked can be dispatched in parallel.  This makes simple cases of parallel execution very simple to do.  To do this, simply prepend '>>' between the object and the invocation operator.  For example:

@foo>>.frobinicate

This would invoke 'frobinicate' on all the elements in @foo in parallel.  

The hyperoperator can be combined with the previous topic of invoking all the methods that match.  This makes it very simple to invoke all of the possible methods on an object in parallel:

$foo>>.*frobinicate()

Here is a simple, but more fleshed out example to wrap things up:

class Department {

   has @.employees;

   has $.name;

   method gen_print_info { return "$.name:\n" ~"\t\t" ~ @.employees.sort.join(', ')}

}

my @company = (

   Department.new( name => 'Accounting', 'employees' => <Jeff Jane Susan>),

   Department.new( name => 'Security', employees => <Alice Bob>),

   Department.new( name => 'Marketing', employees => <Margaret Terry Lawrence>),

   Department.new( name => 'Development', employees => <Matt Fred Steve Joe Alith Jie>)

)

my @print_info = @company>>.gen_print_info;

The example above would execute gen_print_info on all of the Department typed objects in @company.

 

Further Reading

The Lacuna Expanse

Hey readers,

Have you looked at The Lacuna Expanse?  I'm afraid I just burned an hour of time playing it instead of doing other things.  It's a pretty neat MMO that combines strategy and SimCity in a fun game with a galactic theme.  I was surprised to see how well it is put together for being web based.  I'd really recommend checking it out.

If you aren't interested in the game then you might be interested in the tech behind it. The whole thing is written in Perl and uses a lot of fun tech.  Here is a slide deck.

Change in Format

I had a request that I not use gist.github to host the code snippets.  I guess it was a trouble for people who turned off JavaScript.  Since github does not currently support Perl 6 syntax highlighting I will inline my code snippets.  However, when github supports Perl 6 syntax highlighting I will probably go back to hosting on there.  If you have an opinion on this please let me know via email, the comments, or buying me a beer and saying what you think.