some suggestions for ruby:
- list comprehension
{ |x<-0…n| x*2 }
{ |n, x<-0…n, y<-0…x| [x,y] }
Why not do this another way?
(0…5).collect { |x| x * 2 }
[0, 2, 4, 6, 8]
The second one would be mildly harder:
(0…5).collect { |x| (0…x).collect { |y| [x, y] } }
[[[0, 0]], [[1, 0], [1, 1]], [[2, 0], [2, 1], [2, 2]], [[3, 0], [3,
1], [3, 2], [3, 3]], [[4, 0], [4, 1], [4, 2], [4, 3], [4, 4]]]
That is, if I understand your second one.
Obviously, I’m using n = 5.
- default argument name to block/method
map {2} list # same as map {|x| x2} list
map {.lc} list # same as map {|x| x.lc} list
def x2 => _2 # def x2(x); x2; end
I’m afraid that I don’t see the point of these, except obfuscation.
All you’ve done here is replace ‘|x| x’ with ‘_’, and that does
nothing to help readability, IMO.
-austin
– Austin Ziegler, austin@halostatue.ca on 2002.11.25 at 11.53.13
···
On Mon, 25 Nov 2002 15:32:38 +0900, Bulat Ziganshin wrote: