[#5218] Ruby Book Eng tl, ch1 question — Jon Babcock <jon@...>

13 messages 2000/10/02

[#5404] Object.foo, setters and so on — "Hal E. Fulton" <hal9000@...>

OK, here is what I think I know.

14 messages 2000/10/11

[#5425] Ruby Book Eng. tl, 9.8.11 -- seishitsu ? — Jon Babcock <jon@...>

18 messages 2000/10/11
[#5427] RE: Ruby Book Eng. tl, 9.8.11 -- seishitsu ? — OZAWA -Crouton- Sakuro <crouton@...> 2000/10/11

At Thu, 12 Oct 2000 03:49:46 +0900,

[#5429] Re: Ruby Book Eng. tl, 9.8.11 -- seishitsu ? — Jon Babcock <jon@...> 2000/10/11

Thanks for the input.

[#5432] Re: Ruby Book Eng. tl, 9.8.11 -- seishitsu ? — Yasushi Shoji <yashi@...> 2000/10/11

At Thu, 12 Oct 2000 04:53:41 +0900,

[#5516] Re: Some newbye question — ts <decoux@...>

>>>>> "D" == Davide Marchignoli <marchign@di.unipi.it> writes:

80 messages 2000/10/13
[#5531] Re: Some newbye question — matz@... (Yukihiro Matsumoto) 2000/10/14

Hi,

[#5544] Re: Some newbye question — Davide Marchignoli <marchign@...> 2000/10/15

On Sat, 14 Oct 2000, Yukihiro Matsumoto wrote:

[#5576] Re: local variables (nested, in-block, parameters, etc.) — Dave Thomas <Dave@...> 2000/10/16

matz@zetabits.com (Yukihiro Matsumoto) writes:

[#5617] Re: local variables (nested, in-block, parameters, etc.) — "Brian F. Feldman" <green@...> 2000/10/16

Dave Thomas <Dave@thomases.com> wrote:

[#5705] Dynamic languages, SWOT ? — Hugh Sasse Staff Elec Eng <hgs@...>

There has been discussion on this list/group from time to time about

16 messages 2000/10/20
[#5712] Re: Dynamic languages, SWOT ? — Charles Hixson <charleshixsn@...> 2000/10/20

Hugh Sasse Staff Elec Eng wrote:

[#5882] [RFC] Towards a new synchronisation primitive — hipster <hipster@...4all.nl>

Hello fellow rubyists,

21 messages 2000/10/26

[ruby-talk:5548] Re: Some newbye question

From: "Guy N. Hurst" <gnhurst@...>
Date: 2000-10-15 14:40:26 UTC
List: ruby-talk #5548

ts wrote:
> 
> >>>>> "G" == Guy N Hurst <gnhurst@hurstlinks.com> writes:
> 
> G> Or if there are conflicts, maybe '%' would be better.
> 
> pigeon% ruby -e '%a'
> -e:1: unknown type of %string
> pigeon%
> 

Actually, I realized later that using '%' would conflict
with the %string constructs such as %w( ), %x( ), etc.

I have another idea, though. 

Let me recall matz:
> |>   (a) I don't like variable overriding, especially in declaration-less
> |>       language like Ruby.
> |>
> |>   (b) since blocks were introduced for iteration originally, I want
> |>       any assignables can be block parameters.
> 
> 3 possible solution in my mind for the future:
> 
>   (1) local variables in the block parameters be valid only in the
>       surrounding block.  I think Davide proposed this one.  This
>       violates (a), and introduces incompatibility (small?).  This is
>       not perfect since the problem remains for non parameter local
>       variables.
> 

So, to offer more thoughts for those interested, I would like to reconcile
(1) to (a) and (b) - within the limits of my understanding, that is.

- certain local variables in the block parameters can be restricted to block (1)
- regular local variable act as usual (b)

A simple syntactical sugar(?) (such as a trailing tilde '~') could be used 
to denote new block variables that get initialized to the variable of its
namesake. (e.g.  |x~| would mean create a new block variable x with default
value same as x if local variable x exists, whereas |x| retains current meaning).

It would say to the average person "don't keep changes to this var after the block ends".

Example:
i = 2; iterator(5) {|i| i += 1 }
p i 	-> 7
i = 2; iterator(5) {|i~| i += 1 }
p i	-> 2
p i~	-> not defined

They could be mixed:

i = 2; x = "abc"; iterator(5) {|i~,x| i+=1; x="xyz"}
p i	-> 2
p x	-> "xyz"

They can't be used for non-parameters, but that is not really so bad, since
the original behavior can be kept:

i = 2; x = "abc"; iterator(5) {|i~,x,r~| i+=1; x="xyz"; q="keep"; r="pitch"}
p i	-> 2
p x	-> "xyz"
p q	-> "keep"
p r	-> undefined

They should handle nesting:

(ts mentioned nesting before I sent this out...)

	   a = 24 # local variable
  	   iterator(5){|a~, b|
     		b # dynamic variable created
		a # here a is new block variable with value 24 
		b = 12
 		block{|a~,b~| 
			b # block variable, has value 12
			a # block variable, has value 24
			b = 24
			a = 36 
		} # block scope ends;  
 		b # here b has the value 12 again
		a # here a has value 24 again
		a = 5
	   }
	   a # local variable has value 24 again
	   b # has value 12 (existing behavior)


Could this be implemented?

I have an interesting idea about it, but I am no compiler programmer.

I will wait for some responses before I mention more.


Meanwhile, I need to get some sleep.


Guy N. Hurst

-- 
HurstLinks Web Development    http://www.hurstlinks.com/
Norfolk, VA - (757)623-9688
PHP/MySQL - Ruby/Perl - HTML/Javascript

In This Thread