Some comments on new 1.9 features

T

Trans

Just looking at http://eigenclass.org/hiki.rb?Changes+in+Ruby+1.9.
Nicely done!

Comment on a couple things

1) ;; instead of end

It is possible to use ;; instead of end.

(1..100).inject do |s,x|
s+x
;; # => 5050

class Foo
def foo; "foo" end
;;
Foo.new.foo # => "foo"

What's the rationle here? I'd rather have a punctutation mark for 'do'
(yes, ':' again ;-p)

(1..100).inject: |s,x|
s+x
end # => 5050

Of course could have both:

(1..100).inject: |s,x|
s+x
;; # => 5050


2) Block local variables

Used as follows:

# {normal args; local variables}
d = 2
a = lambda{|;d| d = 1}
a.call()
d # => 2

When a variable is shadowed, ruby1.9 issues a warning:

-:2: warning: shadowing outer local variable - d

Come on. This stinkos. At some point I think you have to give it up and
allow a declaration.


3) Calling Procs without #call/#[]

You can now do:

a = lambda{|*b| b}
(a)(1,2) # => [1, 2]

Note that you need the parentheses:

a = lambda{|*b| b}
a(1,2) # => ERROR: (eval):2: compile error...

I know this has been deprecated, but what causes this not to work
exactly?


4) send doesn't call private methods anymore

ruby-talk:153672 It is still possible to call them with the newly
introduced #funcall method.

class Foo; private; def foo; end; end
Foo.new.funcall:)foo) # => nil
Foo.new.send:)foo) # => ERROR: private method `foo' called for
#<Foo:0xb7e0e540>

No #funcall please, I already have enough methods to make exceptions
for in BlankSlate/BasicObject. Use #instance_send instead. Thank you.


5) Class of singleton classes

singleton class inherits Class rather than its object's class

class X;end; x=X.new; class << x; self < X; end # => true

vs. (1.8)

class X;end; x=X.new; class << x; self < X; end # => nil

Is this example backwards? I'm confused. Please confirm.


6) Class variables are not inherited

ruby-dev:23808

class A; @@a = 1; end; class B < A; @@a end # => ERROR: (eval):1:
uninitialized ...

vs.

class A; @@a = 1; end; class B < A; @@a end # => 1

Love it! Thank you!


T.
 
N

nobuyoshi nakada

Hi,

At Fri, 4 Nov 2005 12:27:09 +0900,
Trans wrote in [ruby-talk:164082]:
What's the rationle here? I'd rather have a punctutation mark for 'do'
(yes, ':' again ;-p)

Why do you all want colon to overwork so much? ;)
 
D

David A. Black

Hi --

Hi,

At Fri, 4 Nov 2005 12:27:09 +0900,
Trans wrote in [ruby-talk:164082]:
What's the rationle here? I'd rather have a punctutation mark for 'do'
(yes, ':' again ;-p)

Why do you all want colon to overwork so much? ;)

Not all of us -- I'm still in the "conservative about new punctuation"
camp :)


David
 
B

Brian Schröder

Just looking at http://eigenclass.org/hiki.rb?Changes+in+Ruby+1.9.
Nicely done!

Comment on a couple things

1) ;; instead of end

It is possible to use ;; instead of end.

(1..100).inject do |s,x|
s+x
;; # =3D> 5050

class Foo
def foo; "foo" end
;;
Foo.new.foo # =3D> "foo"

What's the rationle here? I'd rather have a punctutation mark for 'do'
(yes, ':' again ;-p)

(1..100).inject: |s,x|
s+x
end # =3D> 5050

Of course could have both:

(1..100).inject: |s,x|
s+x
;; # =3D> 5050

Please don't add ;; thats

1) Sheer uglyness
2) Parses as a noop operation.

Brian
 
D

Dave Burt

Hi.
Hi --

Hi,

At Fri, 4 Nov 2005 12:27:09 +0900,
Trans wrote in [ruby-talk:164082]:
What's the rationle here? I'd rather have a punctutation mark for 'do'
(yes, ':' again ;-p)

Why do you all want colon to overwork so much? ;)

Not all of us -- I'm still in the "conservative about new punctuation"
camp :)

Aren't you the "conservative about most things" camp, David?

Do we all not like ";;"?

Cheers,
Dave
 
D

David A. Black

Hi --

Hi.
Hi --

Hi,

At Fri, 4 Nov 2005 12:27:09 +0900,
Trans wrote in [ruby-talk:164082]:
What's the rationle here? I'd rather have a punctutation mark for 'do'
(yes, ':' again ;-p)

Why do you all want colon to overwork so much? ;)

Not all of us -- I'm still in the "conservative about new punctuation"
camp :)

Aren't you the "conservative about most things" camp, David?

In Ruby development, or in life? :)
Do we all not like ";;"?

As a pointless no-op, it's great :) Is it really being considered as
a synonym for 'end'? I don't understand that at all.


David
 
K

Keith Fahlgren

Please don't add ;; thats

1) Sheer uglyness
2) Parses as a noop operation.

3) Going to confuse all the people coming from Lisp...
4) Really ugly


Keith
 
T

ts

K> 3) Going to confuse all the people coming from Lisp...

