CLOS usage

Discussion of Common Lisp

How much do you use CLOS?

All the time, I think in CLOS
1
3%
Fairly often
14
37%
Sometimes, when it makes sense
13
34%
Not very often
7
18%
Never! CLOS is for the weak
3
8%
 
Total votes : 38

Re: CLOS usage

Postby Alexander Lehmann » Thu Jul 10, 2008 12:13 am

Yes, I thought so, but wasn't sure :)
Alexander Lehmann
 
Posts: 23
Joined: Sat Jun 28, 2008 11:27 pm

Re: CLOS usage

Postby theclapp » Thu Jul 17, 2008 5:07 am

I don't use or think about CLOS as much as I'd like. I think Kenny Tilton's Cells project looks pretty cool, and it uses CLOS through-and-through. I've done most of my programming over the last 10 years in shell and Perl, which has warped me so that I tend to think in terms of lists and hashtables (arrays and hashes, in Perl). I'd like to change my thinking to flow more along the lines of dataflow and dependencies instead of datastructures and functions.
theclapp
 
Posts: 17
Joined: Wed Jul 16, 2008 11:05 am

Re: CLOS usage

Postby pTymN » Thu Jul 17, 2008 6:24 am

It has always seemed to me that CLOS is a product of that age when it was in vogue to make everything object oriented. Now, it was written in Lisp, so I know that CLOS and Smalltalk are probably the highlights of OO and the C++ that I use in my day job has prematurely turned me off from OO, but I don't think that is the whole story. In Lisp, it has been so trivial to build up a data structure, store it, retreive it and destroy it just a few methods later, that I feel no need to ever make a heavyweight solid data structure of the type that OO champions. Another problem with OO is that it tends to limit exactly how code can get reused. The structureless nature of Lisp allows me to take any meaningful chunk of code and not just put code before or after it, but to take callbacks (which are so awkward in C++ that for the first ten years, I had to look up the syntax), and make them trivial, so that I can make a piece of code that is designed to be (X A X') with your custom chunk A in the middle. In an OO paradigm, the callback would be to call out to obj.A and to overload A. At least java made everything virtual. I cannot tell you how much pain that causes me, when the child class doesn't even get the final say over which versions of methods will be used 100% of the time. Sorry for the rant, I just hope that OO has the mark of shame all over it when stateless functional programming takes over. Seriously, a stack trace that is 100% meaningful, where I don't have to play detective to figure out why the values I am looking at are what they are... that would be nice to have all the time.
pTymN
 
Posts: 20
Joined: Sat Jun 28, 2008 7:15 am
Location: Columbia, SC

Re: CLOS usage

Postby Exolon » Thu Jul 17, 2008 11:49 am

pTymN wrote:Seriously, a stack trace that is 100% meaningful, where I don't have to play detective to figure out why the values I am looking at are what they are... that would be nice to have all the time.

Well, I was really excited about (pure) functional stuff when I first got interested in Haskell, after coming from the pain of C++ and the verbose boulder-dragging of Java. Then I saw some stack traces which kind of stopped me in my tracks.
Maybe you get used to it, but... ouch.

That's also something that I find a little painful with Lisp; especially the lack of line numbers in the uncaught/REPL error handler stack traces, but the generally mystifying nature of error messages I've been getting as a newbie to the language. There's a lot to be said for messages like "Array index out of bounds (CarThingy.java, line 85)" and a backtrace which lists the classes (usually = files) and line numbers of the higher stack frames.
Exolon
 
Posts: 49
Joined: Sat Jun 28, 2008 12:53 pm
Location: Ireland

Re: CLOS usage

Postby dlweinreb » Fri Jul 18, 2008 4:41 am

At ITA Software, we use CLOS very heavily. One reason is that we have built an object-relational database access subsystem, in which (to simplify a big) every database table corresponds to a CLOS class. However, even when we aren't using that, we still use CLOS heavily. Object-oriented programming is a very useful tool for achieving modularity in many common scenarios that arise in programming, particularly in large systems.
dlweinreb
 
Posts: 41
Joined: Tue Jul 01, 2008 5:11 am
Location: Lexington, MA

Re: CLOS usage

Postby dlweinreb » Fri Jul 18, 2008 4:48 am

Alexander Lehmann wrote:Hm, I like CLOS and fairly often use objects. However, I prefer using "regular" functions instead of methods wherever methods aren't explicitly neccessary.


In CLOS, you are still using functions. The best way to think about CLOS is that what you're writing is generic functions. (This is clearer if you always write explicit defgenerics, rather than letting CLOS put them in automatically.) From the caller's point of view, it's just a function! The defmethod's are part of the internal implementation of the function. When is it good to implement a function using this (defmethod) mechanism. Well, if you're going to do different implementations of the same concept based on the type (subclass, in practice) of one (or more!) of your arguments, then it's perfect.

CLOS is just one more tool in the toolbox. It's not the answer to everything; it's the answer to some specific problems.

I always think of the "stream" concept is the best example of OOP. A stream is an abstraction with operations like "write this string to the stream" and such. That has one, unified generic meaning, once you understand what a stream is. But there are many specific implementations (depending on the underlying device). So it's very useful to have a "stream" class, and subclasses for the specific concrete implementations (send the string to the serial port, send the string to a file, etc).

I am planning to write more about this on my blog (dlweinreb.wordpress.com). Some issues of CLOS philosophy have been under heavy discussion at ITA lately (particularly the interaction of keyword arguments with generics functions), so I've been thinking about it a lot lately.
dlweinreb
 
Posts: 41
Joined: Tue Jul 01, 2008 5:11 am
Location: Lexington, MA

Re: CLOS usage

Postby dlweinreb » Fri Jul 18, 2008 4:53 am

Exolon wrote:
pTymN wrote:That's also something that I find a little painful with Lisp; especially the lack of line numbers in the uncaught/REPL error handler stack traces, but the generally mystifying nature of error messages I've been getting as a newbie to the language. There's a lot to be said for messages like "Array index out of bounds (CarThingy.java, line 85)" and a backtrace which lists the classes (usually = files) and line numbers of the higher stack frames.


The quality of the error messages depends primarily on which implementation of Common Lisp you're using. There are eleven of them out there still being maintained actively (see http://common-lisp.net/~dlw/LispSurvey.html). I've been happy with the error messages in SBCL and CCL (OpenMCL), and the stack traces.

One thing that you may need to do is to make sure to compile with proper "safety" declared. This is like the -g argument to C compilers, telling the compiler to keep around extra information to allow the runtime to produce good debugging info. Check the reference material for your Lisp implementation.
dlweinreb
 
Posts: 41
Joined: Tue Jul 01, 2008 5:11 am
Location: Lexington, MA

Re: CLOS usage

Postby dlweinreb » Fri Jul 18, 2008 4:58 am

pTymN wrote:It has always seemed to me that CLOS is a product of that age when it was in vogue to make everything object oriented. Now, it was written in Lisp, so I know that CLOS and Smalltalk are probably the highlights of OO and the C++ that I use in my day job has prematurely turned me off from OO, but I don't think that is the whole story. In Lisp, it has been so trivial to build up a data structure, store it, retreive it and destroy it just a few methods later, that I feel no need to ever make a heavyweight solid data structure of the type that OO champions. Another problem with OO is that it tends to limit exactly how code can get reused. The structureless nature of Lisp allows me to take any meaningful chunk of code and not just put code before or after it, but to take callbacks (which are so awkward in C++ that for the first ten years, I had to look up the syntax), and make them trivial, so that I can make a piece of code that is designed to be (X A X') with your custom chunk A in the middle. In an OO paradigm, the callback would be to call out to obj.A and to overload A. At least java made everything virtual. I cannot tell you how much pain that causes me, when the child class doesn't even get the final say over which versions of methods will be used 100% of the time. Sorry for the rant, I just hope that OO has the mark of shame all over it when stateless functional programming takes over. Seriously, a stack trace that is 100% meaningful, where I don't have to play detective to figure out why the values I am looking at are what they are... that would be nice to have all the time.


Sorry, I'm having a lot of trouble understanding what you mean by things like "(X A X')" and "obj.A".

What's the problem with doing callbacks with CLOS? There are two senses of this that you might mean. First, in OO programming, it's common to have abstract base classes that call some method that is not defined by the abstract base class itself. Java calls these abstract methods; CLOS unfortunately has no particular name for them. To make a concrete subclass that can be instantiated, you must provide an implementation of this abstract method. You can think of this as a callback, in some sense.

Second, there are just plain ordinary callbacks that have nothing special to do with CLOS. You just pass a callback function to a generic function, which stores it away somewhere, and calls it later at the appropriate time. It's all just Lisp, so it's easy to do that, CLOS or no CLOS.
dlweinreb
 
Posts: 41
Joined: Tue Jul 01, 2008 5:11 am
Location: Lexington, MA

Re: CLOS usage

Postby Alexander Lehmann » Fri Jul 18, 2008 5:07 am

dlweinreb wrote:
Alexander Lehmann wrote:Hm, I like CLOS and fairly often use objects. However, I prefer using "regular" functions instead of methods wherever methods aren't explicitly neccessary.


In CLOS, you are still using functions. The best way to think about CLOS is that what you're writing is generic functions. (This is clearer if you always write explicit defgenerics, rather than letting CLOS put them in automatically.) From the caller's point of view, it's just a function! The defmethod's are part of the internal implementation of the function. When is it good to implement a function using this (defmethod) mechanism. Well, if you're going to do different implementations of the same concept based on the type (subclass, in practice) of one (or more!) of your arguments, then it's perfect.

Please correct me if I'm wrong, but I thought that the major difference between "functions" and "methods" -- with respect to Lisp and/or CLOS -- was that for methods, CLOS first looks up the most suitable (specialized) version of a method in regard to the given parameters, whereas this need not be done for plain "functions"?
Alexander Lehmann
 
Posts: 23
Joined: Sat Jun 28, 2008 11:27 pm

Re: CLOS usage

Postby Geoff Wozniak » Sun Jul 20, 2008 2:45 pm

Alexander Lehmann wrote:Please correct me if I'm wrong, but I thought that the major difference between "functions" and "methods" -- with respect to Lisp and/or CLOS -- was that for methods, CLOS first looks up the most suitable (specialized) version of a method in regard to the given parameters, whereas this need not be done for plain "functions"?


What you are calling methods are actually generic functions. Methods are simply function-like elements associated with generic functions. dlweinreb's point was that plain functions and generic functions can be used in the same manner, although the internals are quite different.
Geoff Wozniak
 
Posts: 9
Joined: Wed Jul 16, 2008 5:38 pm
Location: Canada

PreviousNext

Return to Common Lisp

Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 1 guest

cron