From: Gavin Sinclair Date: 2002-09-05T10:25:12+09:00 Subject: Re: Ruby aesthetics > Gavin Sinclair wrote: > ... >> My frame-of-reference for good language design is Ruby. So compared >> to Ruby, I would add: >> - list comprehensions >> - calling procs would look like real functions, not arrays! >> e.g. id = proc { |x| x }; id(12) # not id[12] > > This bothered me a little, OUAT (once upon a time :), but not now. I > like being able to use procs and hashes interchangeably. This makes it > possible to think of a hash as a function in the sense of a set of > ordered pairs: > > succ_mod_3 = {0=>1, 1=>2, 2=>0} > succ_integer = proc {|x| x+1} > > def cycle(succ_map) > x = 0 > 10.times do > print x > x = succ_map[x] > end > end > > cycle succ_mod_3 # ==> 0120120120 > cycle succ_integer # ==> 0123456789 Hey, nice! I like that. Although using an iterator would be more Ruby-ish and flexible, wouldn't it? Besides, we've seen Perl and Python make a real hash of hashes (sorry...) > If you want to use procs and methods interchangeably, you have a little > more work, but not much--just apply #method. Correct, but (please excuse my possibly ignorance and definite inexperience) I think it's a bit messy. I just can't see the uniformity. It'll come in time... and in the meanwhile, it doesn't get in my way. Cheers, Gavin