Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
6Activity
0 of .
Results for:
No results containing your search query
P. 1
Lambda the Ultimate

Lambda the Ultimate

Ratings:

4.0

(1)
|Views: 294|Likes:
Published by Riccardo Mantelli

More info:

Published by: Riccardo Mantelli on Apr 01, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

11/08/2011

pdf

text

original

 
LinuxUser & Developer
51
L
isp has come in from the cold. After years enduring the icy Artificial Intelligence (AI) winter, a period in the late eightieswhen Lisp was dumped by many thanks to associations withover-hyped AI research, and a frosty decade in academic obscurity,the open source community has dusted down this unique language,and freshened her up with lemon odour. Or rather Lemonodor.com, ahigh profile Web site which actively promotes and describes Lisp useand can readily be considered the Slashdot of the Lisp world, hasperformed this service for the community.Like a proud mother, Lisp, probably the oldest language still in usetoday, can view her children and remark on how their best features allstem from her genes or rather memes. Flexibility and speed of development are her watchwords, and key enabling features of thelanguage, such as run-time typing and an interactive approach tointerpretation or compilation have been adopted by newer languagessuch as Python. Yet, Python misses the killer core or inner beautywhich so many celebrate in Lisp.To approach this core takes more than simply enumerating Lisp’sgood points. To hijack Python guru, Tim Peter’s, words, “Goodlanguages aren’t random collections of interchangeable features: theyhave a philosophy and internal coherence that’s never profitablyconfused with their surface features.” Understanding Lisp is a gradualprocess, and involves some degree of immersion in the history,philosophy and culture of Lisp as well as a gentle involvement withcoding to further elucidate core concepts such as recursion andmacros. Yet, Lisp, with an array of dialects, libraries andimplementations is far from the easiest language to get up andrunning with, in contrast to Python, which obviously presents a onestop shop. And although a clear conceptual understanding can bereadily sought in printed works such as The Little Lisper or in Abelsonand Sussman’s seminal Structure and Interpretation of Computer Programs (SICP), practical advice which would further support thisknowledge is sorely lacking within the community. As we’ll see,certain initiatives are under way to resolve these issues, but aside fromevangelising Lisp, an effort which is close to achieving its goals, morework does need to be done in this direction, and this short articleonly aims to provide an overview for the intelligent and necessarilyintrigued beginner.No-one has been more instrumental in persuasively arguing thecase for Lisp than coder and writer Paul Graham (see Hackers andPainters, LU&D 42), whose own work with Viaweb is good testamentboth to the power of Lisp as an expressive language and Lisp’srelevance within enterprise level, large-scale projects. Graham’s essaysand books provide a singular practical and conceptual resource,elegantly tying real world arguments within a neat conceptualbundle, which is well wrapped up by his strong theoretical groundingand knowledge of the language. He speaks from experience, andthose who paraphrase Graham without his depth of understandingwill always sound a bit hollow. Nevertheless, Lisp’s features andadvantages must be outlined, and these can readily be pinned downboth to a decent level of abstraction and to highly usable abstractionsthemselves, such as closures and macros. It’s worth remembering thatLisp belongs within the family of functional languages, which impliesmodularity, an essential requirement for large-scale, complex projects. Suchabstractions, and features such as automaticmemory management, courtesy of built-ingarbage collection, readily enable new waysof programming, and this is Lisp’s greatadvantage.Sure, the semi-interpreted nature of Lisp, with functions able to betried and tested at the interactive REPL (Read Eval Print Loop) prompt,or so called top level, assists in rapid development, and, Grahamproffers amusing examples of improving server software on the fly,but Lisp’s real advantage remains in its extensibility which can readilybe seen as stemming from a core feature of the language; the factthat Lisp programs are expressed as Lisp data structures. Indeed, JohnMcCarthy, a key figure within AI and inventor and primaryimplementor of Lisp, remarks in an essay on the early history of Lisp,that “One can even conjecture that Lisp owes its survival specificallyto the fact that its programs are lists, which everyone, including me,has regarded as a disadvantage.” Hacker, Pascal Constanza, arguesthat this core feature makes of Lisp much more than just another Turing complete language, and this notion, which embeds acomplete theory of computation within Lisp, is arich seam to mine, with demanding papers onthis subject furnished by the likes of Graham,Sussman and Guy Steele, another major player inthe early life of Lisp, and co-inventor of theintriguing Connection Machine.
MORE TO LISP THAN LISTS
Extendibility here means both extending the Lisplanguage itself in a completely transparentmanner, thus building a domain specificlanguage for the application, and providing thefacility for others to readily extend and customisean application. In the first instance, the field of equivalence between software and data allowsfor coding custom languages with powerfulabstractions, and in the latter case, this form of what Graham calls bottom-up programmingnaturally results in extensible software, with GNUEmacs as prime example here. From thisperspective, Lisp isn’t about writing applications,it’s about writing languages. And, given thegrowing complexity of both hardware andcontemporary software systems, this heavilymodular, high level approach to programmingand systems architecture is seriously compelling.Indeed, pioneers Sussman and Abelson prefacetheir essential SICP volume with clear indicationsof how to control complexity, throughestablishing conventional interfaces, andestablishing new languages. And, alongside those who claim that Lisp isunusable due to an arcane syntax whichmultiplies parentheses, some would still maintainthat Lisp is slow, and argue thus that the needfor speed has lost out in the battle withcomplexity. But, given that nearly all modernimplementations compile during interpretation,following a just-in-time model, or allowspecifically for interactive compilation, speed israrely an issue. And the speed of prototyping or coding is a further issue which should also enter the equation. With Lisp, at least one has greater options for exploration and prototyping, and, if needs be, optimisations can be furnished later inthe day. Such notions regarding Lisp as sluggishbelong within an old-fashioned view of Lispwhich focuses on syntax and on lists, arguingthat LISP stands for List Processing Language,and which corrals this powerful language withinan academic prison. The new view of Lisp is that,
Coding with Lisp
‘A hip, burgeoning free software community is currently pushing Lisp, arguably the oldestprogramming language in common use, to the fore as a next generation coding platform. Self-confessed Lisp newbie, Martin Howse, presents the first part of an accessible guide to theculture of this flexible language, and practical implementations under GNU/Linux’
Lambda The Ultimate
The art of Lisp, or coding as philosophy
Coder’s dream oruser’s nightmare?Symbolics Generaenvironment was aLisp hacker’sparadise, allowingcoders to dig deepinto Lisp hardware
Good languages aren’t random collections ofinterchangeable features: they have a philosophyand internal coherence that’s never profitablyconfused with their surface features
Coding with Lisp
50
LinuxUser & Developer
 
