views:

374

answers:

7

Reading well-written code seems to help me learn a language. (At least it worked with C.) [deleting the 'over-specified' part of the question]

I'm interested in particular in lisp's reputation as a language suited to creating a mini-language or DSL specific to a problem. The program ought to be open-source, of course, and available over the web, preferably.

I've Googled and found this example:

http://lispm.dyndns.org/news?ID=NEWS-2005-07-08-1

Anybody have another? (And, yes, I will continue reading "Practical Common Lisp".)

After 11 hours (only 11 hours!): Thanks, everyone. What a wonderful site, and what a bunch of good answers and tips!

+5  A: 

If you haven't taken a look at it yet, the book Practical Common Lisp is available free online and has several example projects.

totorocat
Second this, it's a fantastic Lisp book.
HappyCodeMonkey
Yes, I downloaded that this week, but have not dived in yet. It occurred to me that someone might know of a program or two that came at things from another angle: kind of the 'working code' vs. 'didactic code' difference.
behindthefall
The code in PCL *has* practical value.
skypher
I'm getting a bit long in the tooth to learn a new editor, and I have used gvim for years instead of emacs. Also, clisp under cygwin felt familiar and convenient. Turns out the book wants me to run Allegro from an emacs IDE, and it has (thanks, WinXP) installation/update problems. Something wrong with this picture ...
behindthefall
I use Vim and a console (SBCL w/ rlwrap and SB-ACLREPL) all day.
skypher
Have you (or anyone else) posted a description of how to get that arrangement up and running? Is it an arrangement that could be set up under cygwin? (I, too, run vim in a window and use a shell window to recall previous commands and rerun whatever I'm working on, which is puzzle-solvers in Python these days. Used to be image analysis in C and Tcl on Sun and SGI.)
behindthefall
+5  A: 

I feel your constraints are over-specified:

small enough to comprehend, varied enough to show off most of (c)lisp's tricks and features without being opaque (the 'well-written' part of the wish), and independent of other packages.

Common Lisp is a huge language, and the power set that emerges when you combine the language elements is much larger. You can't have a small program showing "most tricks" in CL.

There are also many concepts that you will find alien when you learn CL coming from another language. As such CL is less about tricks but more about its fundamental paradigms.

My suggestion is to read up on it a bit first and then start building your own programs or looking into open source code.

Edi Weitz for example usually writes good code. Check out his projects at http://www.weitz.de/.

And now go read PCL. :)

skypher
"or looking into open source code."Ah. Well, there you have it. Any recommendations, besides the textbook and the Weitz site (for which many thanks, BTW)? Remember I was looking for an example of the mini-language type of application, but independent of packages.
behindthefall
Here's a simple boolean language for a search engine: http://xach.livejournal.com/131456.html (this doesn't use macros, though).cl-cairo2 has some macro examples that form tiny DSLs (grep for defmacro).fare-matcher has a DSL for defining specific matchers (define-*-matcher).The iterate library (and the LOOP implementation) are both examples of a sophisticated DSL to write flexible loops.usocket has another tiny DSL that abstracts away the details of socket setup/teardown (e.g. WITH-CLIENT-SOCKET).Grepping through a decent clbuild checkout will show lots more.
skypher
Thanks. Will it become obvious to me how to find the code to the "iterate library"? This sounds like a fine example of the "extending the language with the language" genus, and I was recently wondering whether I ought to be satisfied with Python's sole and basic 'while' construct.
behindthefall
Is this the "iterate library" code you were referring to?http://common-lisp.net/project/iterate/darcs/iterate/iterate.lispYummmm.
behindthefall
Yes, that's it.
skypher
+2  A: 

The LOOP macro is an almost perfect example of a DSL embedded in Common Lisp. However, since it's already part of the standard, it may not be what you're after.

Vatine
+2  A: 

CLs format function have a mini dsl.

http://cybertiggyr.com/fmt/

I think that dsl for printing strings will compile to machine code.

(format nil "~{~A~#[~:;, ~]~}" lst))

Flinkman
+4  A: 

I'm kind of lazy to find the links, but you should be able to 'Google'/'Bing' it. The following list mentions very different ways to embed languages and very different embedded languages.

  • ITERATE for iterations
  • System/Module/File description in 'defsystem's, an example would be ASDF
  • infix readmacro
  • define-application-frame in CLIM for specifying user interfaces
  • embedded Lispified SQL queries in LispWorks and CLSQL
  • Knowledgeworks of LispWorks: logic language with rules, queries, ...
  • embedded Prolog in Allegro CL
  • embedded HTML in various forms
  • XMLisp, integrates XML and Lisp
  • Screamer for non-deterministic programming
  • PWGL, visual programming for composing music

Note that there are simple embedded languages and really complex ones that are providing whole new paradigms like Prolog, Screamer, CORBA, ...

Rainer Joswig
+2  A: 

CLSQL provides a Lispy notation for SQL queries, which it compiles to SQL, and just about all Lisp HTML and XML generation libraries qualify. Metabang bind is a DSL for lexically binding variables. You probably didn't know you needed one, but it turns out to be amazingly useful.

Zak
A: 

SERIES is kind of a DSL, depending on your definition. It's in an appendix to CLTL2, though it's not actually part of the language.

Ken