3 ms·
Please forgive some ignorance here, but I thought that LISP couldn't have a proper type system since it would muck with homoiconicity. Clearly I'm wrong about
by tombert 9y ago
Please forgive some ignorance here, but I thought that LISP couldn't have a proper type system since it would muck with homoiconicity. Clearly I'm wrong about this, but now I'm curious why more LISPs aren't typed.
Can anyone here enlighten me?
- deleted 9y ago[deleted]
- taeric 9y agoMy money would be on cost of implementation. Specifically, implementing a full type system takes a large effort. Now, it should come as no surprise that many Common Lisp implementations do give what is equivalent to compile time warnings when things are done incorrectly. What throws most people off, I think, is that compile/runtime are easy to mix in a lisp language. Such that you can go between the phases more naturally than you can in other languages.
- ZenoArrow 9y agoThere are statically typed variants of Lisp. Shen springs to mind. The homepage for Shen has more details about the type system it uses, but just to warn you the site jumps in at the deep end: http://shenlanguage.org/ http://shenlanguage.org/ Perhaps there's a gentler introduction elsewhere.
- madmax96 9y agoWhat do you mean by a "proper type system"? In SBCL, if you set the optimization (SAFETY 3) then the system can catch many type errors in advance. Finally, homoiconicity simply means that the text of a program generally resembles the AST of the language. Adding type annotations (which you can do in CL, clojure, and typed racket) is therefore not incompatible with the principle of homoiconicity.
- tombert 9y agoI think that I got confused based on some post talking about difficulties of implementing a Hindley Milner type system in Lisp. So much for relying on three-year-old memories.
- kazinator 9y agoHomoiconicity is a weak concept; it refers to programs being stored in the original textual representation. A very good example of this that is in widespread use today is the POSIX shell, which is homoiconic because you can run "set" to see function definitions that can be copy and pasted. This is not valued in the Lisp world at all; Lisp implementations throw away the text and compile the code into another representation. Common Lisp has optional support for homoiconicity. There is a function called ed which can recall a function definition for editing. http://clhs.lisp.se/Body/f_ed.htm http://clhs.lisp.se/Body/f_ed.htm Representing source code as a data structure (and allowing user-defined code to intercept and transform it at compile time) isn't homoiconicity.
- icebraining 9y agoYour definition of homoiconicity is different than any I've ever seen, which is something like "the language's own code is a first-class data type" (see the discussion on the C2 wiki, for example: http://wiki.c2.com/?DefinitionOfHomoiconicDiscussion http://wiki.c2.com/?DefinitionOfHomoiconicDiscussion)
- kazinator 9y agohttps://en.wikipedia.org/wiki/Homoiconicity https://en.wikipedia.org/wiki/Homoiconicity uncovers where the term came from: the paper describing a text processing language called TRAC. Nothing about a fist-class data type other beyond the character string. It seems to have been contrived by sticking the greek prefix "homo" (same) onto "iconic", which is derived from "ikonos" (image). The code in the machine has the same (homo) image (ikonos) as what came from the keyboard. The Lisp example in that page is irrelevant. eval is not required, in fact, to walk the nested list data structure; some Lisps have an eval which compiles to native code, then calls the resulting function. Lisp data is somewhat homoiconic in that it has a representation which converts back to text. It's not exactly the original text, but there is an important concept at play called "read/print consistency". It is weaker than homoiconicity, which preserves the exact character spelling, more or less.