6 ms·
"Expressive power" and "computational power" aren't the same thing. Turing's original Universal Machine (you know, the moving read/write head over an indefinit
by kazinator 11y ago
"Expressive power" and "computational power" aren't the same thing.
Turing's original Universal Machine (you know, the moving read/write head over an indefinitely long tape of symbols) is not expressive at all; a simple task like adding two integers on that machine requires a completely arcane, verbose piece of gobbledygook to be prepared on the tape, where you cannot tell at a glance which part of it is the program, and which is the integers to be added. It is less expressive than 4 + 4 in a calculator language that doesn't have loops.
Expressive power is, in its barest essence, the freedom to assign an arbitrary meaning, from some domain, to a new combination of symbols, such that every symbol in that combination refers to some entity in that domain only.
It behooves us to have a general-purpose language with as much expressive power as we can get our hands on.
It is not hard at all to add restrictions in domain languages created inside an expressive language. For instance if you make an x86-64 assembler in Lisp, it will be just as restricted as any other assembler; it will diagnose unrecognized opcodes, bad addressing modes, etc.
- lmm 11y ago> For instance if you make an x86-64 assembler in Lisp, it will be just as restricted as any other assembler; it will diagnose unrecognized opcodes, bad addressing modes, etc. But it won't enforce those things at compilation time in the type system, because it doesn't have one. You might have a macro that checks them, but it would be ad-hoc.
- kazinator 11y agoIf I make an assembler in Lisp, compile it and ship it to you so that you can apply it to your assembly language programs, it wouldn't work so well for me to be diagnosing your assembly language problems in my compile time.
- lmm 11y agoI'd prefer a language where I don't have to write a domain language from scratch and write a program that can enforce its rules at runtime. Rather I'd like to be able to express my domain code in the language itself, so that my users don't have to learn (and I don't have to create) a new language. That requires a consistent way of restricting things at compile time, which is very hard to retrofit - if I ever want to be able to enforce that programs don't do certain things, the language needs to not offer unrestricted access to those things.
- kazinator 11y agoIf you express your domain code in the language yourself, users still have to learn and understand what you have done. What you write in a language has its own de facto language, whether you capture its conventions in a notation or not. Simply knowing the elements of the language in which that work is done isn't enough. Otherwise you could just memorize a language reference manual and call yourself a software engineer. Or could just argue that since the program in any modern language is written in UTF-8, and the users know that already, they have nothing to learn.
- lmm 11y agoThere are still things to learn, and you may still need to adapt tools, but it's a lot easier to work with an "embedded" DSL than an "external" one. You still need to define the nouns and verbs of your domain, but you don't have to define a whole new grammar.
- davexunit 11y agoLisp isn't any one thing, it's a language family. One could create a Lisp that is statically typed.
- lmm 11y ago> Lisp isn't any one thing, it's a language family. Which is rather the problem. Types, in particular, are only useful if everyone has them - optional add-on typing has been tried for many languages, but I've never known it be successful.
- davexunit 11y agoMy point was that making generalizations about Lisp is like making generalizations about languages with C-like (perhaps more correct ALGOL-like) syntax. Most people wouldn't make a statement about Java and assert that it applied to C++, too. This is why saying that Lisp has no type system doesn't make much sense. There are many completely different languages that use s-expression notation, and they all have different feature sets, much like all the C-like languages.
- raattgift 11y agoTyped Racket <https://docs.racket-lang.org/ts-guide/> https://docs.racket-lang.org/ts-guide/> is pretty successful in the Racket community. It's also prompted some pessimistic papers about gradual sound typing, since it's hard to avoid a performance hit when imposing type safety on untyped code using contracts. On the other hand, that performance hit is in part typechecker/compiler implementation dependent and in part dependent on the granularity of the added typing (e.g. typing modules or functions vs typing subexpressions). Typed Racket code often gains a speedup over untyped Racket, since sound typing allows the elision of contracts and other runtime overheads for safety. There is no penalty at all for invoking Typed Racket code from untyped code, either in terms of performance or in terms of what the untyped-language programmer needs to know.
- samth 11y agoNote that we've made big improvements in the performance of Typed Racket's generated contracts just since that paper was written, so many things are now better.
- kruhft 11y agoCommon Lisp has an optional type system and many compilers have excellent type inference engines for optimization.
- kazinator 11y agoCommon Lisp's type system isn't optional. The language is strongly typed. Type goes away (in a sense) when you add declarations. That is to say, if you tell Lisp that, say, some variable contains a fixnum, then (in code compiled with safety 0) it just believes your declaration, and it's up to you to ensure that it's not a lie (else the behavior is undefined). The type system isn't optional in any other sense. It's optional for an implementation to provide static checks and optimizations based on type, which is different. "Static type" and "type" are not synonyms. Common Lisp code is safe by default; you can't use an object of type X as if it were one of type Y.
- kruhft 11y agoThanks for the explanation. Never really thought of it that way.
- lmm 11y agoA spec that says adding a fixnum to a string produces a possibly-runtime error isn't a type system, it's just a particular instance behaviour. Types are by definition associated to terms in a language. (That isn't to say that that kind of runtime behaviour isn't valuable or doesn't provide (some of) the same functionality as a type system. But it's not what the word "type" means).
- kazinator 11y ago> Types are by definition associated to terms in a language. This is true, within a particular paradigm, which isn't the be-all and end-all of what "type" means in computer science. All kinds of things are type. For instance, "JPEG file" or "alphanumeric character" are both type terms. You don't get to dictate to everyone one narrow definition of a term that has an obviously broad applicability in numerous contexts. If we are discussing Common Lisp, and you want to get properly pedantic about what "type" means, the way you can do that is to look up its definition in the ANSI CL glossary, which says: "type n. 1. a set of objects, usually with common structure, behavior, or purpose." Or you can use it in a broader way which is compatible with this concept. If you insist that it means something else which is not compatible with the glossary definition, and you still want to talk about Lisp, then I'm afraid it's not productive; you are more interested in engaging in a conflict about word semantics: which "camp" gets to "own" the ideologically precious word, such as "type". Usually how we can resolve that conflict is to split our vocabulary into different words. You can have "type", I don't need it; I will call it this other thing that the CL glossary refers to "genus". Now type can be the property of a syntactic term in a program, and genus refers to sets of objects which have something in common. I'm mostly interested in genus systems, and type systems in their context (agreement between the type of a program term, and the genus of the run-time thing it operates on).
- sklogic 11y agoEver seen ACL2 used for assembler verification?
- mbrock 11y agoAnother commenter already said that Common Lisp indeed does have a type system. It's possible to circumvent, but that's Lisp for you. You can very easily write an assembler in Haskell that doesn't verify any of that stuff statically. Learning to do advanced kinds of static verification with Haskell's type system is actually rather difficult, and usually requires language extensions. Using a macro that checks those things seems like it could be a very pragmatic way to provide safety. It might also let you verify properties that would be hard to figure out how to verify using only Haskell-style type checking. Indeed, Haskell programmers often use QuickCheck to do ad-hoc verification of type class laws, for example, since they can't be proven in the type system.
- lmm 11y ago> Learning to do advanced kinds of static verification with Haskell's type system is actually rather difficult Perhaps. But it benefits greatly from being a consistent way of doing things: everyone does their static verification the same way, because the language supports exactly one way of doing it. > and usually requires language extensions. Sometimes. But again at least those extensions are relatively standardized, rather than completely ad-hoc as a macro can be. > Indeed, Haskell programmers often use QuickCheck to do ad-hoc verification of type class laws, for example, since they can't be proven in the type system. Yeah, that's one of the reasons I'm excited about Idris. But even in your example, QuickCheck is again a standardized way of doing this.
- mbrock 11y agoWell, all you need to do in a macro to provide error checking is to assert or raise a condition when something is wrong. That's pretty standard. In Haskell land, you can do wonderful things like Servant, the statically verified API server—but that kind of code is very advanced, and written by a shadowy cabal of type level wizards. I think there is less of a standardized way of doing this stuff than one might expect. I'm not really sure what you mean by "standardized." Common Lisp is an actual ANSI standard... But you seem to be referring to the existence of common practices. I'm not convinced that the problem you describe is actually a problem, and I'm not convinced that Haskell or Idris will end up being more successful in the mainstream than Lisp. (I'm a huge fan of Haskell, Agda, and static/dependent typing, for the record.)
- xenophonf 11y agoBut [Lisp] won't enforce those things at compilation time in the type system, because it doesn't have one. What Lisp implementation do you have in mind? I ask because Common Lisp has type system that includes compile-time type checking. For example, SBCL: http://sbcl.org/manual/index.html#Handling-of-Types http://sbcl.org/manual/index.html#Handling-of-Types
- kazinator 11y agoMy guess: some instructor's "one weekend lisp" that he or she had to study for a fraction of a semester.
- agentultra 11y ago> For instance if you make an x86-64 assembler in Lisp, it will be just as restricted as any other assembler; it will diagnose unrecognized opcodes, bad addressing modes, etc. I've written one such assembler in Common Lisp. It was rather straight-forward and generated nice code. Debugger came practically free. Lisp is a language for symbolic computing. Values are not so valuable as computations and trees. If the level you're working at is too restrictive you're free to invent a new algebra for symbols at a higher level in terms of the lower-level primitive symbols. It's the same power one gets from manually calculating sums to inventing a language for expressing all sums. How you choose to represent things has great power in your ability to reason about them.
- PuercoPop 11y ago> For instance if you make an x86-64 assembler in Lisp, it will be just as restricted as any other assembler; Check out Henry Baker's Comfy 65 Compiler[1] to see how far a little lisp changes an assembler language. [1]: http://home.pipeline.com/~hbaker1/sigplannotices/sigcol04.pdf http://home.pipeline.com/~hbaker1/sigplannotices/sigcol04.pd...