52
LinuxUser & Developer
given automatic highlighting and indentation,parentheses and other syntactical issuesdisappear. Lisp is a far more flexible languagethan the acronym would suggest.
GETTING META
 A further consequence of the flattening of software and data as quite distinct animals, isthat Lisp really does live in the land of the meta,and that’s a place where a good fewsophisticated coders and theorists like to hangout. Douglas Hofstadter, in his seminalmathematical and meta-math work, Godel,Escher, Bach: An Eternal Golden Braid, providesmany mind stimulating adventures at the meta-level, and Lisp makes for a very natural fit here. And yet another consequence of the muchvaunted data/software equivalence, is theunusual defining quality that Lisp can be writtenin itself. In practice, this can be achieved in veryfew lines of code, and such a resulting beast isthe rather frightening metacircular interpreter or metacircular evaluator. This creature lies at thevery heart of an understanding of the history andconceptual underpinnings of Lisp, and writingsuch an interpreter forms a useful exercise for thenovice. Again this is another rich seam wellworthy of further investigation, and the intriguedcould start with Graham’s excellent paper, TheRoots of Lisp, or plough straight into Abelsonand Sussman’s work. Indeed, in their heyday, these pioneers werechurning out meta-circular evaluators for subsets and dialects of Lispat an alarming rate, and their work forms an important link betweenthe more exciting aspects of mathematics, philosophy and computer science. Another valuable starting point here would be the commonassertion that the proof of Godel’s incompleteness theorem, which isessential to an understanding of AI, would have been easier if he hadinvented Lisp first, given Lisp’s predilection for the meta-circular. Andjust before any unthinking C coders chime in, a C compiler written inC, which can be used for bootstrapping, does not belong in the realmof the metacircular which further specifies that precise semantics mustnot be defined in the evaluator. Thecommon parallel is with looking up aword in the dictionary, and findingthat the definition uses the originalword. That is how things work with aLisp written in Lisp; eval, which quiteobviously evaluates expressions, isimplemented by calling eval. Incontrast, a C compiler must specifydetailed and precise semantics for each and every construct, and takecare of boring old parsing. The REPLdefines all that is needed to build aLisp interpreter; read an expression,evaluate it and then print the results. Ithas to be admitted that there’s acertain beauty and simplicity at workhere, and Lisp is certainly unique inthis respect. A good deal of this simplicity stemsfrom Lisp’s roots, with the theoreticalwork of John McCarthy in the 1950s,which touches on all the richthematics wrapped up by Godel’swork in the sphere of mathematics.Both McCarthy and Graham write wellon this early history of the language,and their texts make for essentialreading. McCarthy did not set out to design and create aprogramming language to meet specific programming needs or satisfy a problem domain, rather he was interested in mathematicalnotation and expressing theory. This makes Lisp unique in the field of programming, and quite distinct from the functionality associatedwith C or C++. Lisp is a flexible, theoretical language which isprimarily expressive.Rather than jogging through the history of Lisp, which is wellrehearsed elsewhere by the likes of McCarthy and Steele, Graham’sRoots of Lisp paper presents a conceptual walk-through of the birth of Lisp, with McCarthy’s notation translated into Common Lisp code,and along the way he provides a good description of the primitiveLisp forms, which are function calls or macros, before arriving at the
