6

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?
Marcin
  • 48,559
  • 18
  • 128
  • 201
Sideshow Bob
  • 4,566
  • 5
  • 42
  • 79

3 Answers3

6

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.

Inaimathi
  • 13,853
  • 9
  • 49
  • 93
  • "it may have had some" ... nah, "they" just "took" it as it was, without permission from the author allegedly, and never bothered to improve it for fear of backward incompatibility. – Will Ness Feb 04 '12 at 23:50
  • @Will - Man. I guess that explains it then; the original XLISP was a toy project for the writer, not something he was seriously promoting. – Inaimathi Feb 05 '12 at 01:31
  • The dates 1983 to 1986 do not predate excellent practice in Lisp, sorry. By 1986, Common Lisp was already there and nearly the same thing that was standardized in 1994. It's not a case of predating, but a case of not having a clue. AutoLisp was worse than some Lisps in the 1960's. – Kaz Mar 08 '12 at 20:04
  • 2
    Actually what I think happened was that Audotesk took some early, immature Xlisp sources (presumably, liberally licensed). Xlisp went on to improve, but AutoLisp didn't pick up the improvements. I seem to recall there are some FAQ's about AutoLisp out there which talk about this. – Kaz Mar 08 '12 at 20:07
3

If I remember correctly, AutoLisp is a fork from an early version of XLisp (some sources claim it was XLisp 1.0 (see this C2 article).

XLisp 1.0 is a 1-cell lisp (functions and variables share the same name-space) with some rather odd oddities to it.

Vatine
  • 20,782
  • 4
  • 54
  • 70
2

You can add dynamic scoping into the mix btw, and if you don't know what it is consider yourself lucky. But actually not all your four points are that big of a deal IMO:

  • "Undeclared vars are created automatically as global." Same as in CL is it not (via setq)? The other option is to fail, and that's not a very attractive one for the language which is supposed to be used for quick-n-dirty scripting.

  • "magic numbers" are DXF-codes, which you're right are major inconvenience as they tend to change with the changing ACAD versions sometimes (thankfully, rarely). That's just how it is. Fixing it would require a major overhaul, introducing some "schemas" and what not, and why would "they" bother? AutoLISP was left in its state as of 1992 approximately, and never bothered with since. Visual LISP itself is entirely different and much more capable system, but it is all locked out for the regular user, and only made to serve one goal - to emulate the old AutoLISP as faithfully as possible (except where it added new VBA-related features in the later half of the 1990s, and was locked since then too).

  • (while (not done) ...) is not that ugly. There's no tail optimization guarantee, yes, just as there isn't one in CL and Haskell (that last one really stumbles me - there's no guaranteed way to encode a loop in Haskell in constant space without monads - how about that?).

  • "you're forced to declare vars all over the place" here I do not follow you. You declare them were you supposed to declare them - in the function's internal arguments list. What other places do you mean? I don't know of any.

In reality the biggest stumbling block of AutoLISP is its dynamic name resolution IMO, but that's how it was in Xlisp, only few years after Scheme first came out. Then also it's its immutable data store, but that was done mainly for simplicity of implementation, and to prevent too much confusion and hence questions, from the user base, I guess.

Will Ness
  • 70,110
  • 9
  • 98
  • 181
  • 2
    Actually, Haskell does support tail calls (as long as you use strict function application to set the accumulator). I was confused about this point myself and [this answer](http://stackoverflow.com/a/4286283/190887) cleared it up. – Inaimathi Feb 05 '12 at 01:35