From: Jamie W. <j...@jm...> - 2004-02-03 22:30:00
|
On Monday 02 February 2004 10:29, Reuben Thomas wrote: > > Naming: yeah, dunno. Arity: I decided it made sense only for commutative > > operators to be variadic. > > Whereas in e.g. APL they all are, and you get alternating differences with > -. I'm not sure what's worse: providing variadic / (what is that for?) or > not providing it (why doesn't my code work suddenly when I replace + with > /?). How about: ["/"] = function(a,b,c) assert(c == nil, "/ is binary only") return a/b end At least you get a meaningful error that way. > Seems a bit contrived. If you wanted those that had attribute foo < 4, > you'd still need to make a function. small = std.filter(std.compose(std.bind(std.op[">"], 4), std.getter("foo")), objects) Seriously though, I realise it's not very general, but I have found it useful. I suppose it just depends on how large you want the library to end up. > > Say I want to call method swizzle(5) on each of a list of (maybe > > polymorphic) objects: > > > > results = std.map(std.method("swizzle", 5), objects) > > And again, that only works with constant values. If you wanted to call > swizzle(self.foo+self.bar), again, you'd need a function. method() is to methods what bind() is to functions (bind_method() lies somewhere in the middle). I don't see how you can claim that one is useful but not the other. Personally, I use them both about equally, and from my libary use only map() more frequently. If I wanted self.foo+self.bar, then yes, I'd probably write a function (or make a swizzle_foo_bar() method). But in general where the values are not constant: results = std.map(std.method("swizzle"), objects, params) -- Jamie Webb |