From: Ben Tilly Date: 2000-12-16T03:55:32+09:00 Subject: [ruby-talk:7340] Re: Why isn't Perl highly orthogonal? David Alan Black wrote: > >Hello -- > >On Fri, 15 Dec 2000, Ben Tilly wrote: > > > David Alan Black wrote: > > >I'm not sure what it is you're saying wouldn't work. For example: > > > > > >a = [1,2,3,4,5] > > >b = a.map do |e| [e,-e] end > > >c = b.map_with_indices do |e,i| "element #{i} is #{e.inspect}" end > > > > > >p c[2] # => "element 2 is [3, -3]" > > > > I was thinking of the following: > > > > a = [1, [], [3,4,[]]] > > > > Pass that to flatten and you will get [1,3,4]. which is > > likely not what someone with that data structure intended > > to do! > >Right. But who's passing anything to flatten? Hmmm.... Maybe you're >still thinking of my original example? But even there, the flattening >affects only the result array, not the input array: I was talking about your hack to have a map return multiple values, map to anon arrays then flatten. That hack will not work on all data structures because flatten is recursive. Your original map_with_indices didn't have that problem. >[1, [], [3,4,[]]] .map do |e| [e.inspect, "hello"] end .flatten > > => ["1", "hello", "[]", "hello", "[3, 4, []]", "hello"] > >The flattening was just to show that you can get more elements out >than you put in, which I think was what you originally said you'd had >trouble with. If you don't flatten (which is fine with me -- really! >I don't mind! :-) then you get an array of arrays -- which may be what >one wants in a given case, but would not have made the point. I had trouble doing a straight map which returned more. When you flatten or push, that is behaviour I understand. Some context. In current production versions of Perl: %some_hash = map {($_, 1)} @some_array; is slow even though push is fast. I was trying to test that in Ruby. But since that idiom is not supported directly, there was nothing to test. >And (just to clarify) my map_with_indices method doesn't flatten >anything. It just, umm, maps with indices: > I knew that. I was talking about your map then flatten trick to map an array of one size to one of different size. [...] > > I don't have enough of a sense yet to even try to say what > > Ruby-esque behaviour should be. Sorry. > >Don't apologize :-) I just meant that it seemed to me that a,b could >behave in iterator blocks as it does in method definitions -- i.e., >that the a,b syntax per se did not have to introduce ambiguities or >imply unexpected list behavior. My characterization of it in terms of >Ruby-esque-ness was really just referring back to your earlier >statement: > > I don't think that Ruby is list-oriented or that list-oriented ways > of thinking are a good fit for it. Having lists with variable numbers > of arguments is not part of the basic design and I don't think should > be hacked on top when it doesn't fit conceptually. > >Now, come on Ben, admit it -- there's just a *little* bit of >willingness to say what is and is not Ruby-esque creeping in around >the edges, isn't there? :-) > Willingness does not equal ability. I was putting out a guess based on an impression. The fact that you (with more experience) didn't think my impression was obvious suggests that I am missing something. Cheers, Ben _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com