Why are most S-Expression languages dynamically typed?

后端 未结 3 768
梦如初夏
梦如初夏 2021-02-01 17:37

How come most Lisps and Schemes are dynamically typed? Does static typing not mix with some of their common features?

3条回答
  •  北恋
    北恋 (楼主)
    2021-02-01 18:09

    Static typing is lexical, it means that all information about types can be inferred from reading source code without evaluating any expressions or computing any things, conditionals being most important here. A statically typed language is designed so that this can happen, a better term would be 'lexically typed', as in, a compiler can prove from reading the source alone that no type errors will occur.

    In the case of lisp, this is awkwardly different because lisp's source code itself is not static, lisp is homo-iconic, it uses data as code and can to some extend dynamically edit its own running source.

    Lisp was the first dynamically typed language, and probably for this reason, program code itself is no longer lexical in Lisp.

    Edit: a far more powerful reason, in the case of static typing you'd have to type lists. You can either have extremely complex types for each lists which account for all elements, of demand that each element has the same type and type it as a list of that. The former option will produce hell with lists of lists. The latter option demands that source code only contains the same type for each datum, this means that you can't even build expressions as a list is anyhow a different type than an integer.

    So I dare say that it is completely and utterly infeasible to realize.

提交回复
热议问题