Some comments on new 1.9 features

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.

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? :wink:

···

--
Nobu Nakada

Please don't add ;; thats

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

Brian

···

On 04/11/05, Trans <transfire@gmail.com> wrote:

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

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/

Trans wrote:

  class Foo
    def foo; "foo" end
  ;;
  Foo.new.foo # => "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’t see the point, beyond being able to
write the following:

  if something
    if something_else
       ⋮
    else
       ⋮
    ;;;;

  other_statement

Sort of semi-pythonish or something.

        nikolai

···

--
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);}

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.

Hi --

···

On Fri, 4 Nov 2005, nobuyoshi nakada wrote:

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? :wink:

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

David

--
David A. Black
dblack@wobblini.net

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

Keith

···

On Friday 04 November 2005 8:43 am, Brian Schröder wrote:

Please don't add ;; thats

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

Quoting Brian Schröder <ruby.brian@gmail.com>:

Please don't add ;; thats

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

3) Gives me OCaml flashbacks.

(nobody wants that)

-mental

To save one character?

class Foo
   def foo; "foo" end
end

??? That parses today, right?

James Edward Gray II

···

On Nov 4, 2005, at 10:53 AM, Nikolai Weibull wrote:

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?

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 .. ;;

···

--
Domenico

Dale Martenson wrote:

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.

Hi.

David A. Black wrote:

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? :wink:

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

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

Do we all not like ";;"?

Cheers,
Dave

···

On Fri, 4 Nov 2005, nobuyoshi nakada wrote:

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

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

Guy Decoux

Hi --

···

On Fri, 4 Nov 2005, Keith Fahlgren wrote:

On Friday 04 November 2005 8:43 am, Brian Schröder wrote:

Please don't add ;; thats

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

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

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

David

--
David A. Black
dblack@wobblini.net

Quoting Domenico De Felice <defelicedomenico@gmail.com>:

   class Foo:
      def foo: "foo"

It sounds more expressive than do .. ;;

Serious question: why not permit multi-line bodies this way, by
lining up indention?

Not like Python, but more like Haskell, where using "layout" is
merely optional.

-mental

James Edward Gray II wrote:

···

On Nov 4, 2005, at 10:53 AM, Nikolai Weibull wrote:

> class Foo
> def foo; "foo" ;;
> end

To save one character?

class Foo
  def foo; "foo" end
end

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

        nikolai

--
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);}

Trans wrote:

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.

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 :slight_smile:
maybe &d to make d local-scoped.

···

--
Domenico

...

It sounds too much like Python. Python's syntax is one of the reasons
I don't use Python.

-austin

···

On 11/4/05, Domenico De Felice <defelicedomenico@gmail.com> wrote:

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 .. ;;

--
Austin Ziegler * halostatue@gmail.com
               * Alternate: austin@halostatue.ca

Hi --

Hi.

David A. Black wrote:

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? :wink:

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

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

In Ruby development, or in life? :slight_smile:

Do we all not like ";;"?

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

David

···

On Fri, 4 Nov 2005, Dave Burt wrote:

On Fri, 4 Nov 2005, nobuyoshi nakada wrote:

--
David A. Black
dblack@wobblini.net