3 ms·
This pretty well describes my problems with JavaScript. We have first-class functions, but they are horribly crippled by the lack of tail-call optimization, im
by davexunit 13y ago
This pretty well describes my problems with JavaScript. We have first-class functions, but they are horribly crippled by the lack of tail-call optimization, immutable data structures (I don't want to mutate an array in order to implement map), and lack of arity checking.
Alos, does anyone else get annoyed that operators aren't functions? I would love to write `_.reduce([1, 2, 3, 4], +, 0);` but instead I have to implement a sum function first. There's all sorts of little issues like this that make JavaScript a pain to work with.
- saraid216 13y ago> I don't want to mutate an array in order to implement map Er, what? > foo = [1, 2, 3] [1, 2, 3] > foo.map(function(i) { return i + 1; }) [2, 3, 4] > foo [1, 2, 3]
- davexunit 13y agoThat's _using_ map. Read an implementation of map to see what I mean.
- i_s 13y agoThat is using map, not implementing map. Implementing map: function map(f, ary) { var ret = []; for(var i = 0; i < ary.length; i+= 1) { ret.push(f(ary[i])); } return ret; } Though that is not a good example by the op, because that is what you do: https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L2556-#L2557 https://github.com/clojure/clojure/blob/master/src/clj/cloju...
- deleted 13y ago[deleted]
- gotofritz 13y agoI would do it like this... function map(f, ary) { return [].map.call(ary, f); }