Using _ like in Scala?

On Wed, Feb 8, 2012 at 9:57 AM, Robert K.
[email protected]wrote:

blocks,
block

and
So you are talking about an editor feature and not a language feature?
I am starting to get an idea of where I misunderstood you… :slight_smile:

Yes, what I want is an editor feature (it’s also a cognitive aid, even
without an editor to take advantage of it), but it requires a language
feature to enable.

On Wed, Feb 8, 2012 at 9:55 PM, Kevin [email protected] wrote:

Wouldn’t the general use case at issue here be addressed by adding
standalone versions of various functions traditionally associated with
collections so that one could call say reduce like “reduce myarray,
:+”?

I do not think it is a good idea as a general rule because that
totally breaks OO. And cluttering the global namespace with a ton of
methods which just delegate to instance methods with the same name
does not seem a good idea to me either.

As a general remark: we need to balance readability (which generally
benefits from making things explicit, but not too many things) and
writing efficiency (less text => more implicit).

Kind regards

robert

Ruby has Perl’s $_, but only in certain contexts:

$ echo “foo” | ruby -pe ‘next unless $_ =~ /(foo|bar|baz)/’
foo
$

For example. I’m not sure when it’s valid, as this perl-ism isn’t:

1.9.2p290 :001 > fruits = %w( apple banana orange )
=> [“apple”, “banana”, “orange”]
1.9.2p290 :002 > fruits.each { puts $_ }

=> [“apple”, “banana”, “orange”]

On Thu, Feb 9, 2012 at 1:39 AM, Josh C. [email protected] wrote:

Yes, what I want is an editor feature (it’s also a cognitive aid, even
without an editor to take advantage of it), but it requires a language
feature to enable.

OK, just trying to clarify. You wrote

Although what I’d really like would be a syntax for naming inline blocks,
then my editor could fold the block body inside the name, something like
%w[apple banana orange].each display

And it would expand to something like
%w[apple banana orange].each { |display → fruit| puts fruit }

Somehow I didn’t understand what you meant by “syntax for naming
inline blocks” because it did not occur to me that you might be
missing something we actually do have already:

irb(main):001:0> display = ->(x) { puts x }
=> #<Proc:0x201e80c8@(irb):1 (lambda)>
irb(main):002:0> %w[apple banana orange].each &display
apple
banana
orange
=> [“apple”, “banana”, “orange”]

Now, what is missing?

Kind regards

robert

On Thu, Feb 9, 2012 at 3:34 AM, Josh C. [email protected] wrote:

But I imagine any such language would be problematic because you could then
only edit it in IDEs that understood the data format. This “naming blocks”
seemed like a nice compromise that would enable any normal editor to
achieve similar abstractions, while enhancing readability, maintaining
plain text, and requiring almost nothing to change within the language.

Does TextMate have its own mechanism to name a folded block of code,
e.g. by providing the name in a comment? Maybe that would work for
you, although you’d have to place the block on multiple lines.

On Thu, Feb 9, 2012 at 2:42 AM, Robert K.
[email protected]wrote:

apple
banana
orange
=> [“apple”, “banana”, “orange”]

Now, what is missing?

Yeah, I gave that example in my first response, just before “But never
found anything I was very happy with” :slight_smile: It is pretty rare, though, to
encounter a situation where placing a lambda in a local var is less
clutter
than inlining it. As a general opinion, I find that I have an aversion
to
local variables, they make code harder to read, there are a lot of ways
to
get around them, hence the other alternative I showed (but also
ultimately
disliked) of placing the lambda in some other method.

Another thing I will frequently do is have the body of the block
delegate
to some method. That provides a nice abstraction like what I’m wanting,
but
it leads to lots of methods which clutter the class, making it again
less
readable (which in turn leads to more objects with more specific
responsibilities). What I suppose I really want is a language that is
not
in plain text, but stored in some sort of abstraction such that a method
only invoked in one place can be hidden from everywhere, but examined
and
altered at will. Like you only see some file if you’re in it’s
containing
directory, but when you’re in the directory, you can just look at it’s
name, and cat it to see its contents. Seeing some other method’s helper
methods is like seeing other directories’ files. Storing them in local
variables is like seeing the contents of all the files in your directory
every time you cd or ls. I would like the language itself to abstract
away
such things, hide that code away where I only see it if I explicitly
want
to.

But I imagine any such language would be problematic because you could
then
only edit it in IDEs that understood the data format. This “naming
blocks”
seemed like a nice compromise that would enable any normal editor to
achieve similar abstractions, while enhancing readability, maintaining
plain text, and requiring almost nothing to change within the language.

On Thu, Feb 9, 2012 at 2:37 PM, Eric C. <
[email protected]> wrote:

e.g. by providing the name in a comment? Maybe that would work for
you, although you’d have to place the block on multiple lines.

I am pretty sure I’d have to hack the syntax file. I probably would if I
were more competent. The biggest reason that doesn’t seem like a
solution
is that I work on a team with other people. Also, I use Vim about half
the
time.