[#7500] Re: how to introduce reference objects into ruby — "Geert Fannes" <Geert.Fannes@...>

The problem with the code you sent is that you have to go through ALL

16 messages 2006/03/10

[#7553] "not" operator used in expression that is a method parameter can generate syntax error — noreply@...

Bugs item #3843, was opened at 2006-03-15 22:09

27 messages 2006/03/16
[#7554] Re: [ ruby-Bugs-3843 ] "not" operator used in expression that is a method parameter can generate syntax error — nobu@... 2006/03/16

Hi,

[#7557] Re: [ ruby-Bugs-3843 ] "not" operator used in expression that is a method parameter can generate syntax error — 卜部昌平 <shyouhei@...> 2006/03/16

Nobu, you are not answering to the question.... You have to unveil why

[#7559] Re: [ ruby-Bugs-3843 ] "not" operator used in expression that is a method parameter can generate syntax error — Yukihiro Matsumoto <matz@...> 2006/03/16

Hi,

[#7560] Rant about keyword logical operators was : (Re: [ ruby-Bugs-3843 ] "not" operator used in expression that is a method parameter can generate syntax error) — "Zev Blut" <rubyzbibd@...> 2006/03/16

Hello,

[#7565] Re: [ ruby-Bugs-3843 ] "not" operator used in expression that is a method parameter can generate syntax error — mathew <meta@...> 2006/03/16

Yukihiro Matsumoto wrote:

[#7566] Re: [ ruby-Bugs-3843 ] "not" operator used in expression that is a method parameter can generate syntax error — "Brian Mitchell" <binary42@...> 2006/03/16

On 3/16/06, mathew <meta@pobox.com> wrote:

[#7567] Re: [ ruby-Bugs-3843 ] "not" operator used in expression that is a method parameter can generate syntax error — mathew <meta@...> 2006/03/16

Brian Mitchell wrote:

[#7568] Re: [ ruby-Bugs-3843 ] "not" operator used in expression that is a method parameter can generate syntax error — "Brian Mitchell" <binary42@...> 2006/03/16

On 3/16/06, mathew <meta@pobox.com> wrote:

[#7614] PATCH: A subclassable Pathname — "Evan Phoenix" <evanwebb@...>

A simply change (changing all references of "Pathname.new" to

19 messages 2006/03/27
[#7618] Re: PATCH: A subclassable Pathname — Tanaka Akira <akr@...17n.org> 2006/03/27

In article <92f5f81d0603262350k796fe48fp2224b9f2108ac507@mail.gmail.com>,

[#7619] Re: PATCH: A subclassable Pathname — "Evan Phoenix" <evan@...> 2006/03/27

Quite right on the .glob and .getwd. I guess the tests don't test hit

[#7620] Re: PATCH: A subclassable Pathname — Tanaka Akira <akr@...17n.org> 2006/03/27

In article <92f5f81d0603270903g2fb02244i6a395be708dfffa3@mail.gmail.com>,

Re: how to introduce reference objects into ruby

From: "Geert Fannes" <Geert.Fannes@...>
Date: 2006-03-10 13:39:42 UTC
List: ruby-core #7497
Hello, 

some explanation of the things I'm trying todo and why I think Ruby as
it is today is inadequate for this (which I think is a pitty since I
like Ruby a lot):

(The three following paragraphs explains where I need such reference
objects)
A normal matrix object CAN be implemented in Ruby without much troubles
using Arrays. Some sacrifices have to be made from the aesthetic point
of view, but still: I can choose to store ONLY the columns of the
matrix, since there is no difference between accessing an element via
columns and then a specific element from that column, or via rows and a
specific element of that row; I can translate each method that tries to
acces my matrix object via the rows into the corresponding calls that
happen via the columns, and the question of Ruby objects stored in
different places doesn't even pop up.

But things change when you want to implement a SPARSE matrix, i.e., a
matrix for which most of its elements are empty. E.g., I am analyzing
call-networks, data from a telecom firm that contains the call durations
for its customers, which can be represented with a matrix: element (i,j)
is the duration that j calls i. Since not everybody calls to everybody,
it would be a silly waste of space to store all the zero call durations
between people who did not make any calls (and impossible to find a
machine that can store all this info). To implement this, you basically
have to store each column using a Hash instead of an Array. Suppose I
still keep only track of the columns, I have a problem to retrieve a
certain row (e.g., all persons that call customer i): to get this
information, I have to check ALL columns and check if they have some
traffic to customer i, which is of course not as fast as retrieving a
certain column (all customers customer j calls to), which is just a
lookup in the Hash object.

Currently, I have such objects implemented in C and linked to Ruby, but
I would like to have a pure-Ruby implementation of a sparse matrix,
since then I do not need a C compiler, I do not have to fix in advance
that my matrix object can only store doubles or whatever, I can just
store any Ruby object in it at once.

To summorize, when you have a LOT of Ruby objects that should be
accessed from different places (like the columns and row-wise access in
a sparse matrix as explained above), Ruby is not very usefull. The gap
between storing VALUEs, having data duplication, keeping everything in
sync, and, implementing a small class that wraps an object, is too large
(and even impractical since I cannot override the assignment operator).

It think there is a need for a small, lightweight object that does
nothing else than acting as a small box where you can put one Ruby VALUE
in, and passes all incoming signals and methods to its content. This
would also enable parameter passing by reference for numerical objects,
reduce result returning etc. I think it is a pitty that code becomes
overly complex (or Ruby even becomes unsuitable) due to missing
functionality. The fact that this came up before maybe indicates there
is a need for this.

Anyway, can you explain why you consider a reference object as a
"mis-feature"? I don't see why Ruby would be harmed if such a thing was
present. I would like to have a clear view of its consequences and try
to come up with something that interferes as little as possible and
solves the problem without cluttering Ruby itself.

Greetings,
Geert.

-----Original Message-----
From: Evan Phoenix [mailto:evanwebb@gmail.com] 
Sent: Thursday, March 09, 2006 6:24 PM
To: ruby-core@ruby-lang.org
Subject: Re: how to introduce reference objects into ruby

Geert,

This has come up in different varations before, but the answer is
always "No, ruby doesn't support that and most likely never will.".
Primarily, this is because such a "feature" is considered by most
(myself included) to be a mis-feature. Such a thing would mean that
ruby's behavior in many places would be drasticly different to support
this, an really there is no reason. If you believe that you MUST have
such a think to solve a problem, it's probably time to step out of
that box you are in (if you  glance back at it as you do, you'll see
that someone has written "C" on the side of the box as well).

Given that, what problem do you believe that you need such a feature
to convey nicely? In the 3-4 years since I started using ruby, I
haven't yet come up with one myself. If you have some, I'm sure the
community would help you work through the "ruby way" to solve it.

 - Evan Phoenix <evan@fallingsnow.net>

On 3/9/06, Geert Fannes <Geert.Fannes@ikanconsulting.com> wrote:
> Hello,
>
>
>
> One thing that hinders the usability of Ruby for the things I want to
> do, is the fact that certain objects cannot be modified "in place" and
> always return NEW objects (like Fixnum, Bignum or Float), making it
hard
> to do parameter passing by reference or similar things. Things get
> easily out of sync and both memory and cpu time (and programming
> overhead) has to be wasted to keep things going as should.
>
>
>
> To make things clear: Suppose I have a certain number distributed over
> different objects and I want this number to be synchronized (read "the
> same") in these different places:
>
>
>
> a=b=12 #a and b are my to objects I want to be synchronized
>
> a+=1
>
> p a #=> 13
>
> p b #=> 12 KO :-( I want it to be 13, exactly the same as a
>
>
>
> I can of course capture this number in a class, and distribute the
class
> object instead of the number object:
>
>
>
> class Bla
>
>   attr :number,true
>
> end
>
> (a=b=Bla.new).number=12
>
> a.number+=1
>
> p a.number #=> 13
>
> p b.number #=> 13 OK! :-)
>
>
>
> But now my code looks more complicated, I have an extra class and have
> to remember to use the instance variable .number. This also wastes too
> much memory when e.g. implementing a matrix object where I want to
have
> both an array holding the rows, one for holding the columns and the
> actual rows and columns SHARE the same numbers using objects of type
> Bla. This way, if I modify a certain element (say element at row i,
> column j) by taking the i-th row and modifying the j-th element in
that
> row, I want to see the change also if I access the same matrix element
> by selecting the j-th column and the i-th element from that column.
>
>
>
> I tried to create a class that contains a certain Ruby object and that
> passes all the incoming methods to the contained object, acting as a
> kind of reference.
>
>
>
> class Reference
>
>   attr :containedObject,true
>
>
>
>   def initialize(obj)
>
>     @containedObject=obj
>
>   end
>
>
>
>   #handle missing methods and pass them to the contained object
>
>   def method_missing(methodSymbol,*args)
>
>     @containedObject.send(methodSymbol,*args)
>
>   end
>
>
>
>   #override some general existing methods, to make sure that a
Reference
> object is as stealth as possible
>
>   def class
>
>     @containedObject.class
>
>   end
>
>   #unfortunately, this fails since assignment cannot be overloaded,
> which makes sense, but still ...
>
>   def =(rhs)
>
>     @containedObject=rhs
>
>   end
>
> end
>
>
>
> Unfortunately, I cannot overload the assignment operator (and some
other
> operators), so I still cannot work with these objects as if I was
> working with a normal number. So my guess is that to implement such a
> Reference class, I have to go deeper and dive in the Ruby code itself,
> modifying the unoverloadable operators in the parser etc.
>
>
>
> This seems a bit drastic, if someone knows an easier solution to this
> problem, please let me know. If not, are there people willing to help
me
> with introducing a Reference object in Ruby or have suggestions how
this
> can be done? I cannot imagine no one encountered the same problems
> before.
>
>
>
> Greetings,
>
> Geert.
>
>
>


--
When I do good, I feel good;  when I do bad, I feel bad,
and that is my religion.
    -- Abraham Lincoln (1809 - 1865)



In This Thread

Prev Next