Is it behaving strange?

Hi,

···

In message "Re: is it behaving strange ?" on Fri, 16 Feb 2007 04:45:38 +0900, dblack@wobblini.net writes:

irb(main):001:0> a = [9,5]
=> [9, 5]
irb(main):002:0> b = 9,5,6
=> [9, 5, 6]
irb(main):003:0> b = *a, 6
=> [9, 5]
irb(main):004:0> b = [*a, 6]
=> [9, 5, 6]

I don't really understand the third one. I would have expected it to
be the same as the second. I haven't tried a more recent 1.9 version,
though -- maybe it's been changed.

You don't understand because it's a bug. I will fix it soon.

              matz.

definitely, it seems so natural using

= *a,b

and this gives the feel of ruby.

isn't it ?

···

On 2/16/07, Robert Dober <robert.dober@gmail.com> wrote:

On 2/16/07, Peña, Botp <botp@delmonte-phil.com> wrote:
> fr: sur max [mailto:sur.max@gmail.com] :
> # b = [*a,6] # => [9,5,6] ----- false, compile error
> # b = *a,6 # => [9,5,6] ----- false, compile error
>
> pls be careful. "*" op will splat. so here ruby is just telling/policing
you not too.
>
> I always treat splat op as a black hole. this way i make less mistakes.
>
> eg
>
> so this is allowed,
>
> irb(main):050:0> b,*a=1,2,3,4
> => [1, 2, 3, 4]
> irb(main):052:0> a
> => [2, 3, 4]
>
> this one is not,
>
> irb(main):053:0> b,*a,c=1,2,3,4
> SyntaxError: compile error
> (irb):53: syntax error, unexpected ',', expecting '=' b,*a,c=1,2,3,4
> irb(main):054:0>
>
> ruby, is telling me that "*a" is a blackhole. The c does "not matter".
Botp

this is a very nice analogy, however it does only hold for the LHS
i.e. assignment target and formal parameter lists.
On the LHS a splatted expression is an *infinite* consumer a blackhole :wink:
On the RHS a splatted expression is a *finite* producer though.
I see no reason why ..., *a, ... should be forbidden on the RHS.
to ... = *(a + [b])
I'd prefer
... = *a, b

Side note to David:
after a night of consideration I do not believe that there any
syntactical problems
the splat operator already being allowed in front of parenthesis.
>
> so is this one,
>
> irb(main):056:0> *a
> SyntaxError: compile error
> (irb):56: syntax error, unexpected '\n', expecting '='
>
> that's a blackhole without a hole or opening. feed it :slight_smile:
as mentioned above we are in the producer case here
> again, another stupid blackhole reasoning.
I would not go that far :wink:
>
> nonetheless, splat is a very sweet yet too powerful operator.
I feel that splat op digress oo-ness. But i believe it's not oo for
oo's sake. It's solving problems and discovering brilliant solutions.
Ruby does it w ease and fun. Sometimes, i feel ruby will trend toward
object and method unification, wherein objects can be methods and vice
versa. arggh, like matter <==> energy. maybe, a superproc or
superlamdba in the future... i'll stop now :slight_smile:
You might have a point though :wink:
>
> drive w caution, (black)holes ahead.
>
> sorry for the long post fr a nuby.
> kind regards -botp
>
Cheers
Robert

--
We have not succeeded in answering all of our questions.
In fact, in some ways, we are more confused than ever.
But we feel we are confused on a higher level and about more important
things.
-Anonymous

--
sur
http://expressica.com

Hi --

···

On Fri, 16 Feb 2007, Yukihiro Matsumoto wrote:

Hi,

In message "Re: is it behaving strange ?" > on Fri, 16 Feb 2007 04:45:38 +0900, dblack@wobblini.net writes:

>irb(main):001:0> a = [9,5]
>=> [9, 5]
>irb(main):002:0> b = 9,5,6
>=> [9, 5, 6]
>irb(main):003:0> b = *a, 6
>=> [9, 5]
>irb(main):004:0> b = [*a, 6]
>=> [9, 5, 6]
>
>I don't really understand the third one. I would have expected it to
>be the same as the second. I haven't tried a more recent 1.9 version,
>though -- maybe it's been changed.

You don't understand because it's a bug. I will fix it soon.

Cool, thanks.

David

--
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black\)
    (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf\)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)

Hi --

definitely, it seems so natural using

= *a,b

and this gives the feel of ruby.

isn't it ?

