Hmm, I can see that this program must be doing a lot of extra work. As I understand, LAS-CASAS contains a bunch of indices into parts of TAB. You collect what a bunch of things from TAB have in common, until there's some sort of stop code in LAS-CASAS.
One small thing you can do is see that your lisp will already have a handy INTERSECTION function for you:
- Code: Select all
CL-USER> (intersection '(1 2 2 3) '(1 4 2 3))
(3 2 2 1)
CL-USER> (remove-duplicates (intersection '(1 2 2 3) '(1 4 2 3)))
(3 2 1)
Also, you're constantly stepping through TAB to pick out some item -- if there's 500 items, getting the last item will take 500 steps. Now, if those parts of TAB were instead vectors (not lists), it'll take merely 1 step to pick out any item you want.
Further, all those APPENDs are probably taking lots of time. I don't know your application, but surely there must be some way to cut down on those:
- Code: Select all
;; This steps completely through the first list (of 6 items), which is slower than you might expect.
CL-USER> (append (list 1 2 3 4 5 6)
(list 7))
(1 2 3 4 5 6 7)
A more readable style is to use things which describe what you're doing -- and not only do you gain clarity, but you may also gain speed. For instance, SECOND and THIRD don't really tell people your intention -- the meaning of what you're doing. There may be alternatives which are not only clearer to the reader, but also can be optimized behind-the-scenes to be faster.