News for hackers. Stuff that matters.
Re:The death of if/else cascades, a lightweight alternative by daleharvey on Sunday December 06, 2009 @03:18PM (#980094)
the problem with pattern matching is that its hard to dynamically change the dispatch table, in javascript I can just do

  dispatch_table[newthing].handler = function() .....
Re:The death of if/else cascades, a lightweight alternative by silentbicycle on Sunday December 06, 2009 @03:33PM (#980115)
You can change the clause database in Prolog by asserta/assertz/retract, but that runs headfirst into the typical trade-offs involving mutable state, as does your Javascript example. Erlang also lets you change patterns by hot-loading code, but its design goes to great pains to do so with reasonable safety.

Also, pattern matching doesn't require all of the variables to be bound. A pattern may specify some values but just partially specify (a list with at least one remaining value) or constrain (any positive integer) others. This makes it vastly more flexible than just dispatching based on one value.

Re:The death of if/else cascades, a lightweight alternative by daleharvey on Sunday December 06, 2009 @05:07PM (#980232)
certainly, I am an erlang programmer and do love pattern matching, but as much as I pretend to hate javascript, I do love that modules/namespaces whatever are a first class citizen in a way they certainly arent with erlang, (they are at the vm level, but not so much the language, smerl is quite handy for that).

I should probably play with match specs more often

Re:The death of if/else cascades, a lightweight alternative by DougBTX on Sunday December 06, 2009 @06:08PM (#980318)
Which, if we were to take this example seriously, would be very important, since these rules would likely be user specified.
Re:The death of if/else cascades, a lightweight alternative by xtho on Monday December 07, 2009 @12:17AM (#980763)
How should a function be "user" specified? (But which user?) The set of eligible options is well defined at the time of writing the program.
Re:The death of if/else cascades, a lightweight alternative by wlievens on Tuesday December 08, 2009 @06:43AM (#983508)
But the way they are composed, and where and when they apply, is most likely not!