Ruby-dev summary 17252-17356

Hi,

···

In message “Re: a new block parameter/variable notation (Re: ruby-dev summary 17252-17356)” on 02/06/12, Tanaka Akira akr@m17n.org writes:

(b-1) “<…>” that takes local variables only; they are in-block
local. In addition, it follows basic rules of argument
passing, even optinal argumen may be allowed.

Is a block parameter allowed as {<&c> …} ?

I want to allow them. But I’ve not yet decided.

						matz.

Japanese is actually similar to English, in that respect!
We’ve 26 lowercase and 26 uppercase (similar but different symbols with
the same pronounciation), while they have 46 hiragana and 46 katakana
(when you ignore the voicing marks and such).

It’s just the addition of kanji that complicates things… :slight_smile:

···

On Wed, Jun 12, 2002 at 03:14:31PM +0900, Hal E. Fulton wrote:

Why you guys don’t read Japanese?

Heh heh… when you reduce it to an alphabet of 26 characters,
I will be more inclined to learn it.


Evan Martin
martine@cs.washington.edu
http://neugierig.org

Hi,

Not wanting to flog a dead horse, but I just wonder what the final word
on the :a notation was?

Like |a,:b,c| (as in 5555), |a,b~,c| (as in 5592), or |a,{b},c| (as in
42266)?

I don’t like them. From my observation, block parameters used as
either iteration variables or closure arguments, not usually mixed.
:a notation and the like forces extra cost to one of the major usages,
allowing unimportant mixing. I felt it’s good to prepare independent
(and hopefully equally readable) notations for each major usage.

Maybe I have misunderstood some of the other approaches, but I get the
sinking feeling that the order that the iterator methods yield the
arguments have bearing on what I can do on the block side. I see that
this problem is really defined away by the constraint, but I fear that
this decision can preempt some useful, future usages. (Though I can’t
think of any good examples now…)

I’m not in hurry at all for this issue. [ruby-talk:5555] was two
years ago.

						matz.
···

In message “Re: a new block parameter/variable notation (Re: ruby-dev summary 17252-17356)” on 02/06/12, Kent Dahl kentda@stud.ntnu.no writes:

Man, it took me hours to write this mail.

Thanks very much for writing this, Matz. I am understanding
it better now.

I have printed out this message so I can study it and think
about it more. I think perhaps I will frame it and put it
on the wall by my bed.

Indeed, Matz’s English is incredibly good for a non-native
English speaker.

Why you guys don’t read Japanese?

Heh heh… when you reduce it to an alphabet of 26 characters,
I will be more inclined to learn it.

It’s embarassing for me to have a Japanese last name but not
be able to speak much of it (as Matz mentioned being born
in an English-speaking country: that’s what happened to me
and look at what happened! At least he can manage to speak
both).

I can kinda muddle along in romaji – I can make out two, maybe
three kanji – so I was wondering: I know that Babel Fish will
translate (badly) from Japanese to English, but is there something
out there that will translate from Japanese to Japanese,
specifically from hiragana/katakana/kanji to romaji?

I know the Japanese version of Windows98 has some IME support
that will let you key in romaji and turn it into hiragana/katakana
and kanji … I just need something that does it in reverse so
I can read the romaji (and look up in a Japanese-to-English
dictionary if I don’t know the word).

I’ll probably be in Japan for two weeks at the end of July/beginning
of August.

– Dossy

···

On 2002.06.12, Hal E. Fulton hal9000@hypermetrics.com wrote:


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

Hi,

···

In message “Re: ruby-dev summary 17252-17356” on 02/06/12, Dossy dossy@panoptic.com writes:

Or, how about:

5.times do(a) a=gets; print a end

To me, that’s the least surprise. It makes “a” look like a
defined parameter of the do “method” so to speak.

Unfortunately, yacc doesn’t like this rule. It causes conflicts.

						matz.

I am not sure - if I am reading this correctly but it used to be
possible to create Procs with default arguments via Method
objects, now (mswin today's cvs) this segfaults.

This is not related, in svalue_to_avalue() try to change

    if (NIL_P(v)) return rb_ary_new2(0);

with

   if (NIL_P(v) || v == Qundef) return rb_ary_new2(0);

Guy Decoux

“Tobias Reif” tobiasreif@pinkjuice.com wrote in

And I was wrong. This rule is the single biggest design flaw in
Ruby.

Perhaps Rite / Ruby 2+ is a chance to fix this and similiar issues?

I think sometimes, non-backwards-compatible changes are OK, if done in a
transparent way.
People can continue to use Ruby 2- programs with 2- interpreter
versions, and update to 2+ versions as soon as the need arises, by
making some changes to the existing programs.

Maybe it is actually possible to mix new and old behavior within
a single interpreter even in the 1.7 - 1.8 series reminiscent to
the ``from future import’’ mechanism in the Python world,
where they seem to have a lot of experience in overcoming single
biggest design flaws;-). Irony aside, Python actually seem to be
rather successful in introducing incompatible language changes.

