Ruby wish-list

A thought on current_block_yield and then the GC:

It's not exactly the same, but couldn't you just define a
recursive map function?

class Array
  def map_r &block
    map{|e|Array===e ? e.map_r(&block) : block[e]}
  end
end
p [[1,2,[3]],[[[5],6],7],8].map_r{|e|e.to_s}

=> [["1", "2", ["3"]], [[["5"], "6"], "7"], "8"]

Though a little hackish, I wonder if you can receive a named block then
pass that block to itself, a la
def map_r &block
map{|e| block(e, &block) }
end
so that the block could itself call yield. But this would still be a
little harder than being able to say current_block, should it be doable.
Just thinking out loud.

A question on the GC.
So if you try and build a multi-threaded GC [one thread picks up on free
objects, hands them back to the parent thread for use], it turns out
that if you don't free memory, then my current GC does this:

1) you run out of freelist, so you call garbage_collect which spawns a
child thread, and adds to the heap so the parent can continue.
2) when the child thread terminates the heap is now in a larger state
than it was.
3) when it runs out of freelist again, it adds to the heap and spawns
the child thread. The child thread now takes longer to finish than it
did before. Meaning the parent will be adding more to heap while
waiting for it to finish.
4) repeat 3 over and over until you run out of memory.

So currently it doesn't free any memory ever [commented it out]. I'm
hoping that adding that capability will do the trick. If that doesn't
work, though, it seems possible for these two threads to become engaged
in a cycle, if you ever get above a certain threshold then basically it
will just eat up all the memory in the system as it takes longer and
longer to collect. So it exacerbates the problem.

Potential ways to beat this: never add to the heap during a garbage
collect?

Thoughts?
Thanks!
-R

···

--
Posted via http://www.ruby-forum.com/\.

Ari Brown wrote:

Hey!

Not **quite** on topic of garbage collection.... But how hard would
it be to create maybe a style of method creation that doesn't use
the . to represent Object.behavior ?

Define your code in the global namespace, like
def a
end
is a function a 'in the global namespace' -- no dots.
Maybe hard code in the parent class?
The way Rails does it is by say you do the command
my_special_class_function_one
if it doesn't exist it catches the error thrown for non-existence, looks
up how and then defines the method and returns it (redefines things
in-line).

In retrospect, it seems like definitely a core language feature that
may or may not be impossible to get at... But I figured I'd ask :slight_smile:

Also, Is there an easy/hard way to define new %{} style methods? Like
for a Rope object, maybe %m{} or something.

Not sure.
GL!

···

Just a newbie's musings.

Thanks,
Ari
--------------------------------------------|
If you're not living on the edge,
then you're just wasting space.

--
Posted via http://www.ruby-forum.com/\.

This has come up before - I can't find the thread, but I believe the
answer was that it would hinder the ability to add new ones to the
core (since that could potentially break code that had already defined
it).

martin

···

On 10/15/07, Ari Brown <ari@aribrown.com> wrote:

Also, Is there an easy/hard way to define new %{} style methods? Like
for a Rope object, maybe %m{} or something.

Roger Pack wrote:

GC wish list:

Another wish for Ruby would be the power to define ones own unary or
binary operators.

Like I wish I could define "is_within?' for arrays, like
if element_x is_within? array_y
# do stuff
end

That would be sweet. If such a thing were possible, then one could
really create code that looks like complete sentences :slight_smile:
My $.02 for the day.

-Roger

···

--
Posted via http://www.ruby-forum.com/\.

Since this thread is alive again I am throwing in my wish which occured
to me in last months.

I wish parameters can be omited when calling methods with parameter
which have default values set and is (are) in the middle ro begining of
the parameter set.

Example:

def myMethod(a=1, b=2, c=3)
end
myMethod(3,5)
myMethod(,5)

This way I don't have to know the value of parameter b (which I am also
not interested in) and the called method would use default defined value
of 2.

of course if method is defined as:

def myMethod(a=1, b, c=3)
end
myMethod(3,5) => should throw an error.

by
TheR

···

--
Posted via http://www.ruby-forum.com/.

Rubbing the lamp....
I wish...

a = [1,2,3,4]

a[0..1, 4]

or

a[1,2,3]

worked.

:slight_smile:
-=R

···

--
Posted via http://www.ruby-forum.com/.

Oh, I wasn't understanding your idea, which does seem to make sense now.
There's the overhead of essentially duplicating the object space of the
original process in the fork (since mark will write to memory pages).
Maybe it would be worth this cost (esp. on a second processor) for the
benefit of not having to stop the main process?

...

I'll probably hack it up sometime, first version as a straight patch to
1.8.6

