What sound does no duck make?

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 Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : john.carter@tait.co.nz
New Zealand

Surprisingly enough, this email does not originate from a beetle.

Best ruby koan ever :smiley:

···

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?

--
spooq

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

···

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

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.be/lthiry/

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

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.vangelder ---+

Having asked the question, and heard many replies let me summarise...

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?

Well, it turned out that there are several sorts of unduck making several
different unsounds.

There is the uninitialized unduck, which, when you ask it to quack
says, "You Nana! It was _your_ job to put a duck here and you DID NOT,
and now you asking it to Quack! Twit!"

Then there is the not applicable duck, which when you ask it to quack
says, "Sorry, it is just not appropriate nor ever will be appropriate
to have a duck in _this_ particular instance. Don't even try put a duck
in here, let alone ask it to quack."

Then there is the no duck, which when asked to quack (or anything else
for that matter) does nothing, and after having done nothing, leaves
you with nothing. Which was the only sort of nil I had in my rather
limited mind when I asked the question.

John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : john.carter@tait.co.nz
New Zealand

We all live but seconds away from pain and death, yet we live as
though it wasn't even possible.

We are but one person amongst 6 billion, yet we live as though we,
personally, matter.

So, as you were saying... how real did you want me to get?

···

On Fri, 6 May 2005, John Carter wrote:

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.

···

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

--
John Carter

The Cybernetic Entomologist - cyent@xtra.co.nz

http://geocities.yahoo.com/cy_ent

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.

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://catapult.rubyforge.com
http://orbjson.rubyforge.com
http://ooo4r.rubyforge.com
http://www.jamesbritt.com

Having asked the question, and heard many replies let me summarise...

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?

Well, it turned out that there are several sorts of unduck making several
different unsounds.

There is the uninitialized unduck, which, when you ask it to quack
says, "You Nana! It was _your_ job to put a duck here and you DID NOT,
and now you asking it to Quack! Twit!"

Then there is the not applicable duck, which when you ask it to quack
says, "Sorry, it is just not appropriate nor ever will be appropriate
to have a duck in _this_ particular instance. Don't even try put a duck
in here, let alone ask it to quack."

Then there is the no duck, which when asked to quack (or anything else
for that matter) does nothing, and after having done nothing, leaves
you with nothing. Which was the only sort of nil I had in my rather
limited mind when I asked the question.

Goose!

John Carter

E

···

Le 19/5/2005, "John Carter" <john.carter@tait.co.nz> a écrit:

On Fri, 6 May 2005, John Carter wrote:

--
template<typename duck>
void quack(duck& d) { d.quack(); }

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

then something is wrong with my eye-glasses or my definition of wilderness
needs to be checked...

I told nothing to build me a castle.

then something is wrong with my mind and __i__ need to be checked

Nothing happened.

except cpu cycles

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

which is clearly not what i expected

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.

i noticed that telling nothing to build a castle was a logic error (the
__most__ difficult kind of error to debug) fixed it - and re-started a correct
program.

my 2 cts.

-a

···

On Sat, 7 May 2005, Cyent wrote:
--

email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
renunciation is not getting rid of the things of this world, but accepting
that they pass away. --aitken roshi

===============================================================================

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

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.be/lthiry/