Hugh Winkler holding forth on computing and the Web

Showing posts with label lisp. Show all posts
Showing posts with label lisp. Show all posts

Thursday, January 01, 2009

Clojure uptick

Needing to build a standalone piece of server software as an add on to our Java product, I seized the opportunity to see how far Clojure has come. Getting my dev system set up, and learning the language, I noticed the results Google was returning for my queries were mostly very recent... and lots from just last month.



Could Clojure be approaching critical mass?

I've only written a hundred lines or so of code, but here are some random things I love:

1. Shorthand for maps: {:a 1 :b 3}.
2. sorted-map and hash-map -- thanks for letting me choose. Same shorthand syntax for either.
3. Shorthand to select a value from a map: the map is like a function name (my-map :a).
4. Shorthand for lambdas: #(...code...)
5. Shorthand for generating temporary symbols in macros: my-var#. No need to call (gensym).
4. No looping required -- use recur.
5. Java libraries are easy to use.

I haven't yet fiddled with modifying state.

It's free, it's functional, it's got a hardened standard library, it's got a REPL. You can write a program and deliver it on any platform. What could hold it back?

Saturday, June 14, 2008

Ruby: DSL for Writing Programs

Ruby:


PEOPLE = [{:first=>'scott', :last=>'guthrie', :age=>32},
{:first=>'susanne', :last=>'guthrie', :age=>32},
{:first=>'bill', :last=>'gates', :age=>50}]

def avg_age
guthries = PEOPLE.select {|p| p[:last] == 'guthrie'}
guthries.inject(0) {|s, p| s + p[:age]} / guthries.length
end



Common Lisp:


(defvar +people+
(list
(list :first "scott" :last "guthrie" :age 32)
(list :first "susanne" :last "guthrie" :age 32)
(list :first "bill" :last "gates" :age 50)))

(defun avg-age ()
(let ((guthries (remove-if (lambda (p) (not (equal "guthrie" (getf p :last)))) +people+)))
(/ (reduce #'+ (map 'list (lambda (p) (getf p :age)) guthries)) (length guthries))))



These snippets calculate the average age of the people having last name "guthrie". The functions are both two lines long, but the Ruby one is more readable.

S-expressions give Lisp powerful ways to build code in code. But writing programs using S-expressions seems cumbersome compared to Ruby's syntax. The syntax of Ruby shortens the code you have to write to do everyday tasks. It's like a domain specific language for, er, writing computer programs.

You give up some programming power -- a fair trade if you rarely need that power.

Saturday, April 12, 2008

Lisp a casualty of its time

This sad editorial remark from the CLIPS architecture document, describing perceptions about Lisp within NASA around 1984:


...Despite extensive demonstrations of the potential of expert systems, few of these applications were put into regular use. This failure to provide expert systems technology within NASA’s operational computing constraints could largely be traced to the use of LISP as the base language for nearly all expert system software tools at that time. In particular, three problems hindered the use of LISP based expert system tools within NASA: the low availability of LISP on a wide variety of conventional computers, the high cost of state-of-the-art LISP tools and hardware, and the poor integration of LISP with other languages (making embedded applications difficult).


Would they encounter the same barriers today, twenty-four years later?

1. Low availability of LISP on a wide variety of conventional computers: Now we have commercial implementations and open source Lisps, working on most computers and operating systems.

2.High cost of state-of-the-art LISP tools and hardware: The hardware issue has faded away since Lisp machines gave way to general purpose computers. And Lisp is no more memory intensive than Java or .NET. Of the commercial Lisps, LispWorks is affordable for normal mortals, and certainly the Allegro products are within reach of NASA. And there are several good, free, open source CLs.

3. Poor integration of LISP with other languages: An issue only if your mindset is 1984. Nowadays, to integrate with a Lisp program, you'd treat it like any other network resource -- like an RDBMS, or a web service.

I wonder what is the state of the Lisp renaissance within NASA?


[updated to expand remark on item 2]

Sunday, January 20, 2008

Clojure

Clojure is a Lisp that runs on the JVM. I agree with everything on this page describing the design rationale. Objects are overrated; functional and immutable are good. I can't wait to get a breather and figure out whether and where Clojure fits into our technology arsenal.

The real measure will be how well it can leverage the Java platform. There are plenty of great languages, but they have inconsistent support for, say, sockets, or window systems. Can I override a protected method of a Swing base class? Can I connect to an HTTPS server? JRuby has knocked Java integration out of the park, so you get all that capability for free, plus a powerful language.

Update: I think the bullet point "Extend Java in Java, consume Java from Clojure" on the rationale page suggests you can't easily write a Swing app in Clojure. Shoot.

Tuesday, January 15, 2008

And Speaking of Paul Graham...

Arc to be open sourced this winter. It's going to be hard to top the expectations.

Monday, January 14, 2008

The Truth about Lisp

Majorly funny. Leon Bambrick wrote (back in 2006):


If you're good enough to use lisp, you'll soon be frustrated with lisp. Lisp is not an adequate lisp. By the time my bus had made it two blocks I'd written some simple lisp macros that were so powerful they made lisp completely obsolete and replaced it with a new language. Fortunately, that new language was also called lisp. And i was able to prove, mathematically, that the new lisp i'd created was both far superior to lisp in every conceivable way, but also exactly equivalent to lisp in every possible way. I was very excited by this. But also found it very boring....Paul Graham himself was completely written in lisp, by an earlier version of himself, also written in lisp, by an earlier version of lisp. It's lisp, paul graham, lisp, paul graham, all the way down.

Friday, June 08, 2007

Hyperbolism of the Month

...goes to (the envelope please)... Elliotte Rusty Harold!:
Java’s exception handling is the single best error handling and reporting mechanism ever built into a programming language.

I personally don't think you're going to beat the Common Lisp condition system. You can emulate Java-style exception handling, but it's so much richer to be able to restart in the context where the error occurred, without unwinding the stack.

Wednesday, January 17, 2007

We're Writing Hardware

Using statically typed languages, we're constructing hardware, not software, says Steve. A great rant. Let me extend the analogy. Think about the bullet points they used to sell object oriented programming back in the 80s: "Hardened components", "Reusable". These qualities are the opposite of dynamic.

Wait! There's an alternative!

Common Lisp is in many ways really ideal: it's a dynamically typed language with optional type annotations (i.e. you build software, then selectively turn it into hardware), lots of great tools and documentation, all of the essential features of living software I've enumerated in this essay... However, it has stopped growing, and programmers can sense momentum like a shark senses blood.


Oh man. Don't give up on the old girl. The Lisp Renaissance is happening all around you. We have the popular book; now we just need the Django/Rails thing.

Thursday, January 11, 2007

The Volkswagen Lisp

I've been working in Lisp for about six weeks now, and I am far enough along to
get this.