Lisp Usenet classics

Here are some past Erik Naggum Usenet articles for your reading pleasure.

Tags:

Comments

thanks!

it's cool that someone takes the time and effort, scouts the archives and digs out those valuables.

(I wish people were adding "?dmode=source" to the article links, though.  makes Google Groups almost bearable.)

(Anonymous)

Re: Object Orientation and what it means in Common Lisp

This is such an excellent post and I do miss the insightful posts of Erik Naggum.

I must admit though, I have never really gel'd with CLOS, or could never wrap my head around it entirely.

He makes a comment..

"It is not classes that experienced Common Lisp programmers start with. It is the generic functions."

and I do wish there was a good example or tutorial out there which really helped to turn the light on for me and others regarding this.

One of the stumbling blocks is how generic methods must be congruent. Which just seems so foreign coming from a message passing OO language. Its not uncommon to have two methods with the same name but which take a different number of arguments.

For example,

A dog talks although it just says "woof" and so does a human. But a human can say anything.

So a dog might may have a method, talk, which takes no arguments and it just spits out "woof"

and a human might have a method talk: msg, which takes an arugment with text to speak.

I've had someone tell me to just create a talk generic method which takes an argument to specialize on and a second argument msg. When the specialized argument is dog, ignore the msg argument, but when it's human, use the msg argument.

This just seems weird from a standpoint of using the code and trying to understand what I need to pass in. Just making the method more convoluted so that it handles the most complex case? And what happens in the future if I need to add another argument (what happens to all the old calls)?

If you have any suggestions to shed light on this.. I'm all ears... as I would love to really finally get over this... and again, thanks for the great post.

(Anonymous)

Re: Object Orientation and what it means in Common Lisp

Static overloading of method names is the same as using different method names. There is no semantic difference between:

talk() { ... }
talk(String s) { ... }

and:

talk() { ... }
say(String s) { ... }

(Anonymous)

Re: Object Orientation and what it means in Common Lisp

Agreed.

But its annoying to think you always have to come up with a different name just so you don't hit the congruency issue. And there are only so many variations until you start getting convoluted names as well, so I don't see this as a solution. But maybe its the only one.

(Anonymous)

Re: Object Orientation and what it means in Common Lisp

"But maybe its the only one." or maybe I should have rephrased that as, maybe this is just the reality of it all.

(Anonymous)

Re: Object Orientation and what it means in Common Lisp

It might help to take a look at MAKE-INSTANCE. I think it has the protocol you want.

(defgeneric make-instance (class &rest initargs))

You can specialize on the first argument and have the interpretation of the rest of the argument list handled by the various methods. Using this pattern, you can write:

(talk (make-instance 'dog))
(talk (make-instance 'human) :word "lisp")

Aside: Note that MAKE-INSTANCE plays a little trick where (make-instance 'foo ...) simply calls (make-instance (find-class 'foo) ...).

Eric

Re: Object Orientation and what it means in Common Lisp

Dogs don't talk.

(Anonymous)

Re: Object Orientation and what it means in Common Lisp

Clearly you've never met a husky.

Re: Object Orientation and what it means in Common Lisp

In Tennessee, a guy sees a sign in front of a house: "Talking Dog for Sale."

He rings the bell and the owner tells him the dog is in the backyard. The guy goes into the backyard and sees a black mutt just sitting there.
"You talk?" he asks.

"Yep," the mutt replies.

"So, what's your story?"

The mutt looks up and says, "Well, I discovered this gift pretty young and I wanted to help the government, so I told the
CIA about my gift, and in no time they had me jetting from country to country, sitting in rooms with spies and world leaders, because no one figured a dog would be eavesdropping. I was one of their most valuable spies eight years running."

"The jetting around really tired me out, and I knew I wasn't getting any younger and I wanted to settle down. So I
signed up for a job at the airport to do some undercover security work, mostly wandering near suspicious characters and listening in. I uncovered some incredible dealings there and was awarded a batch of medals. Had a wife, a mess of puppies, and now I'm just retired."

The guy is amazed. He goes back in and asks the owner what he wants for the dog.

The owner says, "Ten dollars."

The guy says, "This dog is amazing. Why on earth are you selling him so cheap?"

The owner replies, "He's such a liar. He didn't do any of that shit."

(Anonymous)

Re: Object Orientation and what it means in Common Lisp

Sure, maybe its not the best example... but its just a simple example to express my issue.

Re: Object Orientation and what it means in Common Lisp

Ok, say that dogs talk by barking, but they only have one thing to say all the time.

The thing a particular instance or class has say could be considered a property of the instance or class, not of the talk operation. So you might have classes that look like:

(defclass dumb-animal ()
  ((on-its-mind :initarg :on-its-mind :reader on-its-mind)))

(defclass enlightened-thinker ()
  ((on-its-mind :initarg :on-its-mind :accessor on-its-mind)))

(defclass dog (dumb-animal)
  ((on-its-mind :allocation :class))
  (:default-initargs :on-its-mind "Woof!"))

(defclass chicken (dumb-animal)
  ((on-its-mind :allocation :class))
 (:default-initargs :on-its-mind "Bock bock bock!"))

(defclass person (enlightened-thinker)
  ())

(defun say (stuff)
  (write-line stuff))

(defgeneric speak-your-mind (thing)
  (:method (thing)
    (say (on-its-mind thing))))

(defmethod slot-unbound (class (object enlightened-thinker)
                         (slot-name (eql 'on-its-mind)))
  (error "Nothing on your mind?"))



A person might change what is on his mind, but a dog or chicken won't.

Anyway, you can model everything you want to in CLOS; it helps to understand what's with the grain and what isn't.

Re: Object Orientation and what it means in Common Lisp

(Anonymous)

Re: Object Orientation and what it means in Common Lisp

I found the CLOS part of the book very light... but yes, I have read those in both PDF and paperback forms.

Re: Object Orientation and what it means in Common Lisp

Agreed. Those chapters are a bit light. However, the practical applications discussed in the final chapters of the book help to illustrate the concepts discussed in those chapters a bit better.

September 2014

S M T W T F S
 123456
78910111213
14151617181920
21222324252627
282930    
Powered by LiveJournal.com