TweetFollow Us on Twitter

Winter 91 - THE VETERAN NEOPHYTE

THE VETERAN NEOPHYTE

LISP, COLOR ICONS, AND LAYERS

DAVE JOHNSON

I recently started learning Lisp, in order to write a color icon editor for a project in ACOTSM (that's Apple Classroom of Tomorrow). The people behind ACOT are creating an environment in which kids can build and explore simulated ecologies, and I wanted to help, but didn't know Lisp well enough to be of much use. A color icon editor was needed, and it seemed like a straightforward and painless little project to cut my Lisp teeth on. Hah.

I did learn lots of Lisp, but I spent a disproportionate amount of time learning the low-level system interface in Macintosh Allegro Common Lisp (MCL) and wrestling Color QuickDraw to the ground. For you CopyBits fans, did you know that CopyBits always assumes that the destination PixMap is on the current GDevice? I guess I already knew this--it's documented all over the place--but the implications never affected me before. I needed to convert a 4-bit PixMap to 8 bits, so hey, let's use CopyBits, right? Wrong. The colors got munged every time, because color mapping kicked in and the source's color table didn't match the GDevice's. For the gory details, see Technical Note #277, especially the section on color mapping. If you like CopyBits, you'lllove this tech note.

I was curious what others thought of Lisp, so I asked around a little. Here are some of the responses I got:

Functional languages are cool if you have good libraries, but all those parentheses are a pain in the ass.
-- Bryan "Beaker" Ressler, C programmer.

It's the shortest distance between conception and realization.
-- Matthew MacLaurin, self-admitted Lisp junkie.

I hate it.
-- Neil Day, who was forced to write the Tower of Hanoi iteratively in an introductory Lisp course.

It's a great productivity tool, and Common Lisp provides a rich (though perhaps Byzantine) programming environment.
--Gregg Williams, technical writer and sometime Lisper.

(expectant look)
-- Natty, my dog.

There are several immediately apparent things about Lisp that are foreign to people used to C or Pascal. Data typing is nonexistent unless you want it: Any variable can hold any type of data at any time. Functions can be data, too, and can be passed around all over the place. Everything is cozily wrapped in parentheses many levels deep (after a while, this is somehow comforting). Context is all important and omnipresent. Changes can be immediately tried out, so forprototyping (and for those of us who thrive on immediate gratification) it's a joy to work in. For those lacking in discipline, Lisp can help to create a real mess (of course, any language can do that for you, it's just easier in Lisp). Because it is so forgiving, it encourages my own built-in "middle-out" design

strategy, which in the long run isn't terribly efficient, although lots of fun. With a little self-control, of course, this problem would go away (left as an exercise for the reader).

Writing Lisp code that is QuickDraw intensive is kind of a pain at first. MCL provides great libraries for basic QuickDraw tasks, but if you want to get fancy, you have to do it yourself. For the icon editor, I needed lots of little utility routines to do stuff like find a particular color's pixel value in the color table, add a color to a color table, copy a cicn, change the depth of a cicn, build new cicns from scratch. Nearly half my code consists of these little utilities. They'd be needed regardless of the language, I guess, but writing them in Lisp required me to learn the low-level system interface much more thoroughly than I originally intended. This made me grumble a little, but after I'd gotten over the initial syntactical hump, low-level access became transparent and largely effortless.

The other half of the code was much Lispier. I used the built-in object system (Object Lisp, since I was using MCL 1.3.2. Now, in MCL version 2.0, it's the Common Lisp Object System, or CLOS), and I found that it successfully isolated me from most of the grungy system details like events and window handling (that's what it's supposed to do, right?). I haven't done a lot of object programming, so I can't make incisive comparisons with other object systems, but I liked it.

The sort of layered, threaded structure of Lisp, and the continual "level switching" I had to do during development, got me thinking about how the machine is getting progressively more distant from the software I write. It seems that I write software to live on top of other software, not software to live on a machine. Object programming is a kind of layer creation, in that a well- designed object hides lots of details from the user of the object. MacApp is a layer (a thick one), HyperCard is also a layer (a really thick one), the Mac ® Toolbox is a layer, and so on.

More and more, programmers need to be comfortable stuffed between these layers. Here's the hard truth: YOU NO LONGER HAVE TOTAL CONTROL OF THE MACHINE. Once upon a time, in the dim and distant past, programmers had absolute power over every aspect of the computer. There wasn't even any such thing as a user! A programmer was God in a monotheistic universe. Now there are all sorts of software smoke screens between your code and the machine itself. You are no longer God; at best, you are a minor demigod in charge of shoes, or something. A long time ago I read a discussion of Macintosh programming, and one person compared it to sitting in a dark closet by yourself, and occasionally answering a note that is passed under the door from the outside. I think that's exaggerating a little, but the point is valid. You no longer need to know everything that's going on in the house; you can just be responsible for your own room. At least, that's the idea . . .

One persistent problem is that you have to depend on the reliability of the other code. When my icon editor was almost done, I found a memory leak. Two tiny handles were left on the heap after closing the editor. It took me almost a week (and some expert help) to track it down to a bug in the MCL object system. Obviously, this diluted the benefits gained by using the system.

Overall, though, I really do think that this division of labor, this layering, is a good thing. It lets people find the niche they like best, and ignore much of the rest if they want to. Often it is an incredible time-saver to learn to use others' code rather than learning to do what they did from scratch. Ideally, the layers will insulate you completely from irrelevant detail, and allow you to focus on your task. We're not there yet, but someday, maybe, you can actually stop inventing the wheel.

 
AAPL
$524.94
Apple Inc.
+5.93
MSFT
$40.01
Microsoft Corpora
-0.39
GOOG
$536.10
Google Inc.
-20.44

MacTech Search:
Community Search:

Software Updates via MacUpdate

VMware Fusion 6.0.3 - Run Windows apps a...
VMware Fusion allows you to create a Virtual Machine on your Mac and run Windows (including Windows 8.1) and Windows software on your Mac. Run your favorite Windows applications alongside Mac... Read more
Tweetbot 1.5.1 - Popular iOS twitter cli...
Tweetbot is a full-featured OS X Twitter client with a lot of personality. Whether it's the meticulously-crafted interface, sounds and animation, or features like multiple timelines and column views... Read more
Mac DVDRipper Pro 4.1.7 - Copy, backup,...
Mac DVDRipper Pro is the DVD backup solution that lets you protect your DVDs from scratches, save your batteries by reading your movies from your hard disk, manage your collection with just a few... Read more
PDFpenPro 6.2 - Advanced PDF toolkit for...
PDFpenPro allows users to edit PDF's easily. Add text, images and signatures. Fill out PDF forms. Merge or split PDF documents. Reorder and delete pages. Even correct text and edit graphics! Create... Read more
PDFpen 6.2 - Edit and annotate PDFs with...
PDFpen allows users to easily edit PDF's. Add text, images and signatures. Fill out PDF forms. Merge or split PDF documents. Reorder and delete pages. Even correct text and edit graphics! Features... Read more
Monolingual 1.5.9 - Remove unwanted OS X...
Monolingual is a program for removing unnecesary language resources from OS X, in order to reclaim several hundred megabytes of disk space. It requires a 64-bit capable Intel-based Mac and at least... Read more
Maya 2015 - Professional 3D modeling and...
Maya is an award-winning software and powerful, integrated 3D modeling, animation, visual effects, and rendering solution. Because Maya is based on an open architecture, all your work can be scripted... Read more
Starcraft II: Wings of Liberty 1.1.1.180...
Download the patch by launching the Starcraft II game and downloading it through the Battle.net connection within the app. Starcraft II: Wings of Liberty is a strategy game played in real-time. You... Read more
Sibelius 7.5.0 - Music notation solution...
Sibelius is the world's best-selling music notation software for Mac. It is as intuitive to use as a pen, yet so powerful that it does most things in less than the blink of an eye. The demo includes... Read more
Typinator 5.9 - Speedy and reliable text...
Typinator turbo-charges your typing productivity. Type a little. Typinator does the rest. We've all faced projects that require repetitive typing tasks. With Typinator, you can store commonly used... Read more

Latest Forum Discussions

See All

Have a Special Dead Trigger 2 Easter Bas...
Have a Special Dead Trigger 2 Easter Basket Full of Goodies, Courtesy of Madfinger Games Posted by Rob Rich on April 18th, 2014 [ permalink ] Dead Trigger 2 | Read more »
Almost All of Playdek’s Library is on Sa...
Almost All of Playdek’s Library is on Sale Right Now, and You Should Check it Out Posted by Rob Rich on April 18th, 2014 [ permalink ] Playdek has released quite a few great iOS ports of board and card games over the years, and now most of them... | Read more »
Zynga Launches Brand New Farmville Exper...
Zynga Launches Brand New Farmville Experience with Farmville 2: Country Escape Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »
David. Review
David. Review By Cata Modorcea on April 18th, 2014 Our Rating: :: MINIMALISTIC IN A DIFFERENT WAYUniversal App - Designed for iPhone and iPad David is a minimalistic game wrapped inside of a soothing atmosphere in which the hero... | Read more »
Eyefi Unveils New Eyefi Cloud Service Th...
Eyefi Unveils New Eyefi Cloud Service That Allows Users to Share Media Across Personal Devices Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »
Tales from the Dragon Mountain: The Lair...
Tales from the Dragon Mountain: The Lair Review By Jennifer Allen on April 18th, 2014 Our Rating: :: STEADY ADVENTURINGiPad Only App - Designed for the iPad Treading a safe path, Tales from the Dragon Mountain: The Lair is a... | Read more »
Yahoo Updates Flickr App with Advanced E...
Yahoo Updates Flickr App with Advanced Editing Features and More Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »
My Incredible Body - A Kid's App to...
My Incredible Body - A Kid's App to Learn about the Human Body 1.1.00 Device: iOS Universal Category: Education Price: $2.99, Version: 1.1.00 (iTunes) Description: Wouldn’t it be cool to look inside yourself and see what was going on... | Read more »
Trials Frontier Review
Trials Frontier Review By Carter Dotson on April 18th, 2014 Our Rating: :: A ROUGH LANDINGUniversal App - Designed for iPhone and iPad Trials Frontier finally brings the famed stunt racing franchise to mobile, but how much does its... | Read more »
Evernote Business Notebook by Moleskin I...
Evernote Business Notebook by Moleskin Introduced – Support Available in Evernote for iOS Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »

Price Scanner via MacPrices.net

Free HopTo 2.2 Helps Enhance Your Productivit...
The HopTo app helps you do more on your iPad by providing more and easier adaccess to files and documents. Version 2.2 adds Egnyte and HopTo’s Mac OSX File Connector. If you already have the hopTo... Read more
National Distracted Driving Awareness Month:...
As the country recognizes National Distracted Driving Awareness Month, Sprint is reminding wireless consumers to focus on driving while behind the wheel, to not text or email while driving, and to... Read more
13-inch 2.4GHz Retina MacBook Pro available f...
Abt has the 13″ 2.4GHz 128GB Retina MacBook Pro available for $1229 including free shipping. Their price is $70 off MSRP. Read more
iMacs on sale for up to $160 off MSRP this we...
Best Buy has iMacs on sale for up to $160 off MSRP for a limited time. Choose free home shipping or free instant local store pickup (if available). Prices are valid for online orders only, in-store... Read more
iPad Airs on sale this weekend for up to $100...
Best Buy has WiFi iPad Airs on sale for $50 off MSRP and WiFi + Cellular iPad Airs on sale for $100 off MSRP on their online store for a limited time, with prices now starting at $449. Choose free... Read more
Apple restocks refurbished Mac minis starting...
The Apple Store has restocked Apple Certified Refurbished Mac minis for up to $150 off the cost of new models. Apple’s one-year warranty is included with each mini, and shipping is free: - 2.5GHz Mac... Read more
Hyundai Brings Apple CarPlay To The 2015 Sona...
Hyundai Motor America has announced it will bring Apple CarPlay functionality to the 2015 Sonata. CarPlay is pitched as a smarter, safer and easier way to use iPhone in the car and gives iPhone users... Read more
Updated iPads Coming Sooner Than We Had Thoug...
MacRumors, cites KGI securities analyst Ming Chi Kuo, well-respected as an Apple product prognisticator, saying that Apple will introduce an upgraded iPad Air and iPad mini in 2014/Q3, meaning the... Read more
Toshiba Unveils New High And Low End Laptop M...
Toshiba has announced new laptop models covering both the high-end and low-end of the notebook computer spectrum. Toshiba 4K Ultra HD Laptop Toshiba’s new Satellite P55t features one of the world’s... Read more
Save up to $270 with Apple refurbished 13-inc...
The Apple Store has Apple Certified Refurbished October 2013 13″ Retina MacBook Pros available starting at $1099, with models up to $270 off MSRP. Apple’s one-year warranty is standard, and shipping... Read more

Jobs Board

*Apple* Automotive Parts Department position...
Apple Automotive is one of the fastest growing dealer…and it shows. Consider making the switch to the Apple Automotive Group today! At Apple Automotive, we Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
*Apple* Retail - Manager - Holyoke - Apple I...
Job Summary Keeping an Apple Store thriving requires a diverse set of leadership skills, and as a Manager, you’re a master of them all. In the store’s fast-paced, Read more
*Apple* Retail - Manager - Apple (United Sta...
Job SummaryKeeping an Apple Store thriving requires a diverse set of leadership skills, and as a Manager, you're a master of them all. In the store's fast-paced, dynamic Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.