A probably brain dead idea coming to my mind is changing the
value of a (or more then one?) global variable(s) appropriately.
For example, before and after importing (requiring) a library,
you would to set

$behavior = ‘future’
require ‘new_fancy_lib’

back to the old way

$behavior = `backward’ # ‘redneck’ you name it …

/Christoph

Hi,

The ‘:=’ is nice, but it will become more complicated if later you decide to
add variable initialization (you can not initialize a block variable with
‘:=’ (as I understand(?) it) because it is assigned in every iteration).

I’m not sure I got your idea. As long as the initialization is in the
iteration body, it should be assigned in every iteration. Maybe you
want:

let{<p=list> 5.times do p p; p=p.next end}

or

let{p:=list; 5.times do p p; p=p.next end}

? But are they really useful?

And with my proposals I will not make examples because I know you don’t like
them :wink:

Show me. I’m always open, and but still deserve the right to
like/dislike ideas. :wink:

						matz.
···

In message “Re: ruby-dev summary 17252-17356” on 02/06/13, Carlos angus@quovadis.com.ar writes:

Hi,

Matz, what about making this distinction more general than just
block-local vs. method local? That is, always be able to use := to
create a new binding rather than modifying an existing one. So, if
you had

akr@m17n.org foresaw your idea in [ruby-dev:17346] a week ago.

Too lispy?

Probably. Variable shadowing is not encouraged at all in Ruby.

						matz.
···

In message “Re: a new block parameter/variable notation (Re: ruby-dev summary 17252-17356)” on 02/06/13, Avi Bryant avi@beta4.com writes:

Hello,

matz@ruby-lang.org (Yukihiro Matsumoto) wrote in message
news:1023845919.929356.32025.nullmailer@picachu.netlab.jp

(c-1) local variables assigned by “:=” are in-block variables,
otherwise they are method local variables. If you assigns to
an existing local variable, the variable is shadowed, and you
will probably be warned.

Matz, what about making this distinction more general than just
block-local vs. method local? That is, always be able to use := to
create a new binding rather than modifying an existing one. So, if
you had

def foo
x := 1
y := 2
myproc = lambda{p x, y}
x := 10
y = 20
myproc.call
end

#=> 1
#=> 20

Bindings would be scoped to thier closest enclosing method or block;
using = when no binding already existed for the variable would be the
same as using :=.

My main motivation for wanting this is to ease state management when
using continuations for backtracking - creating new bindings is
obviously safer here than mutating existing ones.
Avi

I agree about the relevance of that issue.

There is something I don’t understand however: aren’t you creating
a huge number of new bindings with := ? Specially considering the
fact that it is so easy to type := instead of =. Some people may
even prefer using := instead of =, overlooking some important
differences, just because := looks more like an assignment than a
comparison for equality.

def foo( stream, l )
x, msg, t = nil, nil, nil
for x in l do
# Using your generalized :=
msg := x.to_s()
t := Time.now
bar( stream, msg) do
stream << msg if (Time.now - t) <= 1
end
# versus today (with same apparent result):
msg = x.to_s()
t = Time.now
begin
local_msg = msg
local_t = t
bar( stream, msg) do
stream << msg if (Time.now - t) <= 1
end
end
# versus my own proposal: unbound
msg = x.to_s()
t = Time.now
bar( stream, msg) do
unbound msg, t # <===
stream << msg if (Time.now - t) <= 1
end
end
end

With my explicit “unbound” statement, the author is more explicit about
the fact that he/she wants some variables to be local to the block, and
that she/he also want these variables to be initialized with the value
of the same variable in the enclosing scope. The total number of bindings
would be the same as today I guess (or similar).

Nota: ‘do local x; xxx end’ would be similar to ‘do unbound x; xxx end’,
the diff is that with “local” x is initialized when the block is called,
versus when the block is created.

I understand that Ruby does not require explicit declaration of variables
and that this is considered a plus. However, “simple things should be
simple and complex ones possible”, and I feel like the need for “truly
local block param/var” and “initialized at block creation time local
block variables” signals that something complex/tricky is occurring…
well… just a feeling.

Yours,

Jean-Hugues

···

At 10:43 13/06/2002 +0900, you wrote:


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

All this talk of block local variables reminded me of a funny trick…

As you know, receivers in ruby cannot change their class? No become, etc.
Right?

Wrong:

#!/usr/bin/env ruby
a = proc { a = 1 }
puts "a is a #{a.class}"
a.call
puts “a is a #{a.class}”

– Nikodemus, fun & games

matz@ruby-lang.org (Yukihiro Matsumoto) writes:

I’m not in hurry at all for this issue. [ruby-talk:5555] was two
years ago.

Matz:

How hard would it be to issue a warning when a block parameter shadows
a local variable. Then we could simple say that in 1.10 it won’t be
supported; all block parameters are local. That would give folks a
year or so to change their code.

Dave

Hi,

···

In message “Japanese to Japanese translator?” on 02/06/12, Dossy dossy@panoptic.com writes:

I can kinda muddle along in romaji – I can make out two, maybe
three kanji – so I was wondering: I know that Babel Fish will
translate (badly) from Japanese to English, but is there something
out there that will translate from Japanese to Japanese,
specifically from hiragana/katakana/kanji to romaji?

There’s a tool named “kakasi”.

						matz.

This might be what you are looking for:

http://etext.lib.virginia.edu/cgi-local/breen/wwwjdic?9T

You can paste Japanese text or give a URL, and it will return a page
showing dictionary definitions for all the kanji. As a student of
Japanese, I’ve found it very useful for deciphering documents that are
otherwise above my reading level due to all the kanji.

···

On Wed, Jun 12, 2002 at 11:16:08PM +0900, Dossy wrote:

I can kinda muddle along in romaji – I can make out two, maybe
three kanji – so I was wondering: I know that Babel Fish will
translate (badly) from Japanese to English, but is there something
out there that will translate from Japanese to Japanese,
specifically from hiragana/katakana/kanji to romaji?

What if we could do this:

5.times.do(a) a=gets; print a end
^?

Or can you not name methods that shadow keywords?

– Dossy

···

On 2002.06.13, Yukihiro Matsumoto matz@ruby-lang.org wrote:

Hi,

In message “Re: ruby-dev summary 17252-17356” > on 02/06/12, Dossy dossy@panoptic.com writes:

Or, how about:

5.times do(a) a=gets; print a end

To me, that’s the least surprise. It makes “a” look like a
defined parameter of the do “method” so to speak.

Unfortunately, yacc doesn’t like this rule. It causes conflicts.


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

“ts” decoux@moulon.inra.fr wrote in

This is not related, in svalue_to_avalue() try to change

I am not sure about your definition of ``related’’ but replace

if (NIL_P(v)) return rb_ary_new2(0);

with

if (NIL_P(v) || v == Qundef) return rb_ary_new2(0);

and the segfault goes away…

Thanks,

/Christoph

Evan Martin wrote:

Why you guys don’t read Japanese?

Heh heh… when you reduce it to an alphabet of 26 characters,
I will be more inclined to learn it.

Japanese is actually similar to English, in that respect!
We’ve 26 lowercase and 26 uppercase (similar but different symbols with
the same pronounciation), while they have 46 hiragana and 46 katakana
(when you ignore the voicing marks and such).

It’s just the addition of kanji that complicates things… :slight_smile:

Ah, but there are so many homonyms in Japanese that it often takes the
Kanji to tell them apart. And the puns!

···

On Wed, Jun 12, 2002 at 03:14:31PM +0900, Hal E. Fulton wrote:

hello,
a)
just wondering if anybody here is successfully doing opengl
on os x with ruby? if so what are you using?

b)
is anybody here working on open sound control for ruby?
i’m thinking about doing it but won’t if somebody’s already at it.

thanks bunches,
c

I would like to raise the issue of programming style here. The
difference between = and := in a
large amount of code is far too easy to overlook. If this form of
notation is introduced then I think
we are going to find ourselves writing a lot of bugs.

Additionally the name: (trailing collon notation) is also easy to overlook.

Just my ha’pence but several languages have been tripped up with this
sort of ‘human error’, most
famously the NASA Fortran ‘.’ bug.

let{<p=list> 5.times do p p; p=p.next end}

or

let{p:=list; 5.times do p p; p=p.next end}

But in

let{a:=1; b:=2; obj.meth(a).meth(b) do ... end }

a and b are locals before I want them to be locals… I want them to be
locals in the iteration only. Yes, I don’t know if it’s useful, I am not an
expert programmer and sometimes lack some common sense ;).

By the way, it will be

let{ ... }  and  let ... end

or how?

Show me. I’m always open, and but still deserve the right to
like/dislike ideas. :wink:

Well, like others proposed too, the idea is to have a header for the block
that could be used to initialize variables. Like the first part in a
for( ; ; ).

5.times let p:=list do p p; p=p.next end

or

5.times let <p=list> do p p; p=p.next end

The only benefit is that it avoids excesive nesting… I use tabs for
indenting ;).