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 (@#$%).
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).
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.
[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.
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:
In message “Re: Symbol#to_proc is just so beautiful”
on Sun, 2 Jul 2006 00:34:22 +0900, [email protected] 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.
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.
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.
“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.
Okay. Though we should consider that it can already be done, and
similar code is already being done in limited cases. Just as an example
here’s how collect could be defined.
alias :old_collect, :collect
def collect( &yld )
if yld
old_collect( &yld )
else
Functor.new { |op, x| x.send(op) }
end
end
But even so, say a special notaion were the best option. What kind of
notations do we have left? Everything starts to seem so perlish. I
don’t know. Maybe ‘->’ could play a role here?