Turns out that just increasing the malloc limit to 80MB or so gives a
nice decrease in GC time[1]--about 80% for me. So that's an easy stop
gap till I get this going. It does tend to use a lot more RAM, though,
unfortunately.

Question about typical VPN's: I assume that typically the bottleneck is
typically RAM and not CPU [ex: on 256MB slice], and they have access to
multiple cores where available, is that right?
Thanks!
-=R
[1] railsbench/GCPATCH at v0.8.3 · skaes/railsbench · GitHub

···

--
Posted via http://www.ruby-forum.com/\.

Oh, wishing star! Here are my wishes:

1. Use "new" as the name of the constructor instead of "initialize".
You can keep "initialize" around for legacy support; just "alias
initialize new" for the future.

This makes it easy to connect the dots: "SomeClass.new" actually calls
the "new" instance method of a newly instantiated object of class
SomeClass.

2. Fix the Ruby parser to treat // (literal regexp) just like the
%r{...} (also literal regexp) construct so that you aren't forced to use
parentheses in method calls:

  $ ruby -v
  ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-linux]

  $ ruby -w -e '"foo".sub /o$/, "x"'
  -e:1: warning: ambiguous first argument; put parentheses or even
spaces

  $ ruby -w -e '"foo".sub %r/o$/, "x"'
  [observe lack of warning]

This problem becomes especially apparent when you use gsub! or sub!:

  "foo".gsub! /o$/, "x" # IMHO, sweet!

  "foo".gsub! %r/o$/, "x" # IMHO, so-so!

  "foo".gsub!(/o$/, "x") # IMHO, ugly!

Thanks for your consideration.

···

--
Posted via http://www.ruby-forum.com/.

That can't be done now?!?

arr = ['a', 'b']

if arr.include? 'a'
puts "array arr includes the letter 'a'"
end

should be easy to do it the other way as well.

···

On Oct 19, 2007, at 5:09 PM, Roger Pack wrote:

Roger Pack wrote:

Like I wish I could define "is_within?' for arrays, like
if element_x is_within? array_y
# do stuff
end

Another wish for Ruby would be the power to define ones own unary or
binary operators.

Like I wish I could define "is_within?' for arrays, like
if element_x is_within? array_y
# do stuff
end

I guess it is possible:

if element_x.is_within? array_y
# do stuff
end

Ruby is flexible enough again!

Another wish list item would be being able to use "a {var_name}" instead
of "a #{var_name}" I hate that extra pound, as it reminds me of perl :slight_smile:

Take care.
-Roger

···

--
Posted via http://www.ruby-forum.com/\.

I wish parameters can be omited when calling methods with parameter
which have default values set and is (are) in the middle ro begining of
the parameter set.

I have already replied once and I thought and still think that
something like mymethod(2, ,3) looks kind of ugly.
But since then I took a look at Python and I like how it works with
default parameters and default values:

Example:

def myMethod(a=1, b=2, c=3)
end

You can call myMethod(b=5) and the other default values aren't
changed. I think this looks more beautyful than leaving empty space
between commas.
Ruby 1.9 supports named parameters, but I don't know anything about
it. Just take a look at it and see if it does what you want.
You can still work with hashes:
def myMethod(opts = {})
  defaults = {:a => 1, :b => 2, :c=> 3}
  opts = defaults.merge(opts)
  #whatever
end

···

On Fri, Mar 28, 2008 at 8:34 AM, Damjan Rems <d_rems@yahoo.com> wrote:

Rubbing the lamp....
I wish...

a = [1,2,3,4]

a[0..1, 4]

or

a[1,2,3]

worked.

Two things:

1) In my mind, this general thread is somewhat ridiculous. It's been
going on for -- what is it? -- ten months now? It seems to be just a
laundry list for things you want Ruby to do, whether they're sensible
or not, without a lot of thought into them, and at least sometimes
with reasoning like "I'm lazy and don't want to type some brackets".

2) "I wish X worked" is not a very useful way to describe what should
happen. I'm not saying you have to write tests or specs, but do
describe the behavior you expect. Maybe looking at the RubySpec
project will give you an idea of everything Ruby presently "should do"
and what the other implementations are working towards. If that
doesn't get you going, think about it as contributing to Rubinius in
some way, and the sooner that comes out the sooner you can easily
twist even more of Ruby to your desires.

When you're working on describing the behavior, consider this (from an
irb session in Ruby 1.8.6):

arr = (1..10).to_a

=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

arr[3,4]

=> [4, 5, 6, 7]

You seem to want arr[3,4] to return [4,5], and guess what? There's a
way to do that now:

arr.values_at(3,4)

=> [4, 5]