A bug report has been submitted for this:

irb(main):001:0> a = [1,2]
=> [1, 2]
irb(main):002:0> b = *a, 3
=> [1, 2]

in 1.9.

David

···

On Fri, 16 Feb 2007, sur max wrote:

--
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black\)
    (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf\)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)

fr: sur max [mailto:sur.max@gmail.com]
# definitely, it seems so natural using
# = *a,b

indeed, as robert pointed out.
but the magic generally leans towards, producing (and thereby questioning) *a, like

def x
  *a
end

or

def x
   1,2,3
end

so what does *a produce, or 1,2,3? an array, a list, or an unarrayed array (to quote dblack)? those are just names, but what is it really, what are its properties/methods/etc?

# and this gives the feel of ruby. isn't it ?

i'm not sure (because the magic tends to fall on hole, a cul de sac), maybe because i seldom use it, ... only matz knows.

kind regards -botp

fr: sur max [mailto:sur.max@gmail.com]
# definitely, it seems so natural using
# = *a,b

indeed, as robert pointed out.
but the magic generally leans towards, producing (and thereby questioning) *a, like

def x
  *a
end

or

def x
   1,2,3
end

so what does *a produce, or 1,2,3? an array, a list, or an unarrayed array (to quote dblack)? those are just names, but what is it really, what are its properties/methods/etc?

# and this gives the feel of ruby. isn't it ?

i'm not sure (because the magic tends to fall on hole, a cul de sac), maybe because i seldom use it, ... only matz knows.

Take a look at these

instruments = {'trombones' => 1, 'clarinets' => 2}
p instruments.to_a

[["trombones", 1], ["clarinets", 2]]

p *instruments

["trombones", 1]
["clarinets", 2]

Normally * uses to_a or to_ary, but certainly its more devious than it
appears. And where exactly is this operator defined in ruby source
tree? eval.c ?

···

On 2/17/07, Peña, Botp <botp@delmonte-phil.com> wrote:

--
gnufied
-----------
There was only one Road; that it was like a great river: its springs
were at every doorstep, and every path was its tributary.
http://people.inxsasia.com/~hemant

I really start to love Smalltalk's syntax more and more...
Maybe sometimes less is more.
Than OTOH what fun Quiz113 was!
But fun can be dangerous I guess :frowning:

Cheers
Robert

···

On 2/17/07, hemant <gethemant@gmail.com> wrote:

On 2/17/07, Peña, Botp <botp@delmonte-phil.com> wrote:
> fr: sur max [mailto:sur.max@gmail.com]
> # definitely, it seems so natural using
> # = *a,b
>
> indeed, as robert pointed out.
> but the magic generally leans towards, producing (and thereby questioning) *a, like
>
> def x
> *a
> end
>
> or
>
> def x
> 1,2,3
> end
>
> so what does *a produce, or 1,2,3? an array, a list, or an unarrayed array (to quote dblack)? those are just names, but what is it really, what are its properties/methods/etc?
>
> # and this gives the feel of ruby. isn't it ?
>
> i'm not sure (because the magic tends to fall on hole, a cul de sac), maybe because i seldom use it, ... only matz knows.

Take a look at these

>> instruments = {'trombones' => 1, 'clarinets' => 2}
>> p instruments.to_a
[["trombones", 1], ["clarinets", 2]]
>> p *instruments
["trombones", 1]
["clarinets", 2]

Normally * uses to_a or to_ary, but certainly its more devious than it
appears. And where exactly is this operator defined in ruby source
tree? eval.c ?

--
gnufied
-----------
There was only one Road; that it was like a great river: its springs
were at every doorstep, and every path was its tributary.
http://people.inxsasia.com/~hemant

--
We have not succeeded in answering all of our questions.
In fact, in some ways, we are more confused than ever.
But we feel we are confused on a higher level and about more important things.
-Anonymous

Hi --

···

On Sat, 17 Feb 2007, hemant wrote:

Take a look at these

instruments = {'trombones' => 1, 'clarinets' => 2}
p instruments.to_a

[["trombones", 1], ["clarinets", 2]]

p *instruments

["trombones", 1]
["clarinets", 2]

Normally * uses to_a or to_ary, but certainly its more devious than it
appears. And where exactly is this operator defined in ruby source
tree? eval.c ?

I'm not sure I'm seeing what you're getting at in your example. Isn't
that what you'd expect it to do?

David

--
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black\)
    (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf\)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)