A Ruby WishList

Hi Folk,

I have been using Ruby for a some time now and I must say that I love
the language. While I have been reading mails here for some time now, I
have just joined this mailing list and this is my first post.

I recently wrote a blog entry about a WishList for Ruby and I would like
to get your responses about it. It is a rather lengthy entry, which is
why I am not posting th entire netry itself to the list.
http://pensieve.thinkingms.com/CommentView,guid,1a1045a1-bec1-45c7-97e9-
f3c9f7937cc7.aspx

To summarise briefly, I have mentioned:

  • Threading support
  • C/Cpp style operators
  • Use of Curly braces/indentation to identify scope
  • Ruby on .Net
  • Currying of methods / partial evaluations
  • Auto initialisation of variables

Awaiting opinions.

Regards,
Roshan James
http://www27.brinkster.com/sparksite/

InterScan_Disclaimer.txt (520 Bytes)

To summarise briefly, I have mentioned:

  • Threading support
  • C/Cpp style operators
  • Use of Curly braces/indentation to identify scope
  • Ruby on .Net
  • Currying of methods / partial evaluations
  • Auto initialisation of variables

I tried to post a comment on your site but I keep getting
Server Error in ‘/’ Application.

Here’s what I was trying to send:

I wish ruby had real threads. The threading support currently provided
is really sad.

This is being worked on for Rite. Green threads aren’t that bad anyway,
they’re still very useful and are more portable (they work even on
DOS). But Rite will have native threads too.

I wish ruby had ++, --, += and that whole class of operators.

You can find a lot of postings about ++ and – in ruby-talk, so I’m not
going to repeat that here. As for +=, once you define + you get += for
free, and a += b will always mean a = a + b. Same with other OP= things.

Use of Curly Braces { }

You could toy with a code filter (preprocessor) to try that, especially
if you want to try significant indentation too.

I rather like the fact that blocks can be spotted easily at the moment.

Auto Initialization of variables
When I write code like this

sum = 0
10.times{|n| sum = sum + n }

having sum be auto-initialized to 0 is evil. Should it be 0, ‘’,
, {}? How would Ruby know?

In Ruby 2.0, you’ll be able to do
10.times{|n| (sum ||= 0) += n }
puts “Sum is #{sum}”
due to the new rules for block variables.

as for

10.times{|n| sum<0> += n; prod<1> *= n; }
there’s no need to import clumsy syntax into Ruby IMHO.

Currying of Methods and Partial Evaluations

add = lambda{|x,y| x + y }
=> #Proc:0x401fb358@:1(irb)
def curry(proc, *args); lambda{|a| proc.call((args+a))} end
=> nil
add10 = curry(add, 10); add2 = curry(add, 2)
=> #Proc:0x401f5a0c@:2(irb)
add10[1]
=> 11
add2[1]
=> 3

This could be done on methods too (without having to reify them with
method(:meth)) if parens. were needed (as in Python) to actually
do the method call. See
http://onestepback.org/index.cgi/Tech/Ruby/PythonAndRuby.rdoc.

···

On Wed, Apr 21, 2004 at 08:07:39PM +0900, James, Roshan (Cognizant) wrote:


Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

And Bruce is effectively building BruceIX
– Alan Cox

I’ll comment on some.

James, Roshan (Cognizant) wrote:

I recently wrote a blog entry about a WishList for Ruby and I would like
to get your responses about it. It is a rather lengthy entry, which is
why I am not posting th entire netry itself to the list.
http://pensieve.thinkingms.com/CommentView,guid,1a1045a1-bec1-45c7-97e9-
f3c9f7937cc7.aspx

To summarise briefly, I have mentioned:

  • Threading support

Coming in Rite or Cardinal (Ruby on Parrot). Rite might have both green
and OS threads.

  • C/Cpp style operators

As Mauricio has mentioned, has been discussed many times.

http://www.ruby-talk.com/blade/2710
http://www.ruby-talk.com/blade/5961

  • Ruby on .Net

There has been some efforts on this. This will require at least a
partial rewrite of Ruby probably to C#. I’d rather see Ruby being ported
to Parrot first though (Parrot will also run on Windows and a myriad
others that .NET/Mono won’t).

  • Auto initialisation of variables

If you don’t declare variables first, Ruby can’t know if it’s a method
or a local variable:

def sum; …; end
def sum=; …; end
sum = sum+1 # this will invoke the sum and sum= methods.

sum = 2
sum = sum+1 # this will increment the sum local variable.

sum # now if you don’t declare it first, what is sum? a
# method or a local variable

However, you don’t need to predeclare $global or Constant because they
can’t be confused with methods.

···


dave

Just a thought… What if there was a class:

class Nothing
def +(other)
other + self
end
def -(other)
other - self
end
#…
def to_int
0
end
def to_str
“”
end
#…
end

basically, this would be a class that would take on the empty version
of whatever was necessary.

This would probably only work with the basic classes, though… since
+, -, etc can be redefined, you can’t assume that obj.+() requires an
argument of it’s own kind; or that a+b == b+a, etc.

So I guess this wouldn’t really wwork, after all. :slight_smile:

cheers,
–Mark

···

On Apr 21, 2004, at 5:42 AM, Mauricio Fernández wrote:

Auto Initialization of variables
When I write code like this

sum = 0
10.times{|n| sum = sum + n }

having sum be auto-initialized to 0 is evil. Should it be 0, ‘’,
, {}? How would Ruby know?

  • Ruby on .Net

There has been some efforts on this. This will require at least a
partial rewrite of Ruby probably to C#. I’d rather see Ruby being ported
to Parrot first though (Parrot will also run on Windows and a myriad
others that .NET/Mono won’t).

I would imagine the code generation pass is different for ILASM then for
JAVA bytecode or Parrot bytecode, but there is no intervening C# pass
required. You could still write a self hosting ruby compiler on ILASM.

Charlie