Syntactic sugar idea

On Thu, May 14, 2009 at 11:33 AM, Lars C.
[email protected] wrote:

as the default name for block parameters:

arr.sort_by { $.size }
File.open(“logfile”, “a”) { $
.puts logtext }
arr.map { foo2bar($_) }

Then I remember how people abuse it and avoid using appropriately
named variables, and I am again happy about the little extra code I
have to write.

Forget the $ and you are spelling out a thought I was bearing with me
for quite some time, ty Daniel and Joel to bring this up :).
I always wanted an implicit _ parameter in blocks, as e.g.
3.times do puts _ end


Si tu veux construire un bateau …
Ne rassemble pas des hommes pour aller chercher du bois, préparer des
outils, répartir les tâches, alléger le travail… mais enseigne aux
gens la nostalgie de l’infini de la mer.

If you want to build a ship, don’t herd people together to collect
wood and don’t assign them tasks and work, but rather teach them to
long for the endless immensity of the sea.

Mark T. wrote:

config “my window” do
.width calculate_width
.height @y
end

Now how does the parser know what .height refers to: calculate_width,
or the implicit block variable?

Yeah, seems impossible. Maybe if there were some other character instead
of “.” to signify sending a message to the block’s “default object”.

Daniel DeLorme wrote:

Gregory B. wrote:

On Thu, May 14, 2009 at 12:16 AM, Daniel DeLorme [email protected] wrote:

Well, you never know… Matz did add the Symbol#to_proc conversion in
1.9 and also the foo\n.bar “fluent interface” syntax. So apparently
trivial changes do make their way into core… sometimes.
But Symbol#to_proc is not a parser change. It’s just using an existing
hook that has been around in Ruby 1.8
But the fluent interface change is a parser change. My point was just
that seemingly trivial requests can make it into the core, whether
they’re a syntax change or not.

Was that fluent interface syntax really a request? I cannot remember
anyone asking for it. I do, however, vividly recall various petitions
to remove that change.

jwm

On May 13, 8:42 pm, Daniel DeLorme [email protected] wrote:

It seems that often an object will be passed into a block only to invoke
a method of that object:
arr.map{ |obj| obj.some_method }

So I had the (weird? stupid?) thought that it would be nice to have some
syntactic sugar like this:
arr.map{ .some_method }

require ‘enumerable/extra’

arr.map(:some_method)

Regards,

Dan

Mmm losing the $ would then render RSpec completely inoperable since
it has an it method.

–Jeremy

On Thu, May 14, 2009 at 9:46 AM, Robert D. [email protected]
wrote:


Antoine de Saint-Exupéry


http://jeremymcanally.com/
http://entp.com/

My books:

http://humblelittlerubybook.com/ (FREE!)

On May 14, 6:31 pm, Daniel B. [email protected] wrote:

require ‘enumerable/extra’

arr.map(:some_method)

Regards,

Dan

Cool! What would it take to make this 1.9 compatible?