perhaps the persons coming from Caml will be happy ...

Guy Decoux
 
D

David A. Black

--8323328-1617525239-1131115704=:27223
Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-1617525239-1131115704=:27223"

This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.

--8323328-1617525239-1131115704=:27223
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

Hi --

3) Going to confuse all the people coming from Lisp...

And, closer to home, all the people coming from Ruby :)


David

--=20
David A. Black
(e-mail address removed)
--8323328-1617525239-1131115704=:27223--
--8323328-1617525239-1131115704=:27223--
 
A

Ara.T.Howard

K> 3) Going to confuse all the people coming from Lisp...

perhaps the persons coming from Caml will be happy ...

an people who don't like to move their fingers off of the

a s d f j k l ;

;-)

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| anything that contradicts experience and logic should be abandoned.
| -- h.h. the 14th dalai lama
===============================================================================
 
N

Nikolai Weibull

Trans said:
class Foo
def foo; "foo" end
;;
Foo.new.foo # =3D> "foo"

The funny thing about this example is that the whole point of having
";;" be "end" is that you could write

class Foo
def foo; "foo" ;;
end

right? Even so, I really don=E2=80=99t see the point, beyond being able =
to
write the following:

if something
if something_else
=E2=8B=AE
else
=E2=8B=AE
;;;;

other_statement

Sort of semi-pythonish or something.

nikolai

--=20
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
 
J

James Edward Gray II

The funny thing about this example is that the whole point of having
";;" be "end" is that you could write

class Foo
def foo; "foo" ;;
end

right?

To save one character?

class Foo
def foo; "foo" end
end

??? That parses today, right?

James Edward Gray II
 
D

Dale Martenson

Block local variables:

# {normal args; local variables}
d = 2
a = lambda{|;d| d = 1}
a.call()
d # => 2

I think embedding language specific items in comments is silly since
you then have no mechanism to comment them out. Create a directive for
these extensions so that they behave as other parts of the language and
abide by the standard placement rules. Such as, things that are
commented out are not executed and thus ignored.
 
D

Domenico De Felice

Nikolai Weibull wrote:
[CUT]
The funny thing about this example is that the whole point of having
";;" be "end" is that you could write

class Foo
def foo; "foo" ;;
end
Why don't use just : for single statement methods?

class Foo
def foo: "foo"
end

or in this case

class Foo:
def foo: "foo"

It sounds more expressive than do .. ;;
 
T

Trans

Dale said:
Block local variables:

# {normal args; local variables}
d = 2
a = lambda{|;d| d = 1}
a.call()
d # => 2

I think embedding language specific items in comments is silly since
you then have no mechanism to comment them out. Create a directive for
these extensions so that they behave as other parts of the language and
abide by the standard placement rules. Such as, things that are
commented out are not executed and thus ignored.

The comment was simply that, to indicate what the semi-colon is doing.
It has no function. Nonetheless to me its a good indication of a better
way:

d = 2
a = lambda{|d| local d = 1}
a.call()
d # => 2

Self commenting.

T.
 
T

Trans

Trans said:
The comment was simply that, to indicate what the semi-colon is doing.
It has no function. Nonetheless to me its a good indication of a better
way:

d = 2
a = lambda{|d| local d = 1}
a.call()
d # => 2

Self commenting.

Sorry, that should be

d = 2
a = lambda{|d| d = 1}
a.call()
d # => 2

Otherwise:

d = 2
a = lambda{|d| share d = 1}
a.call()
d # => 1

T.
 
N

Nikolai Weibull

James said:
On Nov 4, 2005, at 10:53 AM, Nikolai Weibull wrote:
To save one character?
=20
class Foo
def foo; "foo" end
end

Hey! I didn=E2=80=99t say that it was great. I just showed what I thoug=
ht was
the rationale behind having ;; in Ruby. Don't blame me for its
existance. Anyway, it=E2=80=99s not about saving one character. It=E2=80=
=99s about
having the ; have a better counterpart than end in this particular
instance. I didn=E2=80=99t say that it=E2=80=99s worth having just for t=
his, though.

nikolai

--=20
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
 
J

James Edward Gray II

James Edward Gray II wrote:



Hey! I didn=92t say that it was great. I just showed what I thought =20=
was
the rationale behind having ;; in Ruby. Don't blame me for its
existance.

I didn't mean to blame anyone. I was just trying to understand. :)
Anyway, it=92s not about saving one character. It=92s about
having the ; have a better counterpart than end in this particular
instance.

For a fitting counterpart, I like

class Foo
def foo() "foo" end
end

James Edward Gray II=
 
D

Domenico De Felice

Trans wrote:
[CUT]
The comment was simply that, to indicate what the semi-colon is doing.
It has no function. Nonetheless to me its a good indication of a better
way:

d = 2
a = lambda{|d| local d = 1}
a.call()
d # => 2

Self commenting.

IMO it would be even better to use a special character in front of the
name, such as for @instance and @@class attributes, to distinguish
among normal and local scope. However I can't think which character
would look less weird :)
maybe &d to make d local-scoped.
 
D

Dale Martenson

Sorry for the misunderstanding.

I like the "local" and "share" directives. That would make it clear.

Using too many special characters clutter the code and worsen
readability.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top