{"id":1712,"date":"2022-11-24T10:16:50","date_gmt":"2022-11-24T10:16:50","guid":{"rendered":"https:\/\/blog.amt.in\/?p=1712"},"modified":"2022-11-24T10:16:50","modified_gmt":"2022-11-24T10:16:50","slug":"insights-to-common-lisp","status":"publish","type":"post","link":"https:\/\/blog.amt.in\/index.php\/2022\/11\/24\/insights-to-common-lisp\/","title":{"rendered":"Insights to Common Lisp"},"content":{"rendered":"<p>Common Lisp\u00c2\u00a0(CL) is a dialect of the\u00c2\u00a0Lisp programming language, published in\u00c2\u00a0ANSI\u00c2\u00a0standard document\u00c2\u00a0ANSI INCITS 226-1994 (R2004)\u00c2\u00a0(formerly\u00c2\u00a0X3.226-1994 (R1999)).\u00c2\u00a0The\u00c2\u00a0Common Lisp HyperSpec, a hyperlinked HTML version, has been derived from the ANSI Common Lisp standard.<\/p>\n<p>The Common Lisp language was developed as a standardized and improved successor of\u00c2\u00a0Maclisp. By the early 1980s several groups were already at work on diverse successors to MacLisp:\u00c2\u00a0Lisp Machine Lisp\u00c2\u00a0(aka ZetaLisp),\u00c2\u00a0Spice Lisp,\u00c2\u00a0NIL\u00c2\u00a0and\u00c2\u00a0S-1 Lisp. Common Lisp sought to unify, standardise, and extend the features of these MacLisp dialects. Common Lisp is not an implementation, but rather a language\u00c2\u00a0specification.\u00c2\u00a0Several\u00c2\u00a0implementations\u00c2\u00a0of the Common Lisp standard are available, including\u00c2\u00a0free and open-source software\u00c2\u00a0and proprietary products.\u00c2\u00a0Common Lisp is a general-purpose,\u00c2\u00a0multi-paradigm programming language. It supports a combination of\u00c2\u00a0procedural,\u00c2\u00a0functional, and\u00c2\u00a0object-oriented programming\u00c2\u00a0paradigms. As a\u00c2\u00a0dynamic programming language, it facilitates evolutionary and\u00c2\u00a0incremental software development, with iterative\u00c2\u00a0compilation\u00c2\u00a0into efficient run-time programs. This incremental development is often done interactively without interrupting the running application.<\/p>\n<p>It also supports optional type annotation and casting, which can be added as necessary at the later\u00c2\u00a0profiling\u00c2\u00a0and optimization stages, to permit the compiler to generate more efficient code. For instance,\u00c2\u00a0<code>fixnum<\/code>\u00c2\u00a0can hold an\u00c2\u00a0unboxed\u00c2\u00a0integer in a range supported by the hardware and implementation, permitting more efficient arithmetic than on big integers or arbitrary precision types. Similarly, the compiler can be told on a per-module or per-function basis which type safety level is wanted, using\u00c2\u00a0optimize\u00c2\u00a0declarations.<\/p>\n<p>Common Lisp includes\u00c2\u00a0CLOS, an\u00c2\u00a0object system\u00c2\u00a0that supports\u00c2\u00a0multimethods\u00c2\u00a0and method combinations. It is often implemented with a\u00c2\u00a0Metaobject\u00c2\u00a0Protocol.<\/p>\n<p>Common Lisp is extensible through standard features such as\u00c2\u00a0<i>Lisp\u00c2\u00a0macros<\/i>\u00c2\u00a0(code transformations) and\u00c2\u00a0<i>reader macros<\/i>\u00c2\u00a0(input parsers for characters).<\/p>\n<p>Common Lisp provides some backwards compatibility to\u00c2\u00a0Maclisp\u00c2\u00a0and to John McCarthy&#8217;s original\u00c2\u00a0Lisp. This allows older Lisp software to be ported to Common Lisp.<\/p>\n<p>Work on Common Lisp started in 1981 after an initiative by ARPA manager Bob Engelmore to develop a single community standard Lisp dialect.\u00c2\u00a0Much of the initial language design was done via electronic mail.\u00c2\u00a0In 1982,\u00c2\u00a0Guy L. Steele, Jr.\u00c2\u00a0gave the first overview of Common Lisp at the 1982 ACM Symposium on LISP and functional programming.<\/p>\n<p>The first language documentation was published 1984 as\u00c2\u00a0Common Lisp the Language\u00c2\u00a0(known as CLtL1), first edition. A second edition (known as CLtL2), published in 1990, incorporated many changes to the language, made during the ANSI Common Lisp standardization process: extended LOOP syntax, the Common Lisp Object System, the Condition System for error handling, an interface to the pretty printer and much more. But CLtL2 does not describe the final ANSI Common Lisp standard and thus is not a documentation of ANSI Common Lisp. The final ANSI Common Lisp standard then was published in 1994. Since then no update to the standard has been published. Various extensions and improvements to Common Lisp (examples are Unicode, Concurrency, CLOS-based IO) have been provided by implementations and libraries (many available via\u00c2\u00a0Quicklisp).<\/p>\n<h3><span id=\"Scalar_types\" class=\"mw-headline\">Scalar types:<\/span><\/h3>\n<p>Number\u00c2\u00a0types include\u00c2\u00a0integers,\u00c2\u00a0ratios,\u00c2\u00a0floating-point numbers, and\u00c2\u00a0complex numbers.\u00c2\u00a0Common Lisp uses\u00c2\u00a0bignums\u00c2\u00a0to represent numerical values of arbitrary size and precision. The ratio type represents fractions exactly, a facility not available in many languages. Common Lisp automatically coerces numeric values among these types as appropriate.<\/p>\n<p>The Common Lisp\u00c2\u00a0character\u00c2\u00a0type is not limited to\u00c2\u00a0ASCII\u00c2\u00a0characters. Most modern implementations allow\u00c2\u00a0Unicode\u00c2\u00a0characters.<\/p>\n<p>The\u00c2\u00a0symbol\u00c2\u00a0type is common to Lisp languages, but largely unknown outside them. A symbol is a unique, named data object with several parts: name, value, function, property list and package. Of these,\u00c2\u00a0value cell\u00c2\u00a0and\u00c2\u00a0function cell\u00c2\u00a0are the most important. Symbols in Lisp are often used similarly to identifiers in other languages: to hold the value of a variable; however there are many other uses. Normally, when a symbol is evaluated, its value is returned. Some symbols evaluate to themselves, for example all symbols in the keyword package are self-evaluating. Boolean values in Common Lisp are represented by the self-evaluating symbols T and NIL. Common Lisp has namespaces for symbols, called &#8216;packages&#8217;.<\/p>\n<p>A number of functions are available for\u00c2\u00a0rounding\u00c2\u00a0scalar numeric values in various ways. The function\u00c2\u00a0<code>round<\/code>\u00c2\u00a0rounds the argument to the nearest integer, with halfway cases rounded to the even integer. The functions\u00c2\u00a0<code>truncate<\/code>,\u00c2\u00a0<code>floor<\/code>, and\u00c2\u00a0<code>ceiling<\/code>\u00c2\u00a0round towards zero, down, or up respectively. All these functions return the discarded fractional part as a secondary value. For example,\u00c2\u00a0<code>(floor -2.5)<\/code>\u00c2\u00a0yields \u00e2\u02c6\u20193, 0.5;\u00c2\u00a0<code>(ceiling -2.5)<\/code>\u00c2\u00a0yields \u00e2\u02c6\u20192, \u00e2\u02c6\u20190.5;\u00c2\u00a0<code>(round 2.5)<\/code>\u00c2\u00a0yields 2, 0.5; and\u00c2\u00a0<code>(round 3.5)<\/code>\u00c2\u00a0yields 4, \u00e2\u02c6\u20190.5.<\/p>\n<h3><span id=\"Data_structures\" class=\"mw-headline\">Data structures:<\/span><\/h3>\n<p><i>Sequence<\/i>\u00c2\u00a0types in Common Lisp include lists, vectors, bit-vectors, and strings. There are many operations that can work on any sequence type.<\/p>\n<p>As in almost all other Lisp dialects,\u00c2\u00a0<i>lists<\/i>\u00c2\u00a0in Common Lisp are composed of\u00c2\u00a0<i>conses<\/i>, sometimes called\u00c2\u00a0<i>cons cells<\/i>\u00c2\u00a0or\u00c2\u00a0<i>pairs<\/i>. A cons is a data structure with two slots, called its\u00c2\u00a0<i>car<\/i>\u00c2\u00a0and\u00c2\u00a0<i>cdr<\/i>. A list is a linked chain of conses or the empty list. Each cons&#8217;s car refers to a member of the list (possibly another list). Each cons&#8217;s cdr refers to the next cons\u00e2\u20ac\u201dexcept for the last cons in a list, whose cdr refers to the\u00c2\u00a0<code>nil<\/code>\u00c2\u00a0value. Conses can also easily be used to implement trees and other complex data structures; though it is usually advised to use structure or class instances instead. It is also possible to create circular data structures with conses.<\/p>\n<p>Common Lisp supports multidimensional\u00c2\u00a0<i>arrays<\/i>, and can dynamically resize\u00c2\u00a0<i>adjustable<\/i>\u00c2\u00a0arrays if required. Multidimensional arrays can be used for matrix mathematics. A\u00c2\u00a0<i>vector<\/i>\u00c2\u00a0is a one-dimensional array. Arrays can carry any type as members (even mixed types in the same array) or can be specialized to contain a specific type of members, as in a vector of bits. Usually only a few types are supported. Many implementations can optimize array functions when the array used is type-specialized. Two type-specialized array types are standard: a\u00c2\u00a0<i>string<\/i>\u00c2\u00a0is a vector of characters, while a\u00c2\u00a0<i>bit-vector<\/i>\u00c2\u00a0is a vector of\u00c2\u00a0bits.<\/p>\n<p><i>Hash tables<\/i>\u00c2\u00a0store associations between data objects. Any object may be used as key or value. Hash tables are automatically resized as needed.<\/p>\n<p><i>Packages<\/i>\u00c2\u00a0are collections of symbols, used chiefly to separate the parts of a program into\u00c2\u00a0namespaces. A package may\u00c2\u00a0<i>export<\/i>\u00c2\u00a0some symbols, marking them as part of a public interface. Packages can use other packages.<\/p>\n<p><i>Structures<\/i>, similar in use to\u00c2\u00a0C\u00c2\u00a0structs and\u00c2\u00a0Pascal\u00c2\u00a0records, represent arbitrary complex data structures with any number and type of fields (called\u00c2\u00a0<i>slots<\/i>). Structures allow single-inheritance.<\/p>\n<p><i>Classes<\/i>\u00c2\u00a0are similar to structures, but offer more dynamic features and multiple-inheritance. (See\u00c2\u00a0CLOS). Classes have been added late to Common Lisp and there is some conceptual overlap with structures. Objects created of classes are called\u00c2\u00a0<i>Instances<\/i>. A special case are Generic Functions. Generic Functions are both functions and instances.<\/p>\n<p>The above is a brief about\u00c2\u00a0Common Lisp. Watch this space for more updates on the latest trends in Technology.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Common Lisp\u00c2\u00a0(CL) is a dialect<\/p>\n","protected":false},"author":1,"featured_media":1714,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[624,154,7],"tags":[625,156,18],"class_list":["post-1712","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-common-lisp","category-programming-language","category-techtrends","tag-common-lisp","tag-programming-language","tag-technology"],"_links":{"self":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts\/1712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/comments?post=1712"}],"version-history":[{"count":1,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts\/1712\/revisions"}],"predecessor-version":[{"id":1713,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts\/1712\/revisions\/1713"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/media\/1714"}],"wp:attachment":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/media?parent=1712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/categories?post=1712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/tags?post=1712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}