Block vars (some theory)

Hello all,

in different languages there is need to mark variables as
global/local, const/variable, integer/float and so on. there is
several methods to do this markup:

  1. in variable name. f.e. constants and global vars in ruby
    indicated by variable name: Array, $global

  2. by declararation. f.e. type declarators in C or Pascal

  3. by definition, i.e. declararion combinated with some action. as
    example - using ‘:=’ to declare var as local PLUS execute ‘=’

first is definitely better if kind of variable can’t be changed
while program grows; third - when there is only one kind of actions,
which can be combined with declaration

to mark vars as local to block we can use any of methods above. but
imho it is better to explicitly declare vars imported from outer
blocks:

a = 1
{
a = 2 # ruby prints warning - outer var used without explicit import
{
import a
a = 3 # OK - changing value of imported variable
{
local a # bad style - reusing outer variable name.
# suitable only for metaprogramming
a = 4
}
{ local a=4 } # same as above, but more suitable for one-liners
}
}

p a #=> 3

proposed style is a less cryptish than other variants and conforms
to principle of least surprise in my vision

···


Best regards,
Bulat mailto:bulatz@integ.ru

  a = 1
  {
    a = 2 # ruby prints warning - outer var used without explicit import

This is a new language ?

pigeon% ruby -e 'a = 1; { a = 2 }'
-e:1: odd number list for Hash
pigeon%

Guy Decoux

Hello Bulat,

Tuesday, October 08, 2002, 2:32:33 PM, you wrote:

to mark vars as local to block we can use any of methods above. but
imho it is better to explicitly declare vars imported from outer
blocks:

a = 1
{
a = 2 # ruby prints warning - outer var used without explicit import
{
import a
a = 3 # OK - changing value of imported variable

and, of course:

def collect(array)
method = proc { |x|
import a
a << x
}
a = []
array.map {|elem| method.call(elem)}
a
end

i.e. “a=[]” may be placed AFTER using “a” in inner block

···


Best regards,
Bulat mailto:bulatz@integ.ru

Hello ts,

Tuesday, October 08, 2002, 2:49:23 PM, you wrote:

a = 1
{
a = 2 # ruby prints warning - outer var used without explicit import

This is a new language ?

RRR - Ruby for Real pRogrammers :slight_smile:

···


Best regards,
Bulat mailto:bulatz@integ.ru

Hi –

a = 1
{
a = 2 # ruby prints warning - outer var used without explicit import

This is a new language ?

Get used to it. This guy is clearly here to stay. Every day it’s a
new language – Ruby du jour. And none of it has much to do with what
we unenlightened people insist on referring to as “Ruby”. Silly us.

Sigh. I’ve kill-filed him, but apparently the attempt to get rid of
even replies to him didn’t work. I’ll check my .procmailrc again.

And yes, I do know that this reply is going to the whole list. At
this point I don’t think mentioning this person as a problem is
terribly shocking. I do wish he’d find another language to troll
in… Perhaps he can try to convince the Java community to remove
explicit type declarations from the language, or try to get golfers to
use a pyramid-shaped ball, or something.

David

···

On Tue, 8 Oct 2002, ts wrote:


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3
work: blackdav@shu.edu | Seattle, WA, USA
Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com

Hello dblack,

Tuesday, October 08, 2002, 3:34:05 PM, you wrote:

Sigh. I’ve kill-filed him, but apparently the attempt to get rid of
even replies to him didn’t work. I’ll check my .procmailrc again.

and now is the best time to email me your preferred killer because my
next proposition will be equalizing $_ and self:

strlist.map{downcase}

like perlish:

map {lc} $strlist

···


Best regards,
Bulat mailto:bulatz@integ.ru

dblack@candle.superlink.net wrote:

Sigh. I’ve kill-filed him, but apparently the attempt to get rid of
even replies to him didn’t work. I’ll check my .procmailrc again.

I’m using Mozilla to read the Usenet newsgroup (comp.lang.ruby) instead
of being subscribed to the ruby-talk mailing list directly. Does anyone
know if there’s a “killfile” equivalent for Mozilla’s news reader? It’s
not jumping out at me. Barring that, do any of the other good news
clients for Linux have such a feature?

Perhaps he can try to … get golfers to use a pyramid-shaped ball,
or something.

Hrm… this might make it more fun to watch.

···

=====

Use your computer to help find a cure for cancer: http://members.ud.com/projects/cancer/

Yahoo IM: michael_s_campbell


Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com

slrn

for a lot a people, the best console newsreader. I used it a lot
back when I was following es.comp.linux.* (spanish linux hierarchy,
about 500 msg/day)

If you absolutely want X, I think KNews or pan should do the trick (but
I haven’t used them at all).

BTW, it’s funny that the random fortune cookie below was precisely this
one (slrn is partially implemented in S-Lang, its scripting engine)

···

On Tue, Oct 08, 2002 at 10:30:01PM +0900, Lyle Johnson wrote:

dblack@candle.superlink.net wrote:

Sigh. I’ve kill-filed him, but apparently the attempt to get rid of
even replies to him didn’t work. I’ll check my .procmailrc again.

I’m using Mozilla to read the Usenet newsgroup (comp.lang.ruby) instead
of being subscribed to the ruby-talk mailing list directly. Does anyone
know if there’s a “killfile” equivalent for Mozilla’s news reader? It’s
not jumping out at me. Barring that, do any of the other good news
clients for Linux have such a feature?


_ _

__ __ | | ___ _ __ ___ __ _ _ __
’_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

After 14 non-maintainer releases, I’m the S-Lang non-maintainer.
– Ray Dassen

This might sound wildly un-scientific, but I very much prefer matz’s
cautious approach, where features are added carefully and bad style
(such as the example you give) is discouraged by the language, to keeping adding
feature after feature to Ruby until it becomes "interpreted Smalltalk + Perl

  • CLU + Algol + Lisp + C++ + ??"

I won’t cite Victor Hugo, but its famous quotation applies, IMHO.

···

On Tue, Oct 08, 2002 at 08:04:12PM +0900, Bulat Ziganshin wrote:

Hello ts,

Tuesday, October 08, 2002, 2:49:23 PM, you wrote:

a = 1
{
a = 2 # ruby prints warning - outer var used without explicit import

This is a new language ?

RRR - Ruby for Real pRogrammers :slight_smile:


_ _

__ __ | | ___ _ __ ___ __ _ _ __
’_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

How do I type “for i in *.dvi do xdvi $i done” in a GUI?
– Discussion in comp.os.linux.misc on the intuitiveness of interfaces

Hi David and Guy,

I don’t quite understand why you both always react so negative to
everything Bulat writes. I don’t like many of his ideas and his
wordings, too, but at least he tries to offer different points of view.

For example to me it is much more natural to explicitely declare
that a block variable should be shared with an outer scope than to
do it the other way round. (I know it breaks the current behaviour,
but so does Matz’s proposal that block parameters should always
be treated as local variables.) And using an explicit keyword is
much more readable than the proposed := syntax, that says
absolutely nothing to me (sorry matz).

So why shouldn’t Bulat be allowed to discuss topics like this?

Regards,
Pit

···

On 8 Oct 2002, at 20:34, dblack@candle.superlink.net wrote:

Hi –

On Tue, 8 Oct 2002, ts wrote:

a = 1
{
a = 2 # ruby prints warning - outer var used without
explicit import

This is a new language ?

Get used to it. This guy is clearly here to stay. Every day it’s a
new language – Ruby du jour. And none of it has much to do with what
we unenlightened people insist on referring to as “Ruby”. Silly us.

Sigh. I’ve kill-filed him, but apparently the attempt to get rid of
even replies to him didn’t work. I’ll check my .procmailrc again.

And yes, I do know that this reply is going to the whole list. At
this point I don’t think mentioning this person as a problem is
terribly shocking. I do wish he’d find another language to troll
in… Perhaps he can try to convince the Java community to remove
explicit type declarations from the language, or try to get golfers to
use a pyramid-shaped ball, or something.

David


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3 work:
blackdav@shu.edu | Seattle, WA, USA Web:
http://pirate.shu.edu/~blackdav | http://www.rubyconf.com

strlist.map{downcase}
like perlish:
map {lc} $strlist

pigeon% more ToDo
[...]
* discourage use of symbol variables (e.g. $/, etc.) in manual
* discourage use of Perlish features by giving warnings.
[...]
pigeon%

I hope that you know that it exist a mailing-list archive at

  http://www.ruby-talk.org/

Perhaps, you can take look at it before trying to give always *old*
suggestions.

Guy Decoux

Hi –

This might sound wildly un-scientific, but I very much prefer matz’s
cautious approach, where features are added carefully and bad style
(such as the example you give) is discouraged by the language, to
keeping adding feature after feature to Ruby until it becomes
"interpreted Smalltalk + Perl + CLU + Algol + Lisp + C++ + ??"

I won’t cite Victor Hugo, but its famous quotation applies, IMHO.

You mean it was Victor Hugo who wrote:

“I would like to evolve FROM Perl, Java and C++ rather than TO Perl,
Java and C++.”

as “Anonymous” on Ruby Garden? :slight_smile:

(Not that P, J, or C++ is the kind of meaningless pastiche we’re
apparently supposed to wish Ruby were being turned into…)

David

···


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3
work: blackdav@shu.edu | Seattle, WA, USA
Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com

“Pit Capitain” wrote

Hi David and Guy,

I don’t quite understand why you both always react so negative to
everything Bulat writes. I don’t like many of his ideas and his
wordings, too, but at least he tries to offer different points of view.

Actually I don’t even mind his wording (he probably makes
me feel better about my own fou-pas;-) - if one feels that
he is OT, inappropriate, whatever … one can always ignore
his posting (and replies) - however by doing so one might miss
out on occasionally interesting posts (imho;-) and replies
(e.g. Matz thoughts on overloading versus multiple-dispatch
and coercion) .

/Christoph

“Mauricio Fernández” batsman.geo@yahoo.com wrote in message
news:20021008163621.GE10843@student.ei.uni-stuttgart.de

This might sound wildly un-scientific, but I very much prefer matz’s
cautious approach, where features are added carefully and bad style
(such as the example you give) is discouraged by the language, to keeping
adding
feature after feature to Ruby until it becomes "interpreted Smalltalk +
Perl

  • CLU + Algol + Lisp + C++ + ??"

This is very true - but I also think it is reasonable to discuss new
features.

Good design is about considering a lot of different options. Most are
discarded but all contribute to illuminate the problem at hand. Often a more
general solution can be found this way.

I think it is not helpful to discourage suggestions to new Ruby features -
especially because we know they are not going to be implemented lightly.

That said, suggestions could be presented in one or a few mails. They need
not take up 90% of the bandwidth.

Mikkel

Hello Mauricio,

Tuesday, October 08, 2002, 8:36:26 PM, you wrote:

a = 1
{
a = 2 # ruby prints warning - outer var used without explicit import
This might sound wildly un-scientific, but I very much prefer matz’s
cautious approach, where features are added carefully and bad style
(such as the example you give) is discouraged by the language,

we can’t do more than printing a warning because another decision will break
compatibility. agree?

to keeping adding
feature after feature to Ruby until it becomes "interpreted Smalltalk + Perl

  • CLU + Algol + Lisp + C++ + ??"

you are named almost all ruby roots, except eiffel :slight_smile:

in this question, we have one unobvious but minimalistic feature. we
can keep the language in current state or mark this feature as
obsolete and give more structured and explicitly expressed way to do
same job. in the second variant my proposition imho is better than
using ‘:=’ to declare variable as local or using ‘:’ as prefix to
local variable names

of course, i prefer to use words in syntax, not cryptic symbols, as
you may be prefer

···


Best regards,
Bulat mailto:bulatz@integ.ru

Hello Pit,

Tuesday, October 08, 2002, 10:30:53 PM, you wrote:

For example to me it is much more natural to explicitely declare
that a block variable should be shared with an outer scope than to
do it the other way round. (I know it breaks the current behaviour,
but so does Matz’s proposal that block parameters should always
be treated as local variables.)

i considered all the problems and proposed a way which don’t breaks
anything but forces users to use new style as soon as possible

···


Best regards,
Bulat mailto:bulatz@integ.ru

Hi,

It seems so far that Ruby is usually attributed as taking the best
features of several other languages, but Pascal is not one of them.
To me, coming from the Basic->Fortran->C/C+±>Java->Tcl->Perl->Python
background, the first time I saw Ruby, I said, “it looks like Pascal”,
because of the “end” keywords, and “begin” and “do” (although they are
used differently in Ruby). Now, with the proposed “:=” block
operator, I think then Ruby really looks like Pascal.

Probably some other languages have syntax similar to Pascal, but at
least to me Pascal is the “major” language that is closest to Ruby in
syntax resemblance. (“Major” because at least some time ago the first
language taught in CS is Pascal; remember how Borland’s Turbo Pascal
got its popularity?) So can anyone say about Pascal’s influence on
Ruby? Maybe yes, not at all, or a little bit?

In addition, with “:=” as a new operator, is there any case where it
will be confused with “the symbol of ‘=’”? (Does it look like that in
Ruby, the punctuations begin to have too many different, unrelated
meanings, just as the “static” keyword in C++?)

Regards,

Bill

···

===============================================================================
Mauricio Fernández batsman.geo@yahoo.com wrote in message news:20021008163621.GE10843@student.ei.uni-stuttgart.de

This might sound wildly un-scientific, but I very much prefer matz’s
cautious approach, where features are added carefully and bad style
(such as the example you give) is discouraged by the language, to keeping adding
feature after feature to Ruby until it becomes "interpreted Smalltalk + Perl

  • CLU + Algol + Lisp + C++ + ??"

Hello ts,

Tuesday, October 08, 2002, 4:19:50 PM, you wrote:

strlist.map{downcase}
like perlish:
map {lc} $strlist

pigeon% more ToDo
[…]

  • discourage use of symbol variables (e.g. $/, etc.) in manual
  • discourage use of Perlish features by giving warnings.
    […]
    pigeon%

I hope that you know that it exist a mailing-list archive at

http://www.ruby-talk.org/

Perhaps, you can take look at it before trying to give always old
suggestions.

well, i must use more scientific language:

proposition of having several nested execution contents at the same
time :slight_smile: like the non-perlish “with” operator. now better? :slight_smile:

···


Best regards,
Bulat mailto:bulatz@integ.ru

Hi,

···

In message “Re: block vars (some theory)” on 02/10/09, “MikkelFJ” mikkelfj-anti-spam@bigfoot.com writes:

This is very true - but I also think it is reasonable to discuss new
features.

Agreed. I’m always open to new opinions, even though one out of
ten (or hundred maybe) is merged into Ruby.

Sorry if my attitude bothers list members.

						matz.