[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

What sound does no duck make?

John Carter

5/6/2005 4:09:00 AM

12 Answers

Luke Graham

5/6/2005 4:23:00 AM

0

On 5/6/05, John Carter <john.carter@tait.co.nz> wrote:
> Imagine a flock of ducks in the sky. Listen.
> Now remove the ducks. Listen.
>
> What is the sound of no duck quacking?

Best ruby koan ever :D

--
spooq



Lyle Johnson

5/6/2005 12:26:00 PM

0

On 5/5/05, John Carter <john.carter@tait.co.nz> wrote:

> What is the sound of no duck quacking?

For that matter, if a duck quacks in the forest, and no one is there
to hear it, does it really make a sound?

> What should nil respond_to?

I can't tell (based on the setup) if this is a serious question or
not. ;) But if it is a serious question, "nil" at least responds to
the instance methods defined for any Object, since "nil" is an
instance (*the* instance) of NilClass, and NilClass is derived from
Object.



Lionel Thiry

5/6/2005 3:35:00 PM

0

John Carter a écrit :
> Imagine a flock of ducks in the sky. Listen.
> Now remove the ducks. Listen.
>
> What is the sound of no duck quacking?
>
> What should nil respond_to?
>
>
>
> John Carter

class Duck
def initialize(name)
@name = name
end
def quack
puts "#{@name} quacks!"
end
end

# imagine a flock of duck in the sky
duck_flock = [Duck.new("redhead"), Duck.new("mallard"), Duck.new("some duck")]

# listen
duck_flock.each do |duck|
duck.quack
end

# now remove the ducks
duck_flock.clear

# listen
duck_flock.each do |duck|
duck.quack
end

# what should nil respond to?
if duck_flock.empty?
puts "there are no nil's, what are you talking about?"
end

PS: you have read Head First Design Pattern didn't you? Good book, isn't it? But
it seems you missed page 598.

--
Lionel Thiry

Personal website: http://users.skynet....

Cyent

5/6/2005 11:27:00 PM

0

On Fri, 06 May 2005 21:26:24 +0900, Lyle Johnson wrote:

> On 5/5/05, John Carter <john.carter@tait.co.nz> wrote:
>
>> What is the sound of no duck quacking?
>
> For that matter, if a duck quacks in the forest, and no one is there
> to hear it, does it really make a sound?
>
>> What should nil respond_to?
>
> I can't tell (based on the setup) if this is a serious question or
> not. ;) But if it is a serious question, "nil" at least responds to
> the instance methods defined for any Object, since "nil" is an
> instance (*the* instance) of NilClass, and NilClass is derived from
> Object.

I was in the wilderness and there was nothing before me.

I told nothing to build me a castle.

Nothing happened.

When it had finished happening, there was still nothing there.

Now imagine, in another world, another universe....

I was in the wilderness and there was nothing before me.

I told nothing to build me a castle.

The world exploded with a NoMethodError and all died.

--
John Carter

The Cybernetic Entomologist - cyent@xtra.co.nz

http://geocities.yahoo....

I'm becoming less and less convinced of humans as rational beings.
I suspect we are merely meme collectors, and the reason meme is only
kept on to help count our change.

Ara.T.Howard

5/6/2005 11:42:00 PM

0

Ryan Leavengood

5/7/2005 6:11:00 PM

0

John Carter wrote:
> Imagine a flock of ducks in the sky. Listen.
> Now remove the ducks. Listen.
>
> What is the sound of no duck quacking?
>
> What should nil respond_to?

Imagine a large steel box with a small hole, through which you can push
a stick. Inside the box there is supposed to be a duck. This duck is
your dinner, and you are very, very hungry. But before you can open the
box to retrieve the duck for dinner, you have to use the stick and hole
to prove that there is a duck inside (by poking in...poor Mr. Duck.) If
poked the duck will quack rather loudly. But since this is a big box,
the duck can hide sometimes, so it won't always quack when you push in
the stick. Also the proof of duck existence is needed because opening an
empty box will release a deadly gas (it is a dangerous world.)

In addition, this is a smart box, and on the back, where you cannot see
or access it (the box is against a wall), there is a switch which turns
on "smart mode." In smart mode, an empty box will complain when you push
the stick in the hole. Unfortunately some clever guy thought this was
dumb, and he turned off smart mode ("eh, it is a waste of electricity"
was his logic.)

So you spend hours, poking and poking and poking, never really sure if
there is a duck inside, because the box just never told you it was
empty. Eventually you die of starvation, all because that clever guy
turned off that switch.

Ryan


james_b

5/7/2005 6:48:00 PM

0

Ryan Leavengood wrote:
...

>
> So you spend hours, poking and poking and poking, never really sure if
> there is a duck inside, because the box just never told you it was
> empty. Eventually you die of starvation, all because that clever guy
> turned off that switch.

So is this, like, Schrödinger's Duck?


James
--
http://www.ru...
http://www.r...
http://catapult.rub...
http://orbjson.rub...
http://ooo4r.rub...
http://www.jame...



Ryan Leavengood

5/7/2005 7:38:00 PM

0

James Britt wrote:
>
> So is this, like, Schrödinger's Duck?

Hehehe, that thought did cross my mind as I wrote it. But alas my simple
Ruby NoMethodError metaphor isn't on the same plane as Quantum Physics
metaphors.

Ryan


Lionel Thiry

5/7/2005 10:23:00 PM

0

Ryan Leavengood a écrit :
> James Britt wrote:
>
>>
>> So is this, like, Schrödinger's Duck?
>
>
> Hehehe, that thought did cross my mind as I wrote it. But alas my simple
> Ruby NoMethodError metaphor isn't on the same plane as Quantum Physics
> metaphors.
>
> Ryan
>
>

But it gives same headaches!

--
Lionel Thiry

Personal website: http://users.skynet....

Kero van Gelder

5/8/2005 3:41:00 PM

0

> Imagine a flock of ducks in the sky. Listen.
> Now remove the ducks. Listen.
>
> What is the sound of no duck quacking?
>
> What should nil respond_to?

nil.nil? => true
Object.new.nil? => false

and if your duck can not be false itself, code like this works:

if duck = flock.front_duck
duck.relocate_towards_end_of(flock) if duck.tired?
end

+--- Kero ----------------------- kero@chello@nl ---+
| all the meaningless and empty words I spoke |
| Promises -- The Cranberries |
+--- M38c --- http://httpd.chello.nl/k... ---+