Welcome!

You will be redirected in 30 seconds or close now.

ColdFusion Authors: Yakov Fain, Jeremy Geelan, Maureen O'Gara, Nancy Y. Nee, Tad Anderson

Related Topics: ColdFusion

ColdFusion: Article

Improve Your Coding Smarts with ColdFusion

Getting to the source of continuations, closures, and first-class objects

If you read CF-related blogs, you've undoubtedly stumbled upon discussions of seemingly arcane subjects like continuations or closures or first-class objects or absence of side effects. It's likely bloggers have tracked down the source - some would say fount - of such concepts and you'll find them waxing eloquent. As they should.

This short article shows how you too can find the source, play with it, and maybe join the ranks of the anointed.

The source is Lisp, a functional kind of language - as opposed to a procedural, OO or logical language. One of the oldest programming languages, its theoretical basis is found in the Princeton mathematician Alonzo Church's Lambda Calculus, essentially a logic system concerned with functions. It was adapted to computing by MIT's John McCarthy in the late 1950s as Lisp, and has continued to evolve ever since alongside the successive blooming of Fortran, Cobol, Basic, Pascal, C++, and Java. Indeed, Lisp has been a mainstay for artificial intelligence research and widely known as the basis of Emacs and a number of commercial products, an illustrious enough lineage for numerous authors to write histories of the language.

This evolution has spawned many dialects and implementations. Which one to use? Judging from the number of references to them on the Web, a short list of possibilities would include Haskell, OCaml, F#, Scheme, CommonLisp, newLisp, PicoLisp, and Scala. They all have pluses and minuses, adherents and detractors. After downloading and playing with most of those just listed, I finally decided that a small footprint, decent documentation, a modern feature set, and open source were sensible criteria, so I chose newLisp. In addition, I have no plans to develop large, compiled, applications with Lisp - at least not at present.

Just as Perl has Larry Wall, Python Guido van Rossum, and Ruby Yukihiro "Matz" Matsumoto acting as benign dictators or gurus, newLisp has Lutz Mueller. It is now at version 9.1.x and has been under active development for years.

Setting up your environment to code in newLisp is easy. Go to www.newLisp.org and download the implementation for your machine; unzip the download into any directory and double-click on the executable (newlisp-tk.exe on Windows or newlisp-tk on *nix); what opens is a simple editor written in Tk. In that editor, type (mul (add 5 6) (sub 8 4)) and hit enter. You've just run three built-in functions: added 5 and 6 to get 11, subtracted 1 from 8 to get 7, and multiplied those two results to get 77. Lisp is evaluated generally from right to left, inner to outer parentheses; the result of each evaluation is passed to the next function on the left. Return to the newLisp Web site and read the excellent tutorials, examples, and other documentation.

Well, after playing with newLisp for a couple of weeks and developing a smooth workflow process with the editor, I started to rewrite a small CFML algorithm that checks whether a comma-delimited string of U.S. states and/or Canadian provinces is contiguous. It's used by a government agency as part of a process of validating applications for commercial vehicle licenses.
Because the "contiguity checker" uses many features common to all languages - looping, conditional logic, containers (arrays, lists, etc.) - it's a perfect newby learning experience; after all, the basic logic had already been worked out and humming along in production. During the rewrite, and much to my surprise, I found a way to make the algorithm more efficient. To see how the Lisp syntax differs from CFML, see Listing 1.

Then I discovered that Lutz had written a little utility included in the original download. The utility, link.lsp, packages any script you write with the newLisp interpreter to produce a standalone executable - which can then be called from a ColdFusion template using <cfexecute....>. Called from within a CF template using <cfexecute....>, the execution is about 10% slower than the straight CF version. Run from the newLisp-Tk shell, the newLisp version executes faster than the CF version, which is expected because the newLisp interpreter is written in C.

I attribute discovering a more efficient algorithm to the fact that writing Lisp really did require a subtle change in consciousness that felt, to use an adjective posted more than once elsewhere, Zen-like in its focus and clarity. It's difficult to put this internal experience into words but it was like what I experienced years before when laying a floor.

You see, while building a house and with overruns draining the wallet, I decided to forego subcontracting the job of setting the foyer's floor with irregularly shaped and variably sized natural slate, figuring I could do it some weekend. I marked off an 8-by-12-foot area on the garage floor and, with the pile of slate at hand, began arranging the slabs. After hours of labor, the arrangement still looked crappy and I stopped to rest my aching back and began to wonder if professional stonemasons had some sort of secret for laying out natural stones in a pleasing pattern.

Maybe it was the fatigue, maybe it was letting go after trying so hard for so long, but suddenly I began to view the task completely differently: I stopped looking at the slabs themselves and began to look at the spaces between them. After that, the task seemed simple; it took only about 20 minutes to create a nice arrangement. Such thought reversals are akin to those gestalt drawings where, if you stare at them, the foreground becomes background and vice versa, but in this case the mind-shift facilitated the task, presumably because paying attention to the spaces between the slabs shifted my attention to the relationships between them. It is within the relationships that a pattern became obvious.

