Self-similarity or closure in ruby

It seems
   In lisp, everything is expression
   In smalltalk, everything is object
   In Ruby,
       everything is an expression
       everything is an object

This kind of characteristic is called closure.
It is also a kind of self-similarity.

It seems self-similarity or closure will give ruby many benefits.

But what's the benefits we can get? I appreciate your opinions.

Thanks in advance

uncutstone

···

--
Posted via http://www.ruby-forum.com/.

It seems
   In lisp, everything is expression
   In smalltalk, everything is object
   In Ruby,
       everything is an expression
       everything is an object

This kind of characteristic is called closure.

I am afraid that is not correct (c.f.
Closure (computer programming) - Wikipedia if you are
interested)
Cheers
Robert

It is also a kind of self-similarity.

It seems self-similarity or closure will give ruby many benefits.

···

On 6/17/06, uncutstone wu <uncutstone@sina.com> wrote:

But what's the benefits we can get? I appreciate your opinions.

Thanks in advance

uncutstone

--
Posted via http://www.ruby-forum.com/\.

--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein

Everything is an object

- there's a certain set of methods that can be invoked on any
instance, like #to_s, #hash etc. See Obejct.instance_methods()

- anything can be stored in a variable (not like Java for example
where you cannot store POD values in a variable of type
java.lang.Object)

- generally every value can be treated in a generic way

Everything is an expression

- I don't see that much advantage from this in a language like Ruby,
probably one of the most useful features together with the fact that
everything is an object is that you can chain values through boolean
operators like x = a || b || c.

Just some thoughts

Kind regards

robert

···

2006/6/17, uncutstone wu <uncutstone@sina.com>:

It seems
   In lisp, everything is expression
   In smalltalk, everything is object
   In Ruby,
       everything is an expression
       everything is an object

This kind of characteristic is called closure.
It is also a kind of self-similarity.

It seems self-similarity or closure will give ruby many benefits.

But what's the benefits we can get? I appreciate your opinions.

--
Have a look: Robert K. | Flickr

uncutstone wu <uncutstone@sina.com> writes:

It seems
   In lisp, everything is expression
   In smalltalk, everything is object
   In Ruby,
       everything is an expression
       everything is an object

This kind of characteristic is called closure.
It is also a kind of self-similarity.

In Common Lisp, everything is an object too.
In Smalltalk, everything is an expression too (but you need ^ to return values).

···

uncutstone

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org

Robert Dober wrote:

I am afraid that is not correct (c.f.
Closure (computer programming) - Wikipedia if you are
interested)
Cheers
Robert

I took another meaning of the word 'closure'. If you are interested,
please take a look at Closure (mathematics) instead of Closure (computer
science) at rubygarden. You can also take a look at book SICP(structure
and interpretation of computer programs) chapter 2 section 2.

Regards

uncutstone

···

--
Posted via http://www.ruby-forum.com/\.

Beware the Wikipedia, my son!
   The editors' bite, the facts which clash!
Beware the disambiguation page, and shun
   the frumious Bandersnatch!

