EiED Online>> Embedding With A Lisp

July 8, 2004
Volume 2004, Number 5

I've always had a thing for programming languages. I like to analyze them to see what features they bring to the table and how to take advantage of them. It's not surprising that I ran into Lisp rather early, although it was well after I wrote a Fortran development system in Basic. (Hey, Basic was the only thing that ran on the minicomputer I had access to.) I have not used Lisp for any production work in ages but that does not mean that others have not. In fact, varieties of Lisp have been showing up in everything from games to Web servers.

Before all you C, C++, and Java programmers start running for the door, consider Lisp as another tool that may fit into your toolbox. Although the use of multiple programming languages tends to be frowned upon, there are many good reasons for doing so especially if a mix gets the job done sooner. Besides, you might be surprised how easy it is to mix even something like Java with Lisp. Similarly, issues such as performance are myths on par with Java's myths.

First let's take a look at some of the players. This is not an exhaustive list by any means, but it will give you some options to investigate. Common Lisp is the Lisp heavyweight. Companies like Franz, Inc. provides Allegro CL with extensive support for standalone development of Lisp applications. There is a variety of database, knowledgebase, and GUI tools.

C and C++ programmers might want to investigate GNU Common Lisp. This uses the GNU C compiler technology and generates native code.

Guile is a variant of Lisp called Scheme. Scheme is a statically scoped and properly tail-recursive dialect of the Lisp programming language invented by Guy Lewis Steele Jr. and Gerald Jay Sussman while at MIT. Guile was designed as an extension language for use in applications such as Web services. The latest Scheme standard is R5RS (Revised Report on the Algorithmic Language Scheme), and it can be found at Schemers.org.

Kawa Scheme is another Scheme implementation that should interest Java developers, because Kawa turns Lisp code into Java byte codes. It is designed to interact with Java applications, allowing developers to select the language most suitable for a part of an application. Kawa is not alone in this approach. JScheme is another project that also generates Java byte codes.

The Java integration has some significant advantages. First, Java has a garbage collector, something Lisp pioneered and requires. Second, JIT (just-in-time), AOT (ahead-of-time) and other native code compilers bring the same performance optimizations to Lisp since they do not differentiate between the byte code source.

It looks funny Lisp stands for List Processing, but there have been many other descriptions provided such as Lots of Irritating Superfluous Parentheses. Experienced programmers without Lisp exposure normally go into shock when looking at a Lisp program for the first time, but after a little work Lisp coding becomes natural to the point where other languages now start to look arcane. Trust me.

Lisp code is not really totally foreign. Take this little snippet for example.

(case (variable-to-match?)
  ((match1)
   (function1 param1 param2 param3))
  ((match2)
   (function2 1 2 3))
  ((match3)
   (function3 "1" "2" "3"))
  (else
   (do-something-else "goodbye")))

You have probably guessed that this is simply Scheme's version of a case statement.

The one thing you can say about Lisp syntax is its consistency. A list (also called an s-expression) of items is shown between a pair of parenthesis. A function call translates to a list with a function name as the first element, although in the case of the case statement above, there is a little syntactic sugar too.

Simplicity is actually a key benefit of Lisp's syntax. It also blends nicely with data structures, because lists are used for that as well.

Getting into a long discussion about Lisp syntax and semantics is well beyond this article, but it's sufficient to say that there's not much you cannot do in Lisp and a lot that's easier than in other programming languages.

But it's slow, and other myths Assuming you have made it this far, you might be wondering why Lisp has not taken the world by storm. Lisp is actually very old. It is only preceded by Fortran in terms of age for high-level languages. Along the way, Lisp has seen a number of myths built up around it. For example, many consider Lisp to be a language for "artificial intelligence" (AI). While it is true that Lisp is a key language for AI applications, AI is not the only realm for Lisp. Lisp has been used in a range of applications from transportation scheduling to web scripting applications. Emacs was a popular text editor that was based on Lisp.

Performance is almost always an issue for embedded developers. It is often a reason that C is used instead of C++ or Java. Lisp is unlikely to take on C or assembler, but it is a viable alternative or adjunct to C++ and Java. Lisp compilers are as good as or better than those other popular languages.

Lisp applications can be found on high-end systems with gigabytes of memory but the same is true for C, C++, and Java. At the other end of the spectrum, Java fits into 2-megabyte systems and that's plenty for Lisp as well.

Garbage collection is a requirement for Lisp programs that run for any period of time. As I have mentioned in earlier EiED Online columns, garbage collection is not necessarily a bad thing from a performance standpoint, even compared to dynamic memory support in C and C++. In addition, Lisp programmers have never needed to worry about dangling pointers.

Learn on the job Taking a look at Lisp is not as hard as you might think. A number of excellent implementations are available as open-source software, so you can even look under the hood. Likewise, there are a number of training-oriented versions and support materials available over the Internet. It is worth a look, and it can be fun too.

Drop me a note with your stories about embedding Lisp or other less common embedded programming languages.

Related Links
Association of Lisp Users
www.lisp.org

Franz, Inc.
www.franz.com

GNU Common Lisp
www.gnu.org/software/gcl/gcl.html

Guile
www.gnu.org/software/guile/guile.html

JScheme
www.norvig.com/jscheme.html

Kawa Scheme
www.gnu.org/software/kawa

MIT/GNU Scheme
http://www.gnu.org/software/mit-scheme/

Schemers, Inc.
www.schemers.com

Schemers.org
www.schemers.org

About the Author

William G. Wong | Senior Content Director - Electronic Design and Microwaves & RF

I am Editor of Electronic Design focusing on embedded, software, and systems. As Senior Content Director, I also manage Microwaves & RF and I work with a great team of editors to provide engineers, programmers, developers and technical managers with interesting and useful articles and videos on a regular basis. Check out our free newsletters to see the latest content.

You can send press releases for new products for possible coverage on the website. I am also interested in receiving contributed articles for publishing on our website. Use our template and send to me along with a signed release form. 

Check out my blog, AltEmbedded on Electronic Design, as well as his latest articles on this site that are listed below. 

You can visit my social media via these links:

I earned a Bachelor of Electrical Engineering at the Georgia Institute of Technology and a Masters in Computer Science from Rutgers University. I still do a bit of programming using everything from C and C++ to Rust and Ada/SPARK. I do a bit of PHP programming for Drupal websites. I have posted a few Drupal modules.  

I still get a hand on software and electronic hardware. Some of this can be found on our Kit Close-Up video series. You can also see me on many of our TechXchange Talk videos. I am interested in a range of projects from robotics to artificial intelligence. 

Sponsored Recommendations

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!