Anything disappearing from Ruby for 2.0?

The English equivalents are a good lookup guide as to what on earth
the snoopy-swearing variables mean :slight_smile:

Gavin

···

On Monday, December 1, 2003, 3:29:00 PM, David wrote:

[…]

Matz pointed out that he also wants to remove the "require “English”’
equivalents.

This one I agree. Nobody in the world seems to use ‘require “English”’
in Ruby or ‘use English’ in Perl. Those using $_, $/, etc will use them
in the short form. Those hating them will not use them anyway, not even
the pretty English names.

Hi,

···

In message “Re: anything disappearing from Ruby for 2.0?” on 03/12/01, Carlos angus@quovadis.com.ar writes:

Hi :slight_smile: Here’s another idea:

  1. Make #… a method (Integer#… creates ranges, for example)

  2. Make a shortcut to proc {…} (maybe “&{”? Anything, I don’t know)

  3. Define Proc#… to work as a flip-flop

  4. while &{ line =~ /abc/ }…&{ line =~ /def/ }

Not as easy as before, but almost…

What do you think?

I like the basic idea. the “shortcut notation” would be a key. I
couldn’t think of a good one for years. But someone might be able to.

						matz.

Hi!

  • David Garamond; 2003-12-01, 12:43 UTC:

Josef ‘Jupp’ SCHUGT wrote:

I cannot see anything that requires one-liners besides showing
off. They are not even fun in most cases.

I find the ability to write one-liners amazingly useful. Perhaps
you don’t use shell/command-line interface much.

If propose one-lines you possibly did not yet discover the true
strength of using a CLI. A few years ago I would have supported your
statement. But then I started to use shell multiliners during
interactive sessions.

But many, many Unix/Linux users do most of their stuffs in shell
daily. And using a combination of Unix commands sometimes are just
not powerful/easy/portable enough. I use Perl & Ruby one-liners
for all things, from renaming a bunch of files according to some
string/regex operation (e.g. changing all “.tar.gz” to “.tgz”),

That can easily be done using the following (KSH, Bash should do as
well) three-liner:

for i in *.tar.gz; do
mv $i ${i%.tar.gz}.tgz
done

One way of achieving the same in Ruby is the following five-liner:

ruby <<EOF
%x(ls *.tar.gz).each { |x|
x.chomp!
%x(mv #{x} #{x.sub(/.tar.gz$/, ‘.tgz’)})
}
EOF

You could also use ‘echo’ in place of ‘ls’ but then you would have to
replace ‘each’ by ‘split.each’. Of course You can also do the same in
100% Ruby but I don’t see why I should use a scripting language if
the shell allows me to do it more easily so I didn’t take the time
for getting rid of ls and mv.

Btw, I even have a text file where I store hundreds of Perl & Ruby
one-liners which I can just copy paste to the shell window whenever
I needs them. It beats having hundreds of script files which I
don’t know how to name properly.

The same works for multiliners as well.

I don’t see why to make everything fit into one line if there is no
necessity for it.

Josef ‘Jupp’ Schugt

Hi,

···

At Mon, 1 Dec 2003 23:36:25 +0900, Carlos wrote:

Hi :slight_smile: Here’s another idea:

  1. Make #… a method (Integer#… creates ranges, for example)

  2. Make a shortcut to proc {…} (maybe “&{”? Anything, I don’t know)

  3. Define Proc#… to work as a flip-flop

  4. while &{ line =~ /abc/ }…&{ line =~ /def/ }

This needs a hidden flip-flop variable, otherwise matching
/abc/ will be performed each time.

Of course, you can do it like this, but, hmmmm…

(&{ line =~ /abc/ }…&{ line =~ /def/ }).while do
# …
end


Nobu Nakada

type prac.rb
p ARGV
puts
p $*

ruby prac.rb foo bar baz bonf
[“foo”, “bar”, “baz”, “bonf”]

[“foo”, “bar”, “baz”, “bonf”]

Hi,

···

In message “Re: anything disappearing from Ruby for 2.0?” on 03/11/30, “T. Onoma” transami@runbox.com writes:

It will not be changed. Ruby will remain being Ruby even after Ruby2.
Perhaps some next generation language would have constructs for each
role.

You pegged me wrong Matz! It is not that I want them to, per se. I was just
pointing it out.

I meant “if someone (not only you, Tom) want to change, wait for (or
create your own) next generation language.”

						matz.

Dan Doel wrote:

Isn’t the problem with “…” that it’s matching implicitly against Perl
style variables?

In the “/foo/ … /bar/” case, yes, but that’s because /xxx/ does, not “…”.

You could just as easily:

while (line = $stdin.gets)

do_something_useful(line) if (line =~ /foo/ .. line =~ /bar/)
# other magic happens here

here_is_something_else(some_other_var, 2)
   while (some_message(n) .. another_message(x))

end

Nothing perly there. What Matz is proposing (if I read it right, and I
might not have) is to remove the ability to use … as a scalar flip-flop
as a boolean. (Or did I misread that?)

how about extending readlines and defining an IO# method:

class IO
def readlines range = nil

end
def fixnum_or_range_of_fixnum_or_regexp

end
end

lines = IO.readlines /abc/ … /def/

open(path) do |f|
lines = f[ /abc/ … /def/ ]
end

# could also work as a ‘seek and read’ type operator.

record = f[offset, length]

-a

···

On Mon, 1 Dec 2003, Yukihiro Matsumoto wrote:

Date: Mon, 1 Dec 2003 23:49:32 +0900
From: Yukihiro Matsumoto matz@ruby-lang.org
Newsgroups: comp.lang.ruby
Subject: Re: anything disappearing from Ruby for 2.0?

Hi,

In message “Re: anything disappearing from Ruby for 2.0?” > on 03/12/01, Carlos angus@quovadis.com.ar writes:

Hi :slight_smile: Here’s another idea:

  1. Make #… a method (Integer#… creates ranges, for example)

  2. Make a shortcut to proc {…} (maybe “&{”? Anything, I don’t know)

  3. Define Proc#… to work as a flip-flop

  4. while &{ line =~ /abc/ }…&{ line =~ /def/ }

Not as easy as before, but almost…

What do you think?

I like the basic idea. the “shortcut notation” would be a key. I
couldn’t think of a good one for years. But someone might be able to.

  					matz.

ATTN: please update your address books with address below!

===============================================================================

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
STP :: Solar-Terrestrial Physics Data | NCEI
NGDC :: http://www.ngdc.noaa.gov/
NESDIS :: http://www.nesdis.noaa.gov/
NOAA :: http://www.noaa.gov/
US DOC :: http://www.commerce.gov/

The difference between art and science is that science is what we
understand well enough to explain to a computer.
Art is everything else.
– Donald Knuth, “Discover”

/bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’
===============================================================================

If I understand correctly,

In ruby-core:1792, Mathieu Bouchard hints at:

{ || … } -or- { |*| … }

Could something like that work? Or would it be too ambiguious with blocks?

def pshooter(a)
a.call
yield if block_given?
end

pcatch( {|| puts “p” } ) { puts “block” }

#> p
#> block

BTW: why does this happen?

a = proc { puts “p” }
pshooter a # => p
pshooter a { puts “block” }

=> undefined method `a’ for main:Object (NoMethodError)

T

···

On Monday 01 December 2003 03:49 pm, Yukihiro Matsumoto wrote:

I like the basic idea. the “shortcut notation” would be a key. I
couldn’t think of a good one for years. But someone might be able to.

{…} perhaps, by analogy with Haskell’s \ for lambda.

martin

···

Yukihiro Matsumoto matz@ruby-lang.org wrote:

I like the basic idea. the “shortcut notation” would be a key. I
couldn’t think of a good one for years. But someone might be able to.

for i in *.tar.gz; do
mv $i ${i%.tar.gz}.tgz
done

One way of achieving the same in Ruby is the following five-liner:

ruby <<EOF
%x(ls *.tar.gz).each { |x|
x.chomp!
%x(mv #{x} #{x.sub(/.tar.gz$/, ‘.tgz’)})
}
EOF

Your shell solution is nice. My Ruby would have been:

ruby -e “ARGV.each{|f| mv #{f} #{f.sub(/\.tar\.gz$/,'.tgz')}}” *.tar.gz

…or, less likely (but perhaps on Windows):

ruby -rftools -e “ARGV.each{|f| File.mv(f, f.sub(/.tar.gz$/,‘.tgz’))}” *.tar.gz

You could also use ‘echo’ in place of ‘ls’ but then you would have to
replace ‘each’ by ‘split.each’. Of course You can also do the same in
100% Ruby but I don’t see why I should use a scripting language if
the shell allows me to do it more easily so I didn’t take the time
for getting rid of ls and mv.

You seem to be saying if it can be done interactively using shell
commands, then good. But if it can be done easily in Ruby in a
one-liner, then bad.

But I like both. I’m an avid fan of Un*x shell commands… Many
of my Ruby one-liners are strung together in pipes between the
likes of find and grep, etc.

But I’ve found Ruby & Perl’s “one-lining” ability very freeing.
What used to make my brain explode in corruscations of cut and
sort and awk and sed, I can now often approach more simply [to me]
in Perl or Ruby. I’d prefer Ruby.

. . . For instance, I wanted to find out which entities were used
in a group of HTML files, and how many times each entity occurred.
(Like, – is used twice, — isn’t used at all, á
appears 7 times, etc…)

In Ruby, I just wrote:

ruby -ne “h||=Hash.new(0); scan(/&#?\w+;/){|e| h[e]+=1}; END{p h}” *.html

…Cool! Problem solved!

…Now I suppose there might be some way to get a comparable result
with sed & sort & grep, maybe, … I’m not sure, though. Whatever it is,
I suspect it would be annoying, compared to the Ruby. :slight_smile:

Regards,

Bill

···

From: “Josef ‘Jupp’ SCHUGT” jupp@gmx.de

“Josef ‘Jupp’ SCHUGT” jupp@gmx.de writes:

for i in *.tar.gz; do
mv $i ${i%.tar.gz}.tgz
done

Even better, just use mmv:

mmv “*.tar.gz” “#1.tgz”

···


Josh Huber

Josef ‘Jupp’ SCHUGT wrote:

The same works for multiliners as well.

I don’t see why to make everything fit into one line if there is no
necessity for it.

Many of my “one-liners” actually span several physical lines :slight_smile: (Too
bad CMD.EXE doesn’t seem to allow newline characters in one command
line, or does it?).

···


dave

  1. while &{ line =~ /abc/ }…&{ line =~ /def/ }

This needs a hidden flip-flop variable, otherwise matching
/abc/ will be performed each time.

Yes, because a new Proc is created every time. I didn’t notice that :(. I
should have thought, if proc{…}==Proc.new{…}, that would be the
case :). Sorry.

Of course, you can do it like this, but, hmmmm…

(&{ line =~ /abc/ }…&{ line =~ /def/ }).while do
# …
end

And also, the flip-flop is mostly used with “if” inside an external loop.
I think, if we want to keep this useful construction, must find another
way…

Okay, just wanted to be clear on where I stood on that.

Thanks,
-t0

···

On Sunday 30 November 2003 02:18 pm, Yukihiro Matsumoto wrote:

Hi,

In message “Re: anything disappearing from Ruby for 2.0?” > > on 03/11/30, “T. Onoma” transami@runbox.com writes:

It will not be changed. Ruby will remain being Ruby even after Ruby2.
Perhaps some next generation language would have constructs for each
role.

You pegged me wrong Matz! It is not that I want them to, per se. I was
just pointing it out.

I meant “if someone (not only you, Tom) want to change, wait for (or
create your own) next generation language.”

BTW: why does this happen?

a = proc { puts “p” }
pshooter a # => p
pshooter a { puts “block” }

=> undefined method `a’ for main:Object (NoMethodError)

The block associates with ‘a’: pshooter(a { puts “block”}), so ruby
interprets ‘a’ as a method. In this case you should use do … end, it is
more “loose”.

Martin DeMello wrote:

I like the basic idea. the “shortcut notation” would be a key. I
couldn’t think of a good one for years. But someone might be able to.

{…} perhaps, by analogy with Haskell’s \ for lambda.

Backslash is always problematic since it’s used as an escape.

I really like the &{…} idea, for the following reasons:

  1. It’s parallel in some sense to the &block notation, much as
  • can be used on formal or actual parameters.
  1. & is already a recognized operator (token).

  2. There’s no unary & in use yet except &block.

But maybe there is a good reason this should not be used?

Another note: I assume it would work with do/end also:

myproc = & do blah; blah end

which I might even write as

myproc = &do blah; blah end

Hal

···

Yukihiro Matsumoto matz@ruby-lang.org wrote:

how about the ML-way:

alias fn lambda

fn{…}

Regards,

Michael

···

On Tue, Dec 02, 2003 at 06:17:09AM +0900, Martin DeMello wrote:

Yukihiro Matsumoto matz@ruby-lang.org wrote:

I like the basic idea. the “shortcut notation” would be a key. I
couldn’t think of a good one for years. But someone might be able to.

{…} perhaps, by analogy with Haskell’s \ for lambda.

“David Garamond” lists@zara.6.isreserved.com schrieb im Newsbeitrag
news:3FCC69F6.2090501@zara.6.isreserved.com

Josef ‘Jupp’ SCHUGT wrote:

The same works for multiliners as well.

I don’t see why to make everything fit into one line if there is no
necessity for it.

Many of my “one-liners” actually span several physical lines :slight_smile: (Too
bad CMD.EXE doesn’t seem to allow newline characters in one command
line, or does it?).

It does - just the escape character is a bit different. But you didn’t
seriously expect it to be "" on a MS system, did you? :wink:

File foo.bat:
echo ^
test ^
case

This outputs “test case”.

Cheers

robert

From what I understand, the problem with the above shorthand for procs is
this:

def a(x=nil)
x.call if a(‘call’)
yield(‘block’) if block_given?
end

a {|z| puts “which? #{z}”}

It occured to me today that it’s rather odd that blocks can be passed to any
method whether the method uses the block or not. --a method need not
explictly state it takes a block, as it does with everyhting else. It really
is odd if you think about it. What if you could do that with any argument?
Imagine having arguments always passed in to a special keyword, args, and
using parameters_given? :slight_smile: LoL! Cracks me up! I guess I shouldn’t laugh too
much though. In fact having a keyword like args anyway could cetainly be
useful (since we can always count on the name). Imagine:

def a(*)
puts args.join(', ')
end

Well, I suppose it’s a little too late to rethink explict acceptance of block
parameters now. So then. Is there any other way to resolve the above problem?
Short of a YAP (Yet Another Perlism), the general census hasn’t been able to
provded one. But there is one possibility which, seems to me, might actually
work just fine: let blocks take precedence over lambda parameters. A clsely
related concern is already an appearent consideration given the binding rules
the differentiate {…} and do…end. And it makes sense since you can always
unambiguate it with parenthesis when need be:

a( {|z| puts “which? #{z}”} )

It wouldn’t break old code either since currently the keyword method proc or
lambda is used in the cases in which it otherwise could, eg.

a proc { |z| … }

So if we want a shorthand for lambdas, the already used concise notation of
{ || … } in fact does offer a good solution, and weighs in to stave-off Yet
Another Perlism.

T.

···

On Monday 01 December 2003 05:03 pm, T. Onoma wrote:

On Monday 01 December 2003 03:49 pm, Yukihiro Matsumoto wrote:

I like the basic idea. the “shortcut notation” would be a key. I
couldn’t think of a good one for years. But someone might be able to.

If I understand correctly,

In ruby-core:1792, Mathieu Bouchard hints at:

{ || … } -or- { |*| … }

Could something like that work? Or would it be too ambiguious with blocks?