(If I were more creative, I'd finish off the whole poem, but you get the point)

There's a more relevant meaning of 'closure' given here:

This is more the sense which I think the original post was meant, and seems intuitively correct in that sense: in Ruby, any operation on an object results in an object. This is not true in the general case for OO languages (consider int vs. Integer in Java, or pointers in C++).

I'm not as sure that Ruby is closed with respect to expressions in an interesting way. The not-so-interesting case that I can imagine is that any valid expression in a language results in a (possibly trivial or empty) valid expression in that language, which seems to me like a necessary condition to have a useful programming language in the first place. Maybe this definition of expression is too broad?

matthew smillie.

···

On Jun 17, 2006, at 13:17, Robert Dober wrote:

On 6/17/06, uncutstone wu <uncutstone@sina.com> wrote:

It seems
   In lisp, everything is expression
   In smalltalk, everything is object
   In Ruby,
       everything is an expression
       everything is an object

This kind of characteristic is called closure.

I am afraid that is not correct (c.f.
Closure (computer programming) - Wikipedia if you are
interested)
Cheers
Robert

It is also a kind of self-similarity.

Robert Klemme wrote:

···

2006/6/17, uncutstone wu <uncutstone@sina.com>:

It seems self-similarity or closure will give ruby many benefits.

But what's the benefits we can get? I appreciate your opinions.

Everything is an object

- there's a certain set of methods that can be invoked on any
instance, like #to_s, #hash etc. See Obejct.instance_methods()

- anything can be stored in a variable (not like Java for example
where you cannot store POD values in a variable of type
java.lang.Object)

- generally every value can be treated in a generic way

Everything is an expression

- I don't see that much advantage from this in a language like Ruby,
probably one of the most useful features together with the fact that
everything is an object is that you can chain values through boolean
operators like x = a || b || c.

Just some thoughts

Kind regards

robert

Very thanks.

uncutstone

--
Posted via http://www.ruby-forum.com/\.

- generally every value can be treated in a generic way

Everything is an expression

- I don't see that much advantage from this in a language like Ruby,
probably one of the most useful features together with the fact that
everything is an object is that you can chain values through boolean
operators like x = a || b || c.

The distinction between statements and expressions is somewhat
artificial. The biggest benefit is that you don't have to care. You
can assign the value of anything to any variable, anytime.

···

On 6/17/06, Robert Klemme <shortcutter@googlemail.com> wrote:

Just some thoughts

Kind regards

robert

--
Have a look: Robert K. | Flickr

--
- Simen

uncutstone wu wrote:

science) at rubygarden.

Sorry, not rubygarden but wikipedia

···

--
Posted via http://www.ruby-forum.com/\.

>>
>> It seems
>> In lisp, everything is expression
>> In smalltalk, everything is object
>> In Ruby,
>> everything is an expression
>> everything is an object
>>
>> This kind of characteristic is called closure.
>
> I am afraid that is not correct (c.f.
> Closure (computer programming) - Wikipedia if you are
> interested)
> Cheers
> Robert
>
> It is also a kind of self-similarity.

Beware the Wikipedia, my son!

Hey I just defended you in the other thread, daddy!

   The editors' bite, the facts which clash!

Beware the disambiguation page, and shun
   the frumious Bandersnatch!

(If I were more creative, I'd finish off the whole poem, but you get
the point)

There's a more relevant meaning of 'closure' given here:
Closure (mathematics) - Wikipedia

I see what OP meant, thanks for the link, but Wikipedia, the free encyclopedia

/Closure_%28computer_science%29 is not a bad description of what a closure
is in the context of ruby.

This is more the sense which I think the original post was meant, and

seems intuitively correct in that sense: in Ruby, any operation on an
object results in an object. This is not true in the general case
for OO languages (consider int vs. Integer in Java, or pointers in C++).

The mathematical way to say ruby is consistent in concept, I agree.

I'm not as sure that Ruby is closed with respect to expressions in an

interesting way. The not-so-interesting case that I can imagine is
that any valid expression in a language results in a (possibly
trivial or empty) valid expression in that language, which seems to
me like a necessary condition to have a useful programming language
in the first place. Maybe this definition of expression is too broad?

matthew smillie.

Well I still guess OP ment the consistentcy, in that brings me to the

benefits.

As everything is an object there are only methods, look e.g. at these code
snippets in ruby first
2.3.to_i
"12".to_i
"12".to_i(16)
42.to_s
and now in python
str(12.5)
int(1.3)
int(42)
int(42,16)

Now we can also easily extend or redefine methods on the built in classes
irb(main):006:0> class Fixnum
irb(main):007:1> def +(x);0;end
irb(main):008:1> end
=> nil
irb(main):009:0> 3+2
=> 0
I choose this stupid example to show the danger which comes with the power.

I am sure others will come up with much more advantages.

Cheers
Robert

···

On 6/17/06, Matthew Smillie <M.B.Smillie@sms.ed.ac.uk> wrote:

On Jun 17, 2006, at 13:17, Robert Dober wrote:
> On 6/17/06, uncutstone wu <uncutstone@sina.com> wrote:

--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein