From: Tagore Smith
Subject: Beautiful code
Date: 
Message-ID: <1145718830.848631.249810@i39g2000cwa.googlegroups.com>
Robert Heinlein once said: "specialization is for insects". I like to
justify my own dilettantism with that quote. I'm a programmer by trade,
but I have a lot of other interests- music, literature, and languages
come to mind. Whatever I know about any of these things, I learned
through mimicry (most obviously when it comes to languages). In fact,
everything I do well... well, I learned by watching people who did
whatever it was, "perfectly".

I know that c.l.l is primarily a group devoted to arguments about how
various libraries are installed. Not that there's anything wrong with
that. But I am looking for examples to mimic- I'm not a bad programmer,
I think, and I am not even a terribly bad CL programmer, even if my
method of installing libraries tends to be kind of brute force. Being a
not terribly bad programmer is rare enough, but.... But I am certainly
not a _great_ programmer, and I'm afraid that I don't know anyone who
is a really great programmer- I mean, think Tolstoy or Dante here.

I'd like to see some examples of really great programming, preferably
in some sort of Lisp. I don't mean textbook examples- I've read PAIP,
and SICP, and Graham's books, and some of the code was nice, but, I am
looking for real code, meant to do something, but beautifully written.
Elegant. Perfect. And  part of a working system.

Feel free to nominate your own code, but I am looking for systems, not
beautiful functions (but feel free to nominate beautiful functions-
this is is Usenet so don't pay me any mind). I've written a few
routines that sparkled like gems; I can't say that I have ever written
a system that could blind anyone, even in direct sunlight.

I think that citing the best Lisp out there might be a welcome break
from all this "Python vs Lisp" stuff. I read c.l.l because I have
_already_ decided to use CL. I generally don't read c.l.l for exactly
that reason.

So bring out the best that you have seen- an ingenious idea, a sleight
of mind,  a piece of code written by a mentor who has shuffled off this
coil, but left some code behind. Some beautiful code, please.

From: Ken Tilton
Subject: Re: Beautiful code
Date: 
Message-ID: <BKt2g.10$Rx4.9@fe11.lga>
Tagore Smith wrote:
> I am
> looking for real code, meant to do something, but beautifully written.
> Elegant. Perfect. And  part of a working system.

I recall Erik Naggum praising Kent Pitman's code as highly. Just not 
sure where you could find any.

ken

-- 
Cells: http://common-lisp.net/project/cells/

"Have you ever been in a relationship?"
    Attorney for Mary Winkler, confessed killer of her
    minister husband, when asked if the couple had
    marital problems.
From: Paolo Amoroso
Subject: Re: Beautiful code
Date: 
Message-ID: <878xpxsasu.fsf@plato.moon.paoloamoroso.it>
Ken Tilton <·········@gmail.com> writes:

> I recall Erik Naggum praising Kent Pitman's code as highly. Just not
> sure where you could find any.

See the sample code:

  http://www.nhplace.com/kent/Papers/sysdef.lisp.txt

that comes with this paper:

  The Description of Large Systems
  http://www.nhplace.com/kent/Papers/Large-Systems.html


Paolo
-- 
Why Lisp? http://wiki.alu.org/RtL%20Highlight%20Film
The Common Lisp Directory: http://www.cl-user.net
From: Ken Tilton
Subject: Re: Beautiful code
Date: 
Message-ID: <2%x2g.307$327.194@fe08.lga>
Paolo Amoroso wrote:
> Ken Tilton <·········@gmail.com> writes:
> 
> 
>>I recall Erik Naggum praising Kent Pitman's code as highly. Just not
>>sure where you could find any.
> 
> 
> See the sample code:
> 
>   http://www.nhplace.com/kent/Papers/sysdef.lisp.txt

Nice. Thx.

kennj

-- 
Cells: http://common-lisp.net/project/cells/

"Have you ever been in a relationship?"
    Attorney for Mary Winkler, confessed killer of her
    minister husband, when asked if the couple had
    marital problems.
From: Greg Buchholz
Subject: Re: Beautiful code
Date: 
Message-ID: <1145918585.341421.201930@t31g2000cwb.googlegroups.com>
Paolo Amoroso wrote:
> See the sample code:
>
>   http://www.nhplace.com/kent/Papers/sysdef.lisp.txt

I haven't studied the code at all, but I was a little bit surprised by
this comment...

;; If CL had a way of declaring these to be required methods,
;; we'd use that.  Instead, we at least make these give better
;; error messages as default methods for the protocol class SYSTEM.

...and the boilerplate of all the defgeneric and default defmethods.  I
guess I'm surprised that this wasn't all rolled up into a
generate-generic-functions-plus-a-default-method macro like...

(generate-generic-functions-plus-a-default-method
  ((short-name (system))
   (full-name  (system))
   (process-options (system options))
   (process-option (system option-key &rest option-data))
   (source-files (system))
   (generate-plan (system plan-key &rest plan-data))
   (explain-plan (system plan))
   (execute-plan (system plan))
   (explain-action (system action-key &rest action-data))
   (execute-action (system action-key &rest action-data))))

...or some-such.  Would this have been a case of overusing macros?
Also, I'm interested in why the author uses comments above each method,
instead of documentation strings
(http://www.lisp.org/HyperSpec/Body/stagenfun_doc_umentationcp.html#documentation).
 Thoughts?

Thanks,

Greg Buchholz
From: David Combs
Subject: Re: Beautiful code
Date: 
Message-ID: <e4s9s8$n50$1@reader1.panix.com>
In article <··············@fe11.lga>, Ken Tilton  <·········@gmail.com> wrote:
>
>
>Tagore Smith wrote:
>> I am
>> looking for real code, meant to do something, but beautifully written.
>> Elegant. Perfect. And  part of a working system.
>
>I recall Erik Naggum praising Kent Pitman's code as highly. Just not 
>sure where you could find any.

Whatever happened to Kent? -- I haven't seen any posts from him
for quite a while.

And Naggum -- it's been years (and years and years) since
he's been here.  Probably not even *reading* it!

   (Too bad (youse guys) chased him off -- 'spose a *group*
    of people, all of whom knows and respects, could
    invite him back?  He has *immense* lisp knowledge,
    current use, history all the way back, etc.

   And, adults that we are, we could easily
    *quietly* tolerate *his* sometime-flames.
   )


David
From: Wade Humeniuk
Subject: Re: Beautiful code
Date: 
Message-ID: <fru2g.7556$fL.3742@edtnps90>
One of the best

http://www.99-bottles-of-beer.net/language-common-lisp-114.html

Wade
From: Paolo Amoroso
Subject: Re: Beautiful code
Date: 
Message-ID: <87psj9bmhd.fsf@plato.moon.paoloamoroso.it>
"Tagore Smith" <······@tagoresmith.com> writes:

> I'd like to see some examples of really great programming, preferably
> in some sort of Lisp. I don't mean textbook examples- I've read PAIP,
> and SICP, and Graham's books, and some of the code was nice, but, I am
> looking for real code, meant to do something, but beautifully written.
> Elegant. Perfect. And  part of a working system.

I think that Lisa comes close:

  http://lisa.sourceforge.net/


Paolo
-- 
Why Lisp? http://wiki.alu.org/RtL%20Highlight%20Film
The Common Lisp Directory: http://www.cl-user.net
From: Wade Humeniuk
Subject: Re: Beautiful code
Date: 
Message-ID: <LNu2g.2654$FY1.1568@clgrps12>
Here is short excerpt from a CTI Telephony Client/Server system
It uses macros, unwind-protect, conditions, multi-processing, sockets
special vars, anonymous functions, handler-case, CLOS, change-class.

Its where the whole power and synergy of CL comes together
to provide a solution.

(defvar *telephony-server-port* 8000)

(defmacro with-telephony-server-stream ((stream &key (line nil)
                                                     (server "localhost")
                                                     (port '*telephony-server-port*))
                                             &body body)
   `(with-open-stream (,stream (change-class
                                (or (comm:open-tcp-stream ,server ,port)
                                    (error "Unable to connect ~A:~A" ,server ,port))
                                'server-stream :line ,line))
      (grab-line ,line ,stream)
      ,@body))

(defmacro run-telephony-client ((line &key (server "localhost") (port 
'*telephony-server-port*))
                                   &body body)
   `(with-telephony-server-stream (*server-stream* :line ,line :server ,server :port ,port)
      (let* ((*internal-mailbox* (mp:make-mailbox))
             (*reader-process*
              (mp:process-run-function
               (format nil "Telephony Server Reader ~A" ,line)
               nil
               (lambda (stream mailbox)
                 (handler-case
                     (loop for server-event = (get-event stream)
                           do (mp:mailbox-send mailbox server-event))
                   (error (condition)
                          (mp:mailbox-send mailbox condition))))
               *server-stream* *internal-mailbox*)))
        (unwind-protect
            (with-player (*player*)
              ,@body)
          (mp:process-kill *reader-process*)))))
From: Rainer Joswig
Subject: Re: Beautiful code
Date: 
Message-ID: <joswig-4D4BF4.19224322042006@news-europe.giganews.com>
In article <························@i39g2000cwa.googlegroups.com>,
 "Tagore Smith" <······@tagoresmith.com> wrote:

> Robert Heinlein once said: "specialization is for insects". I like to
> justify my own dilettantism with that quote. I'm a programmer by trade,
> but I have a lot of other interests- music, literature, and languages
> come to mind. Whatever I know about any of these things, I learned
> through mimicry (most obviously when it comes to languages). In fact,
> everything I do well... well, I learned by watching people who did
> whatever it was, "perfectly".
> 
> I know that c.l.l is primarily a group devoted to arguments about how
> various libraries are installed. Not that there's anything wrong with
> that. But I am looking for examples to mimic- I'm not a bad programmer,
> I think, and I am not even a terribly bad CL programmer, even if my
> method of installing libraries tends to be kind of brute force. Being a
> not terribly bad programmer is rare enough, but.... But I am certainly
> not a _great_ programmer, and I'm afraid that I don't know anyone who
> is a really great programmer- I mean, think Tolstoy or Dante here.
> 
> I'd like to see some examples of really great programming, preferably
> in some sort of Lisp. I don't mean textbook examples- I've read PAIP,
> and SICP, and Graham's books, and some of the code was nice, but, I am
> looking for real code, meant to do something, but beautifully written.
> Elegant. Perfect. And  part of a working system.

There are some books which describe code of working systems.

* Art of the Meta-Object Protocol

  The way god intended CLOS to be written. I think the
  programming style is really enlightening.

  From there you can study the CLOS implementation
  that was the first reference implementation: PCL
  (Portable Common Loops).

* Building Problem Solvers

  There is even a companion book with just the source code.

There are some nicely written libraries, tools and applications:

* LOOM, a knowledge-representation system

* PowerLOOM, a knowledge-representation system, successor to LOOM

* Garnet, a UIMS

* GBBopen, Blackboard system

* CLUE / CLIO, an older UIMS for X11

Tools

* Common Music, Common Lisp Music

* CL-HTTP (web server/client/walker/proxy/reverse proxy/...)

  See for example W3P, W4 (the code walker)

* ACL2, theorem prover

* SBCL, Common Lisp implementation

Applications

* OpenMusic

Operating Systems

* some parts of Symbolics Genera are interesting

  The OS comes with almost full source for everything.
  So there is lots of things to study (>1 MLOC).

-- 
http://lispm.dyndns.org/
From: Thomas Schilling
Subject: Re: Beautiful code
Date: 
Message-ID: <4avtjlFv59k4U1@news.dfncis.de>
Rainer Joswig wrote:

>>I'd like to see some examples of really great programming, preferably
>>in some sort of Lisp. I don't mean textbook examples- I've read PAIP,
>>and SICP, and Graham's books, and some of the code was nice, but, I am
>>looking for real code, meant to do something, but beautifully written.
>>Elegant. Perfect. And  part of a working system.

> * Art of the Meta-Object Protocol

Yes, truly a remarkable book.  The code may be different
("implementation dependent"), but the *design* definitely fulfils the
requirements.

> * SBCL, Common Lisp implementation

Huh? Can't tell about the other projects, but I took more than one look
at the SBCL source code--and it is certainly not elegant, perfect, or
beautifully written.  No offence, SBCL is a remarkable piece of work;
powerful, refined, well-working Common Lisp implementation.  But it's
design is more than 20 years old.  Many advances in compiler technology
did not find their way into the Python compiler: static single
assignment form for flow analysis (SBCL uses monotone dataflow systems),
the register allocator probably doesn't use graph colouring
techniques--otherwise it probably wouldn't do such sub-optimal work in
many cases, the code uses many longish functions, etc.

Again, this is not to blame any of the developers or a rant about SBCL
drawbacks.  But it's definitely not the right project of the requested
type. MLton may be (though, it's ML of course). Or MinCaml (a working
compiler in 2000 lines, though I haven't seen the code and it's probably
more a toy since it doesn't compile something as complex as CL.)

-ts
From: Rainer Joswig
Subject: Re: Beautiful code
Date: 
Message-ID: <joswig-06F930.03145323042006@news-europe.giganews.com>
In article <··············@news.dfncis.de>,
 Thomas Schilling <······@yahoo.de> wrote:

> Rainer Joswig wrote:
> 
> >>I'd like to see some examples of really great programming, preferably
> >>in some sort of Lisp. I don't mean textbook examples- I've read PAIP,
> >>and SICP, and Graham's books, and some of the code was nice, but, I am
> >>looking for real code, meant to do something, but beautifully written.
> >>Elegant. Perfect. And  part of a working system.
> 
> > * Art of the Meta-Object Protocol
> 
> Yes, truly a remarkable book.  The code may be different
> ("implementation dependent"), but the *design* definitely fulfils the
> requirements.
> 
> > * SBCL, Common Lisp implementation
> 
> Huh? Can't tell about the other projects, but I took more than one look
> at the SBCL source code--and it is certainly not elegant, perfect, or
> beautifully written.  No offence, SBCL is a remarkable piece of work;
> powerful, refined, well-working Common Lisp implementation.  But it's
> design is more than 20 years old.

I think it IS useful to study a Lisp piece of software
that has partly been written/designed 20 years ago. It might not
feature the latest algorithms, but the style can be
interesting.

I would still recommend looking into:

*  sbcl/src/pcl
*  sbcl/src/code
*  sbcl/contrib

and probably more.

Even if the compiler could be more sophisticated, or
even be restructured/refactored, it is a significant piece of
code that is highly educational.

>  Many advances in compiler technology
> did not find their way into the Python compiler: static single
> assignment form for flow analysis (SBCL uses monotone dataflow systems),
> the register allocator probably doesn't use graph colouring
> techniques--otherwise it probably wouldn't do such sub-optimal work in
> many cases, the code uses many longish functions, etc.

Longish functions are not really a problem for me. I can live with
that.

> 
> Again, this is not to blame any of the developers or a rant about SBCL
> drawbacks.  But it's definitely not the right project of the requested
> type. MLton may be (though, it's ML of course). Or MinCaml (a working
> compiler in 2000 lines, though I haven't seen the code and it's probably
> more a toy since it doesn't compile something as complex as CL.)
> 
> -ts


I don't think it is that useless to look at SBCL just because
it lacks some optimizations. Somebody studying Lisp code and
good style Lisp code might prefer a simpler design.

SBCL is also more than a compiler.
It is also a runtime system, a library, a source of
contributions, an object system, ... It shows also how you
can bootstrap a Lisp system with another Lisp system and so on.

-- 
http://lispm.dyndns.org/
From: Alain Picard
Subject: Re: Beautiful code
Date: 
Message-ID: <874q0lsj0n.fsf@memetrics.com>
"Tagore Smith" <······@tagoresmith.com> writes:


> I'd like to see some examples of really great programming, preferably
> in some sort of Lisp. I don't mean textbook examples- I've read PAIP,
> and SICP, and Graham's books, and some of the code was nice, but, I am
> looking for real code, meant to do something, but beautifully written.
> Elegant. Perfect. And  part of a working system.

I don't know about "elegant" and "perfect", but I have to say that
I'm massively impressed by CL-PPCRE, by Edi Weitz.  I think beating
Perl at its own game (i.e. regex speed) is quite a tour de force,
and the code looks readable as always.  Edi is one of the premier
library authors for Lisp, right now, IMO.  His stuff "just works".

Then, there's always the sources to most of Emacs...  maybe elegance
is in the eye of the beholder.  Can something be both elegant and crufty?
I think emacs fits that bill.
From: Thomas A. Russ
Subject: Re: Beautiful code
Date: 
Message-ID: <ymiiroyvrsh.fsf@sevak.isi.edu>
> I'd like to see some examples of really great programming, preferably
> in some sort of Lisp. I don't mean textbook examples- I've read PAIP,
> and SICP, and Graham's books, and some of the code was nice, but, I am
> looking for real code, meant to do something, but beautifully written.
> Elegant. Perfect. And  part of a working system.

Well, it's not quite perfect in the code department, but for elegance of
use and implementation, I would like to nominate the measures package
that Roman Cunis developed.  It uses a very clever encoding of
dimensions using prime numbers and rational numbers that makes handling
arithmetic with dimensioned quantities very slick.  For example,
addition and subtraction are allowed if the rational numbers encoding
the dimensions are =, multiplication and division just require
multipying or dividing the dimension encoding.  Prime factorization is
only needed when printing, not internally, so it has very little impact
on performance.

It was written up in Lisp Pointers:

  R. Cunis, "A Package for Handling Units of Measure in Lisp",
  _ACM Lisp Pointers_  5(2), 1992.

The code itself can be found at the CMU archives,

  http://www-2.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/code/syntax/measures/0.html

or in an updated version as part of the Loom distribution (which I
worked on).

   http://www.isi.edu/isd/LOOM/how-to-get.html

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Tagore Smith
Subject: Re: Beautiful code
Date: 
Message-ID: <1146227321.944359.159150@y43g2000cwc.googlegroups.com>
Tagore Smith wrote:

> So bring out the best that you have seen- an ingenious idea, a sleight
> of mind,  a piece of code written by a mentor who has shuffled off this
> coil, but left some code behind. Some beautiful code, please.

Thanks to everyone who has nominated code. I'm familiar with a few of
these systems, but some of them are new to me. At any rate, you've
given me enough stuff to read through for the next year or two, so
thanks to everyone who added a suggestion to this thread.

Of course I have a follow up: take the system you think exemplifies
great code and explain why it is great. I don't expect many takers with
this proposition- if nothing else, it is sure to be a lot of work. But
consider it please.. it is not unusual to hear people argue that CL is
"better", in some sense, than other commonly used languages. A few
really good examples would go a long way toward justifying that claim.
They might also serve a didactic purpose.
From: Paolo Amoroso
Subject: Re: Beautiful code
Date: 
Message-ID: <87u08d7tpo.fsf@plato.moon.paoloamoroso.it>
"Tagore Smith" <······@tagoresmith.com> writes:

> Of course I have a follow up: take the system you think exemplifies
> great code and explain why it is great. I don't expect many takers with

I nominated Lisa:

  http://lisa.sourceforge.net

I think that it is great code because it is "neat", "idiomatic", with
small functions and well-chosen symbol names.  It is easy to
understand most of the code even if you have limited familiarity with
the problem domain.

Lisa may be one of those systems that explain things with code rather
than comments.  So the limited availability of comments is not a
problem.


Paolo
-- 
Why Lisp? http://wiki.alu.org/RtL%20Highlight%20Film
The Common Lisp Directory: http://www.cl-user.net
From: Eddie Corns
Subject: Re: Beautiful code
Date: 
Message-ID: <e2tq5j$622$1@scotsman.ed.ac.uk>
"Tagore Smith" <······@tagoresmith.com> writes:


>Tagore Smith wrote:

>> So bring out the best that you have seen- an ingenious idea, a sleight
>> of mind,  a piece of code written by a mentor who has shuffled off this
>> coil, but left some code behind. Some beautiful code, please.

>Thanks to everyone who has nominated code. I'm familiar with a few of
>these systems, but some of them are new to me. At any rate, you've
>given me enough stuff to read through for the next year or two, so
>thanks to everyone who added a suggestion to this thread.

I think others would like to see this.  How about putting the links in a more
permanent place like cliki?

>Of course I have a follow up: take the system you think exemplifies
>great code and explain why it is great. I don't expect many takers with
>this proposition- if nothing else, it is sure to be a lot of work. But
>consider it please.. it is not unusual to hear people argue that CL is
>"better", in some sense, than other commonly used languages. A few
>really good examples would go a long way toward justifying that claim.
>They might also serve a didactic purpose.

and these could go there too.

Eddie
From: Paolo Amoroso
Subject: Re: Beautiful code
Date: 
Message-ID: <87ejzhfphh.fsf@plato.moon.paoloamoroso.it>
·····@holyrood.ed.ac.uk (Eddie Corns) writes:

> "Tagore Smith" <······@tagoresmith.com> writes:
[...]
>>Thanks to everyone who has nominated code. I'm familiar with a few of
>>these systems, but some of them are new to me. At any rate, you've
[...]
> I think others would like to see this.  How about putting the links in a more
> permanent place like cliki?

A long time ago, in a CLiki far away, I created a page for this
purpose:

  http://www.cliki.net/Anthology


Paolo
-- 
Why Lisp? http://wiki.alu.org/RtL%20Highlight%20Film
The Common Lisp Directory: http://www.cl-user.net