Let's say you don't care for Array#values_at and Array# is changed
to work as you expect. What will happen when someone who expects the
old behavior tries to use it?

···

On Aug 14, 2:35 pm, Roger Pack <rogerpack2...@gmail.com> wrote:

--
-yossef

Hi,

1. Use "new" as the name of the constructor instead of "initialize".
You can keep "initialize" around for legacy support; just "alias
initialize new" for the future.

Besides that renaming hook like "initialize" is far more difficult
than you expect, I don't think "new" is sufficient name for instance
initialization hook.

2. Fix the Ruby parser to treat // (literal regexp) just like the
%r{...} (also literal regexp) construct so that you aren't forced to use
parentheses in method calls:

$ ruby -v
ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-linux]

$ ruby -w -e '"foo".sub /o$/, "x"'
-e:1: warning: ambiguous first argument; put parentheses or even spaces

No matter how much you hate this warning, ambiguity would not go away.
If you don't put parentheses around arguments, the parser confuses
division operator (/) and regular expression at the first argument.

              matz.

···

In message "Re: ruby wish-list" on Sat, 20 Oct 2007 08:20:33 +0900, Suraj Kurapati <snk@gna.org> writes:

Suraj Kurapati wrote:

  "foo".gsub! /o$/, "x" # IMHO, sweet!

  "foo".gsub! %r/o$/, "x" # IMHO, so-so!

  "foo".gsub!(/o$/, "x") # IMHO, ugly!

Thanks for your consideration.

I wonder if that fact that regex's always with have two /'s might
help...

Now my own wish. I wish ruby didn't need ,'s for method parameters.
Why are they always necessary?
foo a b c # as long as a, b, and c aren't functions, and aren't
operators, this could parse!
Take care.
-Roger

···

--
Posted via http://www.ruby-forum.com/\.

"a %s" % var_name

a @ http://codeforpeople.com/

···

On Nov 5, 2007, at 3:27 AM, Roger Pack wrote:

Another wish list item would be being able to use "a {var_name}" instead
of "a #{var_name}" I hate that extra pound, as it reminds me of perl :slight_smile:

--
it is not enough to be compassionate. you must act.
h.h. the 14th dalai lama

Ruby 1.9 supports named parameters, but I don't know anything about
it. Just take a look at it and see if it does what you want.

Appears the new syntax is
def lolmatz(param1, param2 = 'second', param3)
  print param1, param2, param3
end
lolmatz('first', 'third') # prints 'firstsecondthird'

and it works.
Proc's also can have default parameters that way, too.
So I guess my wish would be a more intuitive style still, like
lolmatz('first', param3='third')
which worked out of the box :slight_smile:

Another would be (of course) easier multi-line comments (more
intuitive), like

···

###
comments!
###

That would be nice.

As a final note, in retrospect it would be possible to create a 'custom'
hash that inherited from the Hash class and had the functionality as if
it were ordered. Go Ruby for flexibility.

Thanks all :slight_smile:
-R
--
Posted via http://www.ruby-forum.com/\.

John Joyce wrote:

···

On Oct 19, 2007, at 5:09 PM, Roger Pack wrote:

Roger Pack wrote:

if arr.include? 'a'
puts "array arr includes the letter 'a'"
end

Another wish [I believe this one is in facets already] is that wherever
there's a multiples verb like .include? it would also come with
.includes? version so that the grammar isn't as confusing.
Thanks!
-R
--
Posted via http://www.ruby-forum.com/\.

Take care.
-Roger

I wish that ranges could be descending, like
(2000..1950)
and that Range.to_a wouldn't become obselete, as it seems quite useful
in rails!

···

--
Posted via http://www.ruby-forum.com/\.

probably not - unless you wanted to introduce ';'s to ruby too:

cfp:~ > cat a.rb
x = 1

result =
x / 4 * 2 /
   42
p result

def x(*re) 'forty-two' end

result =
x / 4 * 2 /
   42
p result

result =
x(/ 4 * 2 /)
   42
p result

cfp:~ > ruby a.rb
0
"forty-two"

a @ http://codeforpeople.com/

···

On Nov 5, 2007, at 1:28 PM, Roger Pack wrote:

I wonder if that fact that regex's always with have two /'s might
help...

--
share your knowledge. it's a way to achieve immortality.
h.h. the 14th dalai lama

Now my own wish. I wish ruby didn't need ,'s for method parameters.
Why are they always necessary?
foo a b c # as long as a, b, and c aren't functions, and aren't
operators, this could parse!

Or could it? Still wishing for this one sigh :slight_smile:
-Roger

···

--
Posted via http://www.ruby-forum.com/\.