Re:Show HN: Matches.js -- Powerful Pattern Matching for Java...
by danh on Thursday September 13, 2012 @03:37PM
(#4518110)
Something like this would make a great addition to CoffeeScript.
[ Parent
| on HN ]
Re:Show HN: Matches.js -- Powerful Pattern Matching for Java...
by natefaubion on Thursday September 13, 2012 @03:47PM
(#4518175)
It meshes pretty well as is. If only I could get rid of the strings and redundant arguments.
mymap = pattern {
'_, []' : -> []
'f, [x, xs...]' : (f, x, xs) ->
[f x].concat mymap(f, xs)
}
It shares a lot of the same splat/rest/destructuring syntax.
Re:Show HN: Matches.js -- Powerful Pattern Matching for Java...
by oscilloscope on Thursday September 13, 2012 @04:57PM
(#4518564)
Check out LiveScript's implicit switch syntax:
Re:Show HN: Matches.js -- Powerful Pattern Matching for Java...
by natefaubion on Thursday September 13, 2012 @05:11PM
(#4518646)
That's along similar lines, but more like guards in Haskell:
http://en.wikibooks.org/wiki/Haskell/Control_structures
Re:Show HN: Matches.js -- Powerful Pattern Matching for Java...
by ble on Thursday September 13, 2012 @09:34PM
(#4519586)
Last I heard, jashkenas was not a fan of adding such.
"... [P]attern matching inspired by static languages is a particularly poor fit for JavaScript (and by extension CoffeeScript), because types are extremely weak in JS." -jashkenas [1]
"[... P]attern matching is not nearly as useful in a language without rich types [...]" - jashkenas [2]
I'm on that reddit thread, respectfully disagreeing with him.
[1]: https://github.com/jashkenas/coffee-script/issues/1419#issue...
[2]: http://www.reddit.com/r/programming/comments/er0qj/coffeescr...