This kind of experience seems the norm for Lisp coders and has been much written about. For instance, Eric Raymond says, "Lisp is worth learning for the profound enlightenment experience you'll have when you finally get it; that experience will make you a better programmer for the rest of your days, even if you never actually use Lisp itself a lot."

Although answering the question "How does Lisp do this?" is beyond the scope of this brief article, Paul Graham, a well-known writer about Lisp, asserts that it promotes "bottom-up" design (www.paulgraham.com). In other words, you "grow" code, rather than "construct" it; it feels like an organic process because functions are also data objects. Another writer notes that Lisp is the ultimate "verb" language while contrasting it with Java, which he describes as a "noun" language. (See "Execution in the Kingdom of Nouns," http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html)

Plenty of Web sites extol the virtues of Lisp and to get you started, surf to Graham's site and then to a Google video (http://video.google.com/videoplay?docid=448441135356213813). Two other inspiring sites are www.defmacro.org/ramblings/lisp.html and www.norvig.com/. And, if you really get motivated, read Peter Seibel's book "Common Practical Lisp," which is so beautifully written that it's a pleasure to read even if you never tickle a Lisp interpreter.

More Stories By Tim Burton

Tim Burton is the eGovernment Applications Architect for a large state agency in Oregon and has been writing CFML since 1998. This is his third career; he previously practiced medicine and made art (metal sculpture).

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
Announcing Poland #DigitalTransformation Pavilion
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
DXWorldEXPO LLC announced today that All in Mobile, a mobile app development company from Poland, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. All In Mobile is a mobile app development company from Poland. Since 2014, they maintain passion for developing mobile applications for enterprises and startups worldwide.
CloudEXPO | DXWorldEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
The best way to leverage your CloudEXPO | DXWorldEXPO presence as a sponsor and exhibitor is to plan your news announcements around our events. The press covering CloudEXPO | DXWorldEXPO will have access to these releases and will amplify your news announcements. More than two dozen Cloud companies either set deals at our shows or have announced their mergers and acquisitions at CloudEXPO. Product announcements during our show provide your company with the most reach through our targeted audienc...
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22nd international CloudEXPO | first international DXWorldEXPO and will feature technical sessions from a rock star conference faculty and the leading industry players in the world.
Everything run by electricity will eventually be connected to the Internet. Get ahead of the Internet of Things revolution. In his session at @ThingsExpo, Akvelon expert and IoT industry leader Sergey Grebnov provided an educational dive into the world of managing your home, workplace and all the devices they contain with the power of machine-based AI and intelligent Bot services for a completely streamlined experience.
DXWorldEXPO | CloudEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
In his keynote at 19th Cloud Expo, Sheng Liang, co-founder and CEO of Rancher Labs, discussed the technological advances and new business opportunities created by the rapid adoption of containers. With the success of Amazon Web Services (AWS) and various open source technologies used to build private clouds, cloud computing has become an essential component of IT strategy. However, users continue to face challenges in implementing clouds, as older technologies evolve and newer ones like Docker c...
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
JETRO showcased Japan Digital Transformation Pavilion at SYS-CON's 21st International Cloud Expo® at the Santa Clara Convention Center in Santa Clara, CA. The Japan External Trade Organization (JETRO) is a non-profit organization that provides business support services to companies expanding to Japan. With the support of JETRO's dedicated staff, clients can incorporate their business; receive visa, immigration, and HR support; find dedicated office space; identify local government subsidies; get...
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
In past @ThingsExpo presentations, Joseph di Paolantonio has explored how various Internet of Things (IoT) and data management and analytics (DMA) solution spaces will come together as sensor analytics ecosystems. This year, in his session at @ThingsExpo, Joseph di Paolantonio from DataArchon, added the numerous Transportation areas, from autonomous vehicles to “Uber for containers.” While IoT data in any one area of Transportation will have a huge impact in that area, combining sensor analytic...
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
Charles Araujo is an industry analyst, internationally recognized authority on the Digital Enterprise and author of The Quantum Age of IT: Why Everything You Know About IT is About to Change. As Principal Analyst with Intellyx, he writes, speaks and advises organizations on how to navigate through this time of disruption. He is also the founder of The Institute for Digital Transformation and a sought after keynote speaker. He has been a regular contributor to both InformationWeek and CIO Insight...
Michael Maximilien, better known as max or Dr. Max, is a computer scientist with IBM. At IBM Research Triangle Park, he was a principal engineer for the worldwide industry point-of-sale standard: JavaPOS. At IBM Research, some highlights include pioneering research on semantic Web services, mashups, and cloud computing, and platform-as-a-service. He joined the IBM Cloud Labs in 2014 and works closely with Pivotal Inc., to help make the Cloud Found the best PaaS.
It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...
I think DevOps is now a rambunctious teenager - it's starting to get a mind of its own, wanting to get its own things but it still needs some adult supervision," explained Thomas Hooker, VP of marketing at CollabNet, in this SYS-CON.tv interview at DevOps Summit at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.