association-list

October 29, 2006

More maundering on about Lisp.

no tags — evan @ 2:14 pm

One of the thing that makes CL a pain in the ass some­times is that there are a lot of strangely named func­tions spe­cial­ized for dif­fer­ent types of objects. The lan­guage has a tril­lion key­words and a lot of them don’t really help the lan­guage learner get com­fort­able with the lan­guage. As an exam­ple, iteration:

In the lan­guage stan­dard there are a couple of dif­fer­ent iter­a­tion con­structs, do, dolist, docount, and loop. Strangely, there is no doarray. It’s easy enough to write one:


(defmacro do-svect ((counter array) &rest body)
  (let ((ctr (gensym)))
    (dotimes (,ctr (fill-pointer ,array)) 
       (let ((,counter (aref ,array ,ctr)))
     ,@body))))
</code>
</pre>
That's all well and good, but it's a pain to have to write a macro for
each and every sequence type of thing that you have to deal with, and
while I understand why it isn't there, I don't understand why there
isn't some generalforeach` type of function.  It would be easy enough
to write, just a macro that detects the type of the sequence type the
function was called on that writes out the appropriate thing.  There
are a number of situations where this would help a lot, to the
beginner.  Just layer them as macros over the normal syntax and
keywords, which, of course, would all still be there if you needed to
do something more complicated.

Syntax, I think, makes things easier to remem­ber, because (and I’m the­o­riz­ing here) it calls in some other part of the brain than the part that we use to remem­ber vocab­u­lary, which is what we’re being asked to do with Lisp. I’ve never in my life writ­ten a line of Smalltalk, but I can remem­ber that their lambda syntax is some­thing like [ x y | x * y ]. I know very little Erlang, but I know that their binary pat­tern match­ing syntax is << x/integer, y/float >> = val. I’ve been read­ing about lisp for years and star­ing at it for ten of the last six­teen hours and I’ll be damned if I can remem­ber how to pass mul­ti­ple values back from a function.

Per­haps Arc will fix all of this, but I think that it would be of no little value to the Lisp com­mu­nity, and to those who want to learn lisp, if people started work­ing on a pack­age that every­one agreed to include and use with their dis­tri­b­u­tions (hah!) that made some things a little easier. It could be some­thing like the modern pack­age that comes with ACL. Hell, every­one could make their own and then we could give them six months, then put them all in a ring and make them fight and then make some­thing more or less agree­able to every­one with the parts that are left over.

Lisp is famed for it’s abil­ity to quickly gen­er­ate Domain Spe­cific Lan­guages, so per­haps it’s time that we bent that abil­ity towards a dif­fer­ent kind of domain, that of learn­ing the lan­guage itself. It might also point to the kinds of things that would be inter­est­ing to put into the next ver­sion of the spec, in the far-​​off, misty future when that fabled doc­u­ment is actu­ally generated.

Leave a Reply