Coding with Lisp
L-Lisp, running with an OpenGL Lisp library, puts some life back into a code heavy subject,with Lindenmayer systems readily simulating plants and fractals
Lisp lives inthe land of themeta, andthat’s a placewhere agood fewsophisticatedcoders andtheorists liketo hang out
Another consequence of the much vaunteddata/software equivalence, is the unusualdefining quality that Lisp can be written in itself
 
LinuxUser & Developer
5554
LinuxUser & Developer
than Common Lisp, more elegant and crystalline, as opposed to thebaroque, full features of Common Lisp. But there are greatsimilarities between the languages, and core features of Schemesuch as continuations, which freeze the state of a computation for later use, can readily be achieved with macros under Common Lisp.Once again, it seems that languages cannot so readily be boileddown to a feature set.The relative size of Scheme is also anissue. Given that Lispdoesn’t really bother about the differencebetween built-infunctions and user-defined functions, it’sa tough call to decidewhere the core language ends and library functions begin. Under  ANSI Common Lisp, the piece of string is certainly seen as being agood deal longer than under Scheme, but to do any useful workSchemers may have to take on board some supplementary libraries.It is perhaps more fitting to investigate specific implementations,with PLT Scheme as a hot favourite on that side of the Lisp fence.Scheme does have a lot of things going for it, and contrary to theargument that Scheme’s simplicity and beauty don’t play well withreal-world issues, it is totally possible to produce enterprise levelapps under Scheme. That said, the free software Common Lispcommunity, grouped around hearty resources such as cliki.net andLemonodor, just seems much more active, though there is a gooddeal of crossover, with seasoned hackers turning their hands to bothdialects. For the sake of simplicity, Scheme will remain outside thescope of these articles, with the caveat that an understanding of theconceptual underpinnings of Scheme and the lazy evaluation whichcontinuations facilitate can prove suitably enriching for any hacker.Beyond this essential conceptual background, what the newbiesorely needs to know are the specifics of respected implementationsand how to get up and running with these most efficiently. Sure youdetailed explication of aneval function written inLisp. Graham describesLisp’s elegant syntax andnotation, and key termssuch as expression, form,list and atom. Alongsidesix primitive operators,the quote operator,which has obviousparallels with quotationin the English language,is well described asfunctioning to distinguishdata from code. Thelambda notation for denoting functions isclearly elaborated, andwith great elegance,Graham whips out asurprise Lisp eval, writtenusing functions built fromonly seven primitives.Further functions can beelaborated and evaluatedusing this eval, which canreadily be transformedtowards a contemporaryLisp, and thence bendedtowards implementationswhich can easily furnishabstractions such asobject-orientedprogramming (OOP).Indeed, in his excellent ANSI Common Lisp,Graham shows as anexercise how a minimalOOP can beimplemented inCommon Lisp, withoutusing CLOS (CommonLisp Object System)features. His preliminarylanguage is implementedin just eight lines of code.Under the mini OOP embedded language, when it comes down toimproving the syntax of message calls to make them read more likeLisp, the rather more complex meta world of macros is encountered.Once again macros come courtesy of the uniform treatment of codeand data as forms for manipulation. Graham has devoted the wholeof the huge On Lisp volume to macros, which he considers of greatimportance within the paradigm of bottom-up programming, andmacros are certainly an essential, if hard to learn, feature which allowsfor writing programs that write programs. Macros are quite simplyfunctions which transform expressions and they can themselves callother functions and make use of other macros; a heady brew indeedwhose power of transformation is unheard of elsewhere. To clear upany confusion, macros under Lisp have little to do with their C-basednamesakes, which perform purely string substitutions. Macros allowthe language to play with its own readily accessible internals as data,and a good many Common Lisp functions are implemented asmacros themselves. Understanding macros is one thing, and makinguse of them perhaps even more complex, but given the definitionthat macros are simply operators that are implemented bytransformation, and noting a few example expansions which canreadily be tested with the macroexpand-1 function should set thebeginner on the right track.
SCHEMING
Though Lisp’s history post-McCarthy does make for interestingreading, with colourful anecdotes peppering the story of computer science’s most philosophical language and furnishing a classicnarrative of riches to rags and back again, there is little here that istotally relevant to the contemporary Lisper, aside perhaps fromintriguing material covering the hardware implemented LispMachines and their associated development environments such asGenera, which few contemporary IDEs can even dream of competing with. It’s also worth bearing in mind that given Lisp’sflexibility and extendibility which make it easy to create quiteradically different dialects of Lisp, Lisp should really be considered asa family of languages rather than a language in its own right. Anduntil the early to mid 80s the Lisp world was seriously splinteredwith competing dialects and implementations proliferating. Toaddress these issues, hardcore Lisp hackers gathered to standardise anew language, Common Lisp, which is the main Lisp in use today,alongside Scheme, an unusual, elegant dialect created by Sussmanand Steele in the late 70s. Common Lisp is well specified inCommon Lisp the Language, or CLtL for those in the know,authored by Guy Steele. ANSI standardisation for Common Lispfollowed a few years later.Thus, one of the first choices facing the novice Lisp coder, beforeeven considering free implementations, is whether to ride withCommon Lisp or Scheme. There can be no easy answer and thequestion has probably fed more flame wars in both communitiesthan any other issue. Researching the culture of both dialects canthrow interesting light on theoretical issues under both languages,and it’s relatively easy to grasp the fundamental differences in feeland approach. Scheme does have a particularly interesting history,and its creation is considered as of seminal importance within thehistory of computing, resulting as it does from an attempt tounderstand Actors, Carl Hewitt’s message passing model of computation. Scheme can be viewed as a more minimal language
The Lemonodor effect
The Common Lisp community has certainlygone from strength to strength in the lasttwo years, with blogs and wikis as primarymedium for the sharing of enthusiasm,inspiration and information. There are blogsby and for newbies, and blogs from oldhands such as Rainer Joswig, and sometimeLU&D contributor, Daniel Barlow. However,the Slashdot of all Lisp weblogs, if such athing can be imagined, is surely Lemonodor,clearly signalling that Lisp is the new rock and roll with a mix of hardcore news fromthe Lisp community, John Wiseman’s artisticLA lifestyle reports, and a marked emphasison Lisp within the field of robotics.Lushly produced, with intriguingillustrations often loosely associated with thetopic at hand, Lemonodor is a legend in theland of Lisp. And a mention by Wiseman of asite, surely results in record traffic, if not of Slashdotting proportions. Even one of thebest free Common Lisp IDEs, SLIME, makesmention of achieving Lemonodor fame in thestartup routines. Inspired by Planet GNOME,Planet Lisp acts as meta blog, collectingessential content from a huge number of Lisp-related weblogs. Despite sometimes strayingfrom the Lisp path into territory which indeedmay rival the poor signal-to-noise ratios of Slashdot, Planet Lisp does make for a decentdaily immersion in Lisp culture.With plentiful RSS feeds, and much crosslinking the Lisp world is well connected, andthe greatest resource of them all, cliki.netcollects much of these links and blogs andprovides further essential resources. Cliki.net,powered by Daniel Barlow’s CLiki engine, aCommon Lisp wiki, is well worth checking outchangelog-wise on a daily basis. The practicallisp page is a useful starting point for newbies,if somewhat dated in respect to SLIME use,but cliki.net does provide links or informationon practically every aspect of Lisp culture andpractice. Parodying or mirroring theevangelicism of a religious Web site, anotherCLiki, the ALU (Association of Lisp Users) wiki,is packed with so called “Road to Lisp” pageswhich demonstrate the fervent admirationwhich Lisp provokes. Unfortunately, the ALUwiki has recently been the subject of prolonged spam attacks, and its active lifedoes appear to be in danger. Other CLikis of note include the *hyper-cliki*, an annotatableCommon Lisp reference, and the wonderfullyfunky TUNES project CLiki which outlines arange of projects and resources towards thecreation of a free reflective computing system,or Lisp-based OS. Other essential onlineresources linked from cliki.net, include theCommon Lisp Cookbook, an attempt to createa community resource parallelling the PerlCookbook approach and both Successful Lispand Practical Common Lisp, two essentialonline works.
Coding with Lisp
Scheme can be viewed as a more minimallanguage than Common Lisp, more elegant andcrystalline, as opposed to the baroque, fullfeatures of Common Lisp
Key Links
Lemonodorwww.lemonodor.comSICPmitpress.mit.edu/sicpPaul Grahamwww.paulgraham.comJohn McCarthywww-formal.stanford.edu/jmcGuy Steelelibrary.readscheme.org/page1.htmlPLT Schemewww.plt-scheme.orgPlanet Lispplanet.lisp.org*hyper-cliki*lisp.tech.coop/indexALU wikialu.cliki.net/indexCLikiwww.cliki.net/indexTUNES projecttunes.orgSuccessful Lispwww.psg.com/~dlamkins/sl/contents.htmlPractical Common Lispwww.gigamonkeys.com/bookCommon Lisp Cookbookcl-cookbook.sourceforge.net
can fire up, say, CLISP, a pleasant, simpleCommon Lisp interpreter, straight from thecommand line and throw a few Lisp expressionsat it, but to get some decent work done you’llneed a more powerful implementation whichintegrates well with an editor such as GNUEmacs to form an efficient IDE. In parttwo, we’ll pit SBCL against CMUCL, thetwo favoured free implementations,integrate these tightly with GNU Emacsusing a touch of SLIME, throwpackaging and packages into the mixand touch on embedding andextending with Lisps such as librep andfunctionalities such as FFI (ForeignFunction Interface).
Lushly produced, withintriguing illustrations oftenloosely associated with thetopic at hand, Lemonodor is alegend in the land of Lisp
SLIME on GNU Emacs makes for a contemporary IDE which matches up to the power andsheer flexibility of Lisp languagesDebugging is a fine art under Common Lisp, and along with packaging and macros canreadily confuse the beginner
Coding with Lisp

Activity (6)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Vandrefalk liked this
Bikash Gyawali liked this
neuro_shift9502 liked this
Logickle liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->