[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:6540] Re: Question about the behavior of write attributes in blocks

From: Dave Thomas <Dave@...>
Date: 2000-11-23 02:14:28 UTC
List: ruby-talk #6540
"Christoph Rippel" <chr@subdimension.com> writes:

> I lifted the following two lines from your (great) book - Page 285
> ************
> a = ["a","b","c","d"].
> a.collect! {|x| x+"!"}
> p a
> *************
> which has the output
> >> undefined method `a' for ["a", "b", "c", "d"]:Array (NameError)

You have an extraneous '.' at the end of the first line. Ruby says
"there should be a message name following the dot" so it continues
scanning and finds the 'a' at the start of the next line. But
[1,2,3].a isn't going to work, as arrays don't handle a message called
'a'.

> ************
> p 34.id == 34.id
> ************
> returns >> true  - in contrast to
> ************
> p "x".id  == "x".id
> ***************
> which returns >>false.  From this I would conclude that  ``34''  is
> semantically a singleton ``34'' object - but the interpreter barks at the
> following lines

Yes - numbers are effectively singletons, while string literals
generate a new string every time they are evaluated.

> *********
> module Withbla
> def bla
> end
> end
> x = 34
> x.extend(Withbla)
> ***********
> with the complain >> `extend_object': can't define singleton (TypeError)  -
> what is the semantic reasoning behind this?

My guess is that it's because Fixnums have value semantics, and hence
there is no real object behind each one. (They are objects, but they
don't have objects). This means that Ruby has nothing in memory to
hang the additional definitions onto. For the same reason, you can't
do 

  x = 23
  def x.ddd
  end

or
  class <<x
  end

However, Bignum's do have a real object, so this works

  x = 10**30
  def x.aaa
  end

It's the price we pay for having efficient integer representations and 
consistent integer semantics.


Dave

In This Thread