[#16113] Strange idea... exporting from a scope — "Hal E. Fulton" <hal9000@...>

Hello...

33 messages 2001/06/01

[#16364] Re: Garbage Collection? — Michael Davis <mdavis@...>

Windows 2000 and linux (RedHat 6.2). I have run these tests on both OSs.

12 messages 2001/06/09

[#16400] Symbolic Computation III — Mathieu Bouchard <matju@...>

14 messages 2001/06/11

[#16502] Playing with Ruby Syntax (was: Initial thoughts about Ruby From a Smalltalk Programmer) — jweirich@...

Michael> Hi Everyone, I have to say I'm utterly fascinated by Ruby

9 messages 2001/06/15

[#16661] Problem running irb with Ruby 1.6.4 under FreeBSD 4.0 — Bob Alexander <balexander@...>

I've installed Ruby 1.6.4 on a FreeBSD 4.0 machine, and get the

11 messages 2001/06/20

[#16686] opening db files made by apache dbmmanage — Fritz Heinrichmeyer <fritz.heinrichmeyer@...>

14 messages 2001/06/21

[#16801] rb_define_class() vs Class.new() — Kero van Gelder <kero@...4050.upc-d.chello.nl>

Hi,

18 messages 2001/06/23
[#16802] Re: rb_define_class() vs Class.new() — ts <decoux@...> 2001/06/23

>>>>> "K" == Kero van Gelder <kero@d4050.upc-d.chello.nl> writes:

[#16841] RE: national characters is strings — "Aleksei Guzev" <aleksei.guzev@...>

Next week I'll try to rebuild Ruby with Unicode strings. But it would be

15 messages 2001/06/25
[#16842] Re: national characters is strings — matz@... (Yukihiro Matsumoto) 2001/06/25

Hi,

[#16843] Re: national characters is strings — "Aleksei Guzev" <aleksei.guzev@...> 2001/06/25

That's good enough. But I'm afraid this could ( not would ) cause string

[#16868] Something strange with Ruby's inheritance mechanism — Eric Jacoboni <jaco@...>

As Ruby beginner, i try some "canonical" OO scripts. Doing so, I've

14 messages 2001/06/25
[#16873] RE: Something strange with Ruby's inheritance mechanism — "Aleksei Guzev" <aleksei.guzev@...> 2001/06/26

[#16879] Re: Something strange with Ruby's inheritance mechanism — Mathieu Bouchard <matju@...> 2001/06/26

On Tue, 26 Jun 2001, Aleksei Guzev wrote:

[#16869] Something strange with Ruby's inheritance mechanism — Eric Jacoboni <jaco@...>

As Ruby beginner, i try some "canonical" OO scripts. Doing so, I've

12 messages 2001/06/25

[#16881] — "Aleksei Guzev" <aleksei.guzev@...>

32 messages 2001/06/26
[#16916] Re: Method overloading (option) Was: Re: — "Wayne Blair" <wayne.blair@...> 2001/06/26

[#16920] Re: Method overloading (option) Was: Re: — matz@... (Yukihiro Matsumoto) 2001/06/26

Hi,

[#16888] finalizers, destructors and whatnot — "David Leal" <david@...>

Hi all,

16 messages 2001/06/26

[#17037] keeping an Exception object alive — David Alan Black <dblack@...>

Hello --

19 messages 2001/06/28
[#17055] Re: keeping an Exception object alive — matz@... (Yukihiro Matsumoto) 2001/06/29

Hi,

[#17066] RCR: Exception methods (was: Re: Re: keeping an Exception object alive) — David Alan Black <dblack@...> 2001/06/29

Hello --

[#17076] Re: RCR: Exception methods (was: Re: Re: keeping an Exception object alive) — matz@... (Yukihiro Matsumoto) 2001/06/29

Hi,

[#17079] Re: RCR: Exception methods (was: Re: Re: keeping an Exception object alive) — David Alan Black <dblack@...> 2001/06/29

Hello --

[#17138] Re: RCR: Exception methods (was: Re: Re: keeping an Exception object alive) — matz@... (Yukihiro Matsumoto) 2001/07/02

Hi,

[#17141] Re: RCR: Exception methods (was: Re: Re: keeping an Exception object alive) — David Alan Black <dblack@...> 2001/07/02

Hello --

[#17142] Re: RCR: Exception methods (was: Re: Re: keeping an Exception object alive) — ts <decoux@...> 2001/07/02

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

[ruby-talk:16118] Re: Strange idea... exporting from a scope

From: "Hal E. Fulton" <hal9000@...>
Date: 2001-06-01 05:51:25 UTC
List: ruby-talk #16118
----- Original Message -----
From: Wayne Blair <wayne.blair@relian.com>
To: ruby-talk ML <ruby-talk@ruby-lang.org>
Sent: Thursday, May 31, 2001 10:18 PM
Subject: [ruby-talk:16114] Re: Strange idea... exporting from a scope


> Hi Hal,
>
> Maybe I'm missing something (like I have no idea what the block problem
is),
> but why wouldn't you just declare the variable in the outer scope then set
> it from inside the block:
>
> my_var = nil
> my_method do |x,y,z|
>    # ...
>    my_var = 123
>    #...
> end
> puts my_var      # 123

Hi Wayne...

I always get confused by this, and I'm a fool for answering this
email at nearly 1 a.m. my time... my neurons are firing very
sluggishly.

Here is my summary of the block problem. (I'm likely missing
some points.)

1. Intuition (for many people) says that the entities in the
"parameter" list (which really isn't a parameter list, right?)
are local to the block.

2. Their intuition is wrong. If Ruby sees a variable in the list
that already exists, it will use the existing one.

3. Some people at some times hate this. They don't want a
variable trounced just because they used a variable of the
same name in an innocent-looking context. They would like
to see these variables all become block-local by default.

4. Other people at other times would hate the default-block-local
behavior. They depend on the existing behavior so as not to
have to create unnecessary variables and do extraneous
assignments.

  item = nil
  x.each do |item|
    if condition(item)
        break
    end
  end

  puts item    # This one caused the failure
  # item = nil above is needed, or item is unknown here

5. I still favor the symbol idea -- if a param is a symbol, then it
refers to the outer scope; if not, it's block-local. This will still
break old code, but I think it is more intuitive than the reverse
(which would not break old code). And if it's a symbol, and the
variable doesn't exist yet, then create it.

  x = 5                            # and y doesn't exist
  my_meth do | x, :y |
    x = 6
    y = 7
  end

  puts x              # 5  (unchanged)
  puts y              # 7  (new var)

Not *all* code would be broken anyhow... only that which
depended on this feature. If you're not doing an "implicit import
and export" of a variable, you're in good shape.

6. I suppose the only thing that the export method would save you
is having to define a variable before the block. That reminds me
too much of a variable declaration in this case (and Ruby does
not have those, as such).

The reason is that we expect "the stuff the block does" to be
understandable from reading the block. But its behavior is
radically changed by something *before* the block. (Yes, I know
that all locals are available inside the block -- that's not my point --
the point is that I just forgot the point.)

Anyway, I guess #5 above is still my favorite solution... but I was
intrigued by the idea of a variable being "exported" from a scope.

Thanks for replying,
Hal


In This Thread