[#98950] Strange behaviour of Strings in Range — Michael Neumann <mneumann@...>

Hi,

24 messages 2004/05/01

[#98975] Why no Proc##[]=() ? Why no Proc##replace() ? — Jean-Hugues ROBERT <jean_hugues_robert@...>

Hi,

15 messages 2004/05/01
[#98983] Re: Why no Proc##[]=() ? Why no Proc##replace() ? — Dan Doel <djd15@...> 2004/05/01

I'm not sure what your proposal means.

[#98997] Re: Why no Proc##[]=() ? Why no Proc##replace() ? — Jean-Hugues ROBERT <jean_hugues_robert@...> 2004/05/02

About class Proc; def []=(*args); self[*args] end end and the value of

[#98980] Ruby Newbie (ooh, that rhymes!) - When do I use do/end, when {}? — glenn_m_smith@... (Glenn)

Hello all

23 messages 2004/05/01

[#99105] What do you use Ruby for? — glenn_m_smith@... (Glenn)

OK, the more I read about Ruby (currently on page 29 of the FAQ,

25 messages 2004/05/03

[#99119] YAML vs. Marshal — dejaspam@... (Bill Atkins)

Is there any reason to use Marshal instead of YAML? Is there anything

21 messages 2004/05/03
[#99121] Re: YAML vs. Marshal — Joel VanderWerf <vjoel@...> 2004/05/03

Bill Atkins wrote:

[#99191] Re: YAML vs. Marshal — why the lucky stiff <ruby-talk@...> 2004/05/04

Joel VanderWerf wrote:

[#99192] Re: YAML vs. Marshal — Hal Fulton <hal9000@...> 2004/05/04

why the lucky stiff wrote:

[#99204] What so special about PostgreSQL and other RDBMS? — "Sarah Tanembaum" <sarah.tanembaum@...>

Beside its an opensource and supported by community, what's the fundamental

96 messages 2004/05/04

[#99270] Is Ruby Top 1 of Programming Languages that are Loved? — "Park Heesob" <phasis68@...>

Hi all,

66 messages 2004/05/05
[#99333] Re: [OT]Is Ruby Top 1 of Programming Languages that are Loved? — ptkwt@... (Phil Tomson) 2004/05/06

In article <83173408.0405051506.5db85fe6@posting.google.com>,

[#99358] Re: [OT]Is Ruby Top 1 of Programming Languages that are Loved? — Dick Davies <rasputnik@...> 2004/05/06

* Phil Tomson <ptkwt@aracnet.com> [0554 02:54]:

[#99378] Re: [OT]Is Ruby Top 1 of Programming Languages that are Loved? — "Ara.T.Howard" <ahoward@...> 2004/05/06

On Thu, 6 May 2004, Dick Davies wrote:

[#99326] RAA error - can't dup NilClass — Simon Strandgaard <neoneye@...>

When I try to enter my project page

15 messages 2004/05/06
[#99327] Re: RAA error - can't dup NilClass — "NAKAMURA, Hiroshi" <nahi@...> 2004/05/06

Hi,

[#99328] Re: RAA error - can't dup NilClass — "NAKAMURA, Hiroshi" <nahi@...> 2004/05/06

Hi, again,

[#99332] miniruby.exe & statically linked ruby.exe (Windows) — ptkwt@... (Phil Tomson)

I've been trying to build a statically linked ruby.exe on windows using

12 messages 2004/05/06

[#99399] DRb Connection Closed Error?!?!?!? — "Ken Hilton" <kenosis@...>

Greetings,

14 messages 2004/05/06

[#99438] What is Borges? — dejaspam@... (Bill Atkins)

Can someone please explain to me what Borges does? Its home page

41 messages 2004/05/07
[#99482] Re: What is Borges? — Dick Davies <rasputnik@...> 2004/05/07

* Bill Atkins <dejaspam@batkins.com> [0534 01:34]:

[#99530] Re: What is Borges? — Julian Fitzell <julian@...4.com> 2004/05/07

Dick Davies wrote:

[#99534] Re: What is Borges? — Carl Youngblood <carl@...> 2004/05/07

[#99527] Ruby Installer for Windows: use of Win32OLE bug causes crash — Jos Backus <jos@...>

This is with the latest Ruby Installer for Windows, 181-13-rc2.

11 messages 2004/05/07

[#99583] Ruby Installer for Windows 1.8.1-13 final — "Curt Hibbs" <curt@...>

The Ruby Installer 1.8.1-13 (final) for Windows has been released and

62 messages 2004/05/08
[#99643] Why Ruby? -- A Resource for Promoting Ruby — "Curt Hibbs" <curt@...> 2004/05/09

I'm pleased to announce the kickoff of RubyForge project called "Why Ruby?"

[#104934] Ruby Installer for Windows 1.8.2-14 Release Candidate — "Curt Hibbs" <curt@...> 2004/06/30

I have uploaded a release candidate for Ruby Installer that was built using

[#104952] **RC2** Ruby Installer for Windows 1.8.2-14 Release Candidate — "Curt Hibbs" <curt@...> 2004/07/01

The original release candidate that I posted earlier today did not include

[#105519] Re: [ANN] **RC2** Ruby Installer for Windows 1.8.2-14 Release Candidate — Lothar Scholz <mailinglists@...> 2004/07/07

Hello Curt,

[#105546] Re: [ANN] **RC2** Ruby Installer for Windows 1.8.2-14 Release Candidate — Hidetoshi NAGAI <nagai@...> 2004/07/08

Hi,

[#105550] Re: [ANN] **RC2** Ruby Installer for Windows 1.8.2-14 Release Candidate — nobu.nokada@... 2004/07/08

Hi,

[#99597] How to get the last 5 elements of an array? — Gavin Sinclair <gsinclair@...>

Hi,

20 messages 2004/05/08

[#99680] rubygarden homepage hacks — Simon Strandgaard <neoneye@...>

On daily basis the homepage at rubygarden is being edited.

19 messages 2004/05/09

[#99734] in search of a compelling reason to use ruby.... — Ryan Paul <segphault@...>

i'm a python programmer, and I have recently been hearing a lot about

28 messages 2004/05/10

[#99764] safe eval? — "Ara.T.Howard" <Ara.T.Howard@...>

20 messages 2004/05/10
[#99773] Re: safe eval? — Florian Gross <flgr@...> 2004/05/10

Ara.T.Howard wrote:

[#99834] Re: safe eval? — ts <decoux@...> 2004/05/11

>>>>> "F" == Florian Gross <flgr@ccan.de> writes:

[#99854] Proposal: Object#send(nil) -> self — Gavin Sinclair <gsinclair@...>

A quick one. I see some sense in Object#send accepting 'nil' as the

21 messages 2004/05/11

[#99879] Strange regexp behaviour in gsub — Kristof Bastiaensen <kristof@...>

Hi,

15 messages 2004/05/11

[#99945] Recommendations (Ruby making my head swim) — Mike Rhodes <rhodes553@...>

I recently bought "Programming Ruby" and set out to learn the language

13 messages 2004/05/12

[#99966] Major Addition Bug? — "Sean O'Dell" <sean@...>

Doing this:

57 messages 2004/05/12
[#99967] Re: Major Addition Bug? — ts <decoux@...> 2004/05/12

>>>>> "S" == Sean O'Dell <sean@celsoft.com> writes:

[#99970] Re: Major Addition Bug? — "Sean O'Dell" <sean@...> 2004/05/12

On Wednesday 12 May 2004 09:53, ts wrote:

[#100032] are there any ruby IDEs? — Ryan Paul <segphault@...>

I use vim most of the time, but i'm curious if there are any

35 messages 2004/05/12

[#100093] How to make combinations of an array to produce all possible expressions? — Erik Terpstra <erik@...>

I have an array 'conds', which contains some sub-expressions for an

11 messages 2004/05/13

[#100136] Ruby's Best -- Please Help — "Curt Hibbs" <curt@...>

On the "Why Ruby?" project wiki (http://whyruby.rubyforge.org/), I am trying

23 messages 2004/05/13
[#100284] Please revisit Ruby's Best and vote for additions — "Curt Hibbs" <curt@...> 2004/05/14

If you were an early visitor to:

[#100137] First Presentation Posted to Why Ruby! — "Curt Hibbs" <curt@...>

Assaph Mehr just posted the first presentation to Why Ruby

22 messages 2004/05/13
[#100172] Presenting a more unified front (Ruby webring?) — ptkwt@... (Phil Tomson) 2004/05/13

In article <EAENKKNOJPMNCDMLDOMLKEHHEFAA.curt@hibbs.com>,

[#100182] C++ Exception compatibility idea — Asfand Yar Qazi <im_not_giving_it_here@..._hate_spam.com>

Hi,

26 messages 2004/05/13
[#100206] Rite implementation in C++? (Objective C?) — ptkwt@... (Phil Tomson) 2004/05/13

In article <40A3E539.2010204@hypermetrics.com>,

[#100193] subclasses of string as hash keys — Matthias Georgi <matti_g@...>

15 messages 2004/05/13

[#100273] Regexp Error? — "Robert Klemme" <bob.news@...>

What's wrong here?

16 messages 2004/05/14

[#100295] Re: Regexp Error? — Michael Campbell <michael_s_campbell@...>

ts wrote:

15 messages 2004/05/14

[#100325] Re: Please revisit Ruby's Best and vote for additions — "Curt Hibbs" <curt@...>

James Britt wrote:

12 messages 2004/05/14

[#100395] Need Help Selecting a GUI — dejaspam@... (Bill Atkins)

As anyone can tell by looking at the topics of my recent posts, I'm

18 messages 2004/05/15

[#100461] Ruby on Rails — Matt Lawrence <matt@...>

Very neat presentation, it kept me up way too late last night watching it.

24 messages 2004/05/16

[#100511] How to duck type? - the psychology of static typing in Ruby — Tim Bates <tim@...>

Hi all,

83 messages 2004/05/17
[#100525] Re: How to duck type? - the psychology of static typing in Ruby — "SER" <ser@...> 2004/05/17

Broken record time:

[#100791] Re: How to duck type? - the psychology of static typing in Ruby — Marek Janukowicz <childNOSPAM@...17.ds.pwr.wroc.pl> 2004/05/19

On Thu, 20 May 2004 03:43:22 +0900, Dave Thomas wrote:

[#100613] FoX: removing widgets — Yuri Leikind <y.leikind@...>

Hello all,

16 messages 2004/05/18
[#100670] Re: FoX: removing widgets — Lyle Johnson <lyle@...> 2004/05/18

Yuri Leikind wrote:

[#100629] Newbie installation problem: libraries? — Paul Emmons <pemmons@...>

I have recently installed ruby-1.8.1 on my Mandrake Linux system.

11 messages 2004/05/18

[#100649] Windows desktop app w/ simple db; how? — "Kirk Haines" <khaines@...>

Imagine that you had a very simple web based application. It queries some

12 messages 2004/05/18

[#100653] Zero is true ... whoda thunk? — "Richard Lionheart" <NoOne@...>

Hi,

29 messages 2004/05/18
[#100655] Re: Zero is true ... whoda thunk? — Mark Sparshatt <msparshatt@...> 2004/05/18

Richard Lionheart wrote:

[#100682] Re: Zero is true ... whoda thunk? — Chris Pine <cpine@...> 2004/05/19

On Wed, 19 May 2004 06:34:54 +0900, Mark Sparshatt wrote:

[#100691] Re: Zero is true ... whoda thunk? — David Naseby <david.naseby@...>

>-----Original Message-----

14 messages 2004/05/19

[#100721] irb or xterm crash with UTF-8 — Simon Strandgaard <neoneye@...>

server> irb

15 messages 2004/05/19

[#100839] Where to download FXRuby library; where to put it; RUBYLIB, RUBYPATH env. vars — "Richard Lionheart" <NoOne@...>

Hi,

14 messages 2004/05/20

[#100862] Ruby's builtin Datastructures — Brian Schroeder <spam0504@...>

Hello all,

13 messages 2004/05/20

[#101071] Concerning version numbers... — Hal Fulton <hal9000@...>

A few people in recent weeks have been bemoaning the fact that software

15 messages 2004/05/22

[#101110] Ruby for educational purposes and localization — Laurent Julliard <laurent__no__@__spam__moldus.org>

All,

10 messages 2004/05/23

[#101165] make faster Richards benchmark — dlissett0@... (Duncan Lissett)

I'd appreciate any suggestions on how to make a faster Ruby

15 messages 2004/05/24

[#101226] Concerning package names — djberg96@... (Daniel Berger)

All,

13 messages 2004/05/24

[#101292] Numeric#of — "Ara.T.Howard" <ahoward@...>

53 messages 2004/05/25

[#101329] separating ruby-talk from comp.lang.ruby? — David Alan Black <dblack@...>

Hi --

65 messages 2004/05/25
[#101388] Re: separating ruby-talk from comp.lang.ruby? — ptkwt@... (Phil Tomson) 2004/05/25

In article <m3brkcda7g.fsf@wobblini.net>,

[#101391] Re: separating ruby-talk from comp.lang.ruby? — "David A. Black" <dblack@...> 2004/05/25

Hi --

[#101360] ruby-dev summary 23459-23562 — Minero Aoki <aamine@...>

Hi all,

30 messages 2004/05/25
[#101395] Re: ruby-dev summary 23459-23562 — Florian Gross <flgr@...> 2004/05/25

Minero Aoki wrote:

[#101369] defining condititions — Florian Weber <csshsh@...>

hi!

18 messages 2004/05/25

[#101522] WEBrick and FastCGI response — Jim Freeze <jim@...>

Reply-To:

15 messages 2004/05/27

[#101560] Re: separating ruby-talk from comp.lang.ruby? — "Mills Thomas (app1tam)" <app1tam@...>

Here, here, hear, hear. No NNTP here.

41 messages 2004/05/27
[#101565] Re: separating ruby-talk from comp.lang.ruby? — "David A. Black" <dblack@...> 2004/05/27

Hi --

[#101569] Re: separating ruby-talk from comp.lang.ruby? — Dave Thomas <dave@...> 2004/05/27

[#101571] Re: separating ruby-talk from comp.lang.ruby? — "David A. Black" <dblack@...> 2004/05/27

Hi --

[#101616] Re: separating ruby-talk from comp.lang.ruby? — "David A. Black" <dblack@...> 2004/05/28

Hi --

[#101686] Re: separating ruby-talk from comp.lang.ruby? — Dave Thomas <dave@...> 2004/05/28

[#101890] Re: separating ruby-talk from comp.lang.ruby? — "David A. Black" <dblack@...> 2004/05/31

Sorry everyone, testing again.... small meaningless tweak to

[#101674] Andreas' practical language comparison — "Georgy" <no.mail@...>

Hi all!

13 messages 2004/05/28

[#101745] Test::Unit: assert_follows_spec() (or something like that) — David Garamond <lists@...6.isreserved.com>

For deterministic functions/methods, the same set of inputs should

20 messages 2004/05/29

[#101823] gsub!, replace with \' — Patrick Gundlach <clr1.10.randomuser@...>

Dear Ruby-hackers,

14 messages 2004/05/30

[#101830] Behavior of application changes when adding non-relevant puts — felix.nawothnig@... (Felix Nawothnig)

Hi.

12 messages 2004/05/30

[#101853] mysql-ruby — Paul Vudmaska <paul@...>

%$@#%$ i know i've abused this list with more questions than answers but

14 messages 2004/05/31

[#101855] elegant way to say "try this thing, one at a time, until condition is met" — David Garamond <lists@...6.isreserved.com>

Example: I need to unmount /usr and /usr2, but currently I can't because

23 messages 2004/05/31

[#101899] RMagick available on Windows — Tim Hunter <cyclists@...>

Thanks to Kaspar Schiess, RMagick for Windows is now available at

13 messages 2004/05/31

Re: Why no Proc##[]=() ? Why no Proc##replace() ?

From: Jean-Hugues ROBERT <jean_hugues_robert@...>
Date: 2004-05-04 06:42:13 UTC
List: ruby-talk #99143
Warning: I believe this thread of msgs is rather academic. Because I
initiated it I thought it might be useful to tell you that. if you don't
enjoy academic stuff, save your time and skip this msg :-)

class Proc
   def []=(*a)
     self[*a]
   end
end

Some consequences:

At 00:53 04/05/2004 +0900, you wrote:
>On Monday 03 May 2004 7:54 am, Jean-Hugues ROBERT wrote:
> > Sometimes, a Proc is sometimes like an anonymous method, right ?
> > If assignment does not make sense for proc p,
> > then is does not make sense for method m.
> > then m.[]=( 1, x) does not make any more sense than p.[]=( 1, x)
> > Then m[1] = x does not make sense either
> > Then it is an embarrassing situation because a[1] = x does not make
> > sense... So, it has to make sense for method, and it should make sense for
> > proc too. Am I missing something ?
>
>Right. If m is a Method object, then m[1] = x doesn't make sense either.

OK. To summarize: I feel it makes sense that: class Method; def []=(*a) 
self[*a] end end
And you feel like it does not make sense (if I understand correctly).

Lets try (using Proc instead of Method, we both agree I think that a Proc
can act as an anonymous method).

# Make it so that a Proc can be a valid lvalue:
class Proc; def []=(*a) self[*a] end end

def trace_array( an_array, msg )
   proc { |*args|
     if args.length() == 1 then
        p "#{msg}: Read access at pos #{args[0]}"
        an_array[args[0]]
     elsif args.length() == 2 then
        p "#{msg}: Write access at pos #{args[0}"
        an_array[args[0]] = args[1]
     else
        p "#{msg}: Weird access."
        an_array[*args[0...-1]] = args[-1]
     end
   }
end

def buggy_meth()
   a = [1,2,3]
   a = trace_array( a, "a in buggy_meth()") if $Debug
   ... use a ...
end

In this example you can substitute a Proc where an Array was expected.
The Proc is invoked both for read and write accesses to the Array.
It outputs a msg and then performs the required operation on the Array.

This is a simple debugging tool made possible thanks to an additional
level of indirection.

With a Lvalue class that I am going to propose soon in a RCR, one
could do something similar on all lvalues, not just the [] ones:

def trace_lvalue( a_lvalue, msg )
   proc { |*args|
     if args.length() == 0 then
       p "#{msg}: Read access"
       a_lvalue
     else
       p "#{msg}: Write access"
       a_lvalue = args[0]
     end
   end
end

def buggy_meth()
   a = false
   a = trace_lvalue( ref a, "a flag in buggy_meth()") if $Debug
   ... Use a ...
end

In this example, you can substitute a Proc wherever a lvalue was
expected. The Proc is invoked both for read and write accesses to
the lvalue.

This is probably meta-programing, but I feel like I often need help
when I am chasing bugs (I make a lot of them ;-))

>m[1] = x only makes sense to me if m is an Array or a Hash or a String or
>something where it makes sense to talk about the Nth element of m. Proc and
>Method objects are not such types, in my opinion.

Fair enough.

> > That is true, it feels like treating assignment as an operation on object.
> > But it not true that Ruby treats assignment as an operation on variables,
> > it does so only for scalar object. For non scalars, arrays, hash, etc,
> > assignment is by method call (.[]=() on the non scalar object).
>
>We look at this in different ways. Let me try to explain my point of view more
>clearly.
>
>   o.a = b
>
>is to me a nicer way of saying
>
>   o.set_a(b)
>
>Which is what you'd do in Java. In Java, you can have lvalues of the form o.a
>if a is a public variable o. This is _never_ the case in Ruby, because there
>are only private instance variables.  However, Matz recognizes that it looks
>nicer if you can make attribute accessors look like public instance variables,
>so he wisely allowed for the syntax sugar to do so.
>
>If a is an Array, then:
>
>   a[i] = j
>
>means:
>
>   a.add_at_index(i, j)
>
>And similarly for Hashes and Strings. However, the semantic for [] on Proc
>and Method objects is:
>
>   a[i]  <==> a.call(i)
>
>However, I cannot think of any meaningful name for:
>
>   a[i] = j
>Which in your example turns into:
>
>   a.call(i, j)
>
>Even stranger might be:
>
>   a[i, j, k] = l, m, n  #=> becomes a.call(i, j, k, [l, m, n])

Its actually # => becomes a.call( i, j, k, l).

>In other words, for Proc and Method, [] is taken to mean "execute encapsulated
>code."  However, "execute encapsulated code equals" doesn't make sense to me,
>at least in the context of Ruby.

In Java you implement accessors using .getX() and .setX().
class MyClass
   def getX() @x end
   def setX() @x = v end
end
In Ruby the "standard" is to use x() and x=().
class MyClass
   def x() @x end
   def x=( v) @x = v end
end
It is so frequent that you have a convenience method that does it for you
class MyClass
   attr_accessor :x # defines both x() and x=()
end
Another "style" of accessors is o.x() & o.x(y):
class MyClass
   def x(*a) (a.length() == 0) ? @x : (@x = a[0]) # x() is both a getter 
and a setter
end

We both agree I think that o.x = y is a nicer syntax then o.x( y).
Only I think that p[] = y is a nicer syntax then p[y] if proc were an accessor.

Another one:
If ptr = Pointer.new(...) then p[] = x is nicer syntax (to me) than p.set( 
x) because
to me it reads "the content of p is assigned the value of x".

Not to mention: x = y versus x.set( y).

Back to block: b[] = x, to me, reads as "the content of b is assigned the 
value of x".
What that means exactly depends on the semantic of the block b.

Back to assignment:
class SomeClass
   def self.factory( *args )
     if xxx
       proc { |*a| ... }
     elsif yyy
       method( :something)
     elsif zzz
       ConcreteClassA.new( *args)
     else
       OtherConcreteClass.new( *args)
     end
   end
end
something = SomeClass.factory( xxx)
p something[0]
something[0] = 1

As a user of class SomeClass, I don't need to care about how accessors are 
implemented.
This is both encapsulation and polymorphing.

My conclusion is:
When x[ii] means "content of x" and x[ii]= y means "content of x is 
assigned the value of y",
it makes sense that x can be anything, a Method or a Block included, 
because I should
not care about that, it is up to the implementation to decide.
As a consequence it makes sense to define Proc##[]= as much as Proc##[] and
def []=(*a) self[*a] end makes sense as a default implementation.

OTOH the whole issue may be academic, because as a user, one can already:
class ProcPointer < Proc
   def []=(*a)
     self[*a]
   end
end
Which I believe is cleaner than
class Proc
   def []=(*a)
      self[*a]
   end
end
because the later one can be easily overlooked and as a result decreases the
readability of the code.
Yet, if the later one was included in Ruby, I believe the Proc class would
be more versatile.

> > This is not symetric. Ruby could always treat assignment as an operation
> > on an object. This requires: a Lvalue class and the ability to redefine
> > the assignment operator. As a result a variable could easily be an instance
> > of Lvalue and we would get closer to the motto "Everything is an object in
> > Ruby". I am currently prototyping such a Lvalue class.
>
>I don't really see how this would work.  It would require a fundamental change
>in the way variables work in Ruby.  For example, what happens when you do:
>
>   c = Foo.new
>
>If c is an Lvalue class, then the variable that c refers to becomes a new Foo
>object.  Otherwise, c becomes a new instance of Foo.  However, this means
>that all Ruby variables would have to be by-value instead of by-reference as
>they are now.

If c is_a? Lvalue then the lvalue object that c refers to (& which can be 
any lvalue,
a variable included), becomes a new Foo (which means that it now refers to 
a Foo:
c now refers to the same something but that something now refers to the new 
Foo).

However, this does not mean that all Ruby variables would have to be different
from what they are today (whatever the name you use to describe what they are
today). Only variables that holds a reference to a Lvalue object would have
to be treated differently than the "normal" variables. That's because the Ruby
interpretor would have to invoke some .getter() or .setter() method of the
Lvalue instead of using the variable's content directly (or, to rephrase more
formally, xxx instead of directly using the reference to some object that the
variable holds).

>   For example, if you did:
>
>   c = b
>
>Currently c and b refer to the same object.  In order to make your changes
>work, this would not be possible. I think this is a step backwards. It makes
>programmers think about what kind of memory they want to use (heap or
>stack, by-value or by-reference?). Not to mention that by-reference would
>be by far more used, considering Ruby has essentially _no_ by value variables
>at present and it does just fine.

I am not proposing such a radical change at all. I would rather go forward
than backward :-) What I am proposing is an additional tool, by the way of an
additional level of indirection. When the programmer need that tool it has
to be explicit and she/he would create a Lvalue object using some explicit
syntax:
b = "toto"
c = ref b # *explicit*
c = "titi"
p b # => "titi"
c is like an alias for b.

>This is all not to mention the fact that Ruby variables are untyped, so they
>need to be able to refer to amounts of memory to handle arbitrarily large
>objects.  The above scheme would require something similar to #become in
>Smalltalk.  The difference would be that for most objects, assignment would
>default to #become, rather than it being an uncommonly used method.

#become is a nice tool. But its use and abuse is programmer's responsability.

The implementation of Lvalue that I am propotyping does not use #become
(#become BTW is not yet fully available I believe, but that is not the reason).

b = "toto"
p b.object_id() # 123
c = ref b
c = "titi"
p b.object_id() # 456
If I were to use #become, b.object_id() would stay the same. It's not the
case and must not be.

As a matter of fact, I am very unsure that a Lvalue class could be implemented
at all using #become.

> > If there was a Lvalue class, and if p was to return a lvalue, then I guess
> > p.call = a, b, c
> > would be equivalent to
> > lvalue = a, b, c
> > which is equivalent to
> > lvalue = a.
> > I would then expect the lvalue to be assigned a. Either by calling
> > lvalue.=(a) or directly by the interpretor.
> >
> > But there is no Lvalue class today. The closer is a user defined Pointer
> > class: p = lambda { ... return an instance of Pointer }
> > p.call()[]= a, b, c
> > eqv p.call().[]=(a)
> >
> > As you can see, with a Pointer, you have to dereference yourself using [],
> > whereas with a Lvalue you would not.
>
>Based on what I said above, I think it's by far better to require someone to
>use a pointer class to make non-local variable assignments.  The actual need
>for them doesn't come up particularly often, and the consequences of making
>assignment object-based are, if you ask me, bad.

Then you don't mind that much that "In Ruby everything is an object, but 
variables and
... and ...".
I would prefer "In Ruby everything is an object". Introspection is a great
tool, the more, the better.

But goods and bads is all relative and its OK that our opinions
differs... My "match, assign & Lvalue" RCR should better be
*very* convincing !

> > I made 2 mistakes, self is not the Proc object, x gets scoped out.
> > r.replace { x } would work, but then r = proc { x } is more obvious.
> > I don't know how to get the current Proc object from the proc's body.
> > Any clue ?
>
>Well, in general, you'll have
>
>   r = lambda { ... }
>
>The block captures the scope in which it resides, so you can use r in the
>block to refer to the Proc itself.  That's the only way, as far as I know.

Yes, apparently it is the only way. Using it in a safe way requires some care:
begin
   r = lambda { ... use r here ... }
end
That way you are immune to further change to r, at least if r did not
exist before. A safer way:
begin
   my_own_very_specific_r_never_used_before = lambda { ... }
end

Yours,

Jean-Hugues



-------------------------------------------------------------------------
Web:  http://hdl.handle.net/1030.37/1.1
Phone: +33 (0) 4 92 27 74 17  


In This Thread