It's a lot more legible than getting into all the Snoopy talk (@#$%).
This is way OT, but I can't actually remember Snoopy ever swearing. Yet
it gets mentioned frequently (even in the pick-axe). Has the ruby
community collectively hallucinated it? Or did ruby programmers grow up
in a parallel universe with R rated daily comics?
···
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
That's how Snoopy's speech was depicted in the cartoons (not the comic strips).
···
On 4/19/06, Joel VanderWerf <vjoel@path.berkeley.edu> wrote:
John Johnson wrote:
> It's a lot more legible than getting into all the Snoopy talk (@#$%).
This is way OT, but I can't actually remember Snoopy ever swearing. Yet
it gets mentioned frequently (even in the pick-axe). Has the ruby
community collectively hallucinated it? Or did ruby programmers grow up
in a parallel universe with R rated daily comics?
select could return a functor --in this case an enumerator:
all_people.select.retired?
And in fact I believe this functionality is in 1.9 already. It works
with all enumeratable methods and methods of classes that serve the
same purpose. I think it could be further generalized though for any
method accepting a block. For:
def foo(&blk)
then
foo.bar
translates into
foo { |x| x.bar }
(It may require the ability to sepcify manditory blocks though, like I
brought up in another recent thread)
It's a lot more legible than getting into all the Snoopy talk (@#$%).
I agree. I don't see the problem with it.
I agree that it's fine, but:
a) It can be expressed with a shorter code snippet (less line noise),
therefore making it easy to do method-chaining.
"&:>" and such, I would argue, are shorter but have *more* line noise
than the equivalent explicit blocks.
b) I implicitly understand that it is an array of numbers, so the idea
of "a number" repeats itself three times (you had to write 'n' twice).
a better example might be:
all_people.select { |person| person.retired? }
The subject of this operation is expressed twice more than it ought to
be.
Therefore,
[1,2,3].all?(:>, 0)
and
all_people.select(:retired?)
I always think of these things partly in terms of explanation. In
order to explain all_people.select(:retired?), one would either have
to present :retired? as a "magic" way of filtering for retiredness, or
explain that it's actually {|p| p.retired? } in disguise. Somehow it
doesn't work as, so to speak, a primary, transparent technique.
"Why is there a colon?" Because it's a symbol. "So a symbol invokes
the method of that name?" No.
On 4/19/06, Joel VanderWerf <vjoel@path.berkeley.edu> wrote:
John Johnson wrote:
It's a lot more legible than getting into all the Snoopy talk (@#$%).
This is way OT, but I can't actually remember Snoopy ever swearing. Yet
it gets mentioned frequently (even in the pick-axe). Has the ruby
community collectively hallucinated it? Or did ruby programmers grow up
in a parallel universe with R rated daily comics?
That's how Snoopy's speech was depicted in the cartoons (not the comic strips).
Ah... the parallel universe of television
Thanks for clearing that up for me.
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
Interesting but too radical. I'm afraid that it's too hard to imagine
>> foo { |x| x.bar }
when I see
>> foo.bar
I can see that on first econounter the idea, certainly. And I think the
same is true when enumerable method returns an enumerator. It's
something that requires getting usedto. I'm more accustom to it myself
becuase I have used "Functor pattern" enough. If I may suggest, at
least make a note to reconsider it in the future. I think as the
enumerator functionality becomes more common, this will not seem so
radical.
And actually if you look at it less abstract terms it doesn't seem
quite as radical either:
[1,2,3].collect.to_s
["A3","B2","C1"].sort_by[1,1]
'pretty little ponies'.gsub(/[^aeiou]/).upcase
T.
···
In message "Re: Symbol#to_proc is just so beautiful" > on Sat, 1 Jul 2006 16:56:15 +0900, transfire@gmail.com writes:
In message "Re: Symbol#to_proc is just so beautiful" on Sun, 2 Jul 2006 00:34:22 +0900, transfire@gmail.com writes:
And actually if you look at it less abstract terms it doesn't seem
quite as radical either:
[1,2,3].collect.to_s
This means 'print([1,2,3].collect)' would not work, since it calls
to_s for string conversion, but to_s gives it an array of strings.
In any case, I feel like it requires special notation (for partial
evaluation), even if we really need it.
Interesting but too radical. I'm afraid that it's too hard to imagine
>> foo { |x| x.bar }
when I see
>> foo.bar
I can see that on first econounter the idea, certainly. And I think the
same is true when enumerable method returns an enumerator.
Definitely. I find this:
array.map.upcase
(if I'm getting the magic enumerator thing right) pretty obscure. I
mean, the words on the screen more or less describe what's happening,
but the dot syntax feels to me like it's being pushed beyond the
limits of usefulness.
David
···
On Sun, 2 Jul 2006, transfire@gmail.com wrote:
In message "Re: Symbol#to_proc is just so beautiful" >> on Sat, 1 Jul 2006 16:56:15 +0900, transfire@gmail.com writes:
>And actually if you look at it less abstract terms it doesn't seem
>quite as radical either:
>
> [1,2,3].collect.to_s
This means 'print([1,2,3].collect)' would not work, since it calls
to_s for string conversion, but to_s gives it an array of strings.
Why should it? If the block is manditory then it won't work anyway.
This is what I was saying about this notation needing a way to specify
manditory blocks in order to work. It cannot apply to optional blocks.
(Which reminds me I got bit by optional blocks yesterday when I forgt
to put .each :/)
In any case, I feel like it requires special notation (for partial
evaluation), even if we really need it.
Well, "need" is pretty relative. It's more a question of want I think.
How much do we want a consice notation like this? After all a special
notation might ruin it's readiabilty, which is it's main advantage.
Anyhow, it's certainly not pressing. But I have a hunch the idiom will
gain more acceptance over time.
Thanks,
T.
···
In message "Re: Symbol#to_proc is just so beautiful" > on Sun, 2 Jul 2006 00:34:22 +0900, transfire@gmail.com writes:
This means 'print([1,2,3].collect)' would not work, since it calls
to_s for string conversion, but to_s gives it an array of strings.
Why should it? If the block is manditory then it won't work anyway.
This is what I was saying about this notation needing a way to specify
manditory blocks in order to work. It cannot apply to optional blocks.
(Which reminds me I got bit by optional blocks yesterday when I forgt
to put .each :/)
In any case, I feel like it requires special notation (for partial
evaluation), even if we really need it.
Well, "need" is pretty relative. It's more a question of want I think.
How much do we want a consice notation like this? After all a special
notation might ruin it's readiabilty, which is it's main advantage.
"need" is pretty relative indeed. And I'm a big fan of concise
notation in general. But still I don't think this is a good idea
(without special notation). Iterating method calls (like to_s in
above example), should be distinguishable from usual method calls,
because they are different, they act different, their implementations
are different.
Besides that you need to have knowledge of whether #collect requires
mandatory block or not to tell how obj.collect.to_s works. Note that #collect may or may not have mandatory block depends on its receiver.
matz.
···
In message "Re: Symbol#to_proc is just so beautiful" on Sun, 2 Jul 2006 01:05:42 +0900, transfire@gmail.com writes: