Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can anyone explain the design decisions behind Autolisp/visual lisp to me?

I wonder can anyone explain the design rationale behind the following features of autolisp / visual lisp? To me they seem to fly in the face of accepted software practice ... am I missing something?

  • All variables are global by default (ie unless placed after a / in the function arguments)
  • Reading/writing data from autocad requires putting stuff into an association list with lots of magic numbers. 10 means x/y coordinates, 90 means length of the coordinate list, 63 means colour, etc. Ok you could store these in some constants but that would mean yet more globals, and the documentation encourages you to use the magic numbers directly.
  • Lisp is a functional-style language, which encourages programming by recursion over iteration, but tail recursion is afaik not optimised in visual lisp leading to horrendous call stacks - unless, of course you iterate. But loop syntax is very restrictive; e.g. you can't break out of or return a value from a loop unless you put some kind of flag in the termination condition. Result, ugly code.
  • Generally you are forced to declare variables all over the place which flies in the face of functional programming - so why use a functional(-ish) language?
like image 296
Sideshow Bob Avatar asked Feb 02 '12 13:02

Sideshow Bob


People also ask

What is the difference between AutoLISP and Visual LISP?

AutoLISP in AutoCAD offers functions for interactive data entry, processing and access to the AutoCAD drawing database ( DWG ). VisualLISP (originally "Vital LISP ") was added to AutoCAD in the versions R14 (as an add-on) and 2000 (integrated).

Is AutoLISP the same as LISP?

There is only one Lisp system in AutoCAD, so AutoLISP is just a subset of its functionality, not a separate implementation these days. Common Lisp (usually abbreviated as CL) is the name of the current mainstream Lisp programming language, not related to AutoCAD in any way.

Does AutoCAD still use LISP?

It was incorporated into AutoCAD 2000 released in March 1999, as a replacement for AutoLISP. Since then, Autodesk has ceased major enhancements to Visual LISP and focused more effort on VBA and . NET, and C++.


1 Answers

Lisp isn't a language, it's a group of sometimes surprisingly different languages. Scheme and Clojure are the functional members of the family. Common Lisp, and the more specialized breeds like Elisp aren't particularly functional and don't inherently encourage functional programming or recursion. CL in fact includes a very flexible object system, an extremely flexible iteration DSL, and doesn't guarantee optimized tail calls (Scheme dialects do, but not Lisps in general; that's the pitfall in thinking of "Lisp" as a single language).

Now that we have that cleared up, AutoLisp is an implementation from 1986 based on an early version of XLISP (the earliest of which was published in 1983).

The reason that it might fly in the face of currently accepted programming practice is that it predates currently accepted programming practice. Another thing to keep in mind is that the cheapest netbook available today is several hundred times more powerful than what a programmer could expect to have access to back in the mid 80s. Meaning that even if a given feature was accepted to be excellent, CPU or memory constraints may have prevented its implementation in a commercial language.

I've never programmed in Autolisp/Visual Lisp specifically, and the stuff you cite sounds bloody annoying, but it may have had some performance/memory advantage that justified it at the time.

like image 109
Inaimathi Avatar answered Oct 13 '22 06:10

Inaimathi