Common Lisp . Abbreviated to “CL”, it is a dialect of the Lisp programming language, published in ANSI X3.226-1994 standard. Developed to standardize divergent Lisp variants above, it is not an implementation, but rather a specification. Various implementations of the Common Lisp standard are available, including commercial products and open source software.
Summary
[ hide ]
- 1 Common Lisp language
- 2 History
- 3 Features
- 4 Types of Data
- 1 Other types
- 5 Interpreted Compilation
- 6 Functions
- 7 Sources
Common Lisp language
The Common Lisp language is a dialect of the Lisp programming language. Common Lisp is a language widely used in robotics and in engineering and artificial intelligence. This was done to standardize the divergent Lisp variants (although mainly the MacLisp variants ) that preceded it, it is not an implementation but a language specification. The Common Lisp has several implementations such as open source and free software and proprietary products. Common Lisp is a general-purpose multi-paradigm language . It supports a combination of programming paradigms such as procedural (imperative), functional, and object-oriented.
As a dynamic programming language, it facilitates software development in an evolutionary and incremental way, with iterative compilation into efficient runtime programs. Common Lisp includes CLOS , an object system that supports multi-methods and method combinations. It is extensible through standard features such as Lisp macros (compile-time code rearrangement accomplished by the program itself) and read macros (syntax extension to give special meaning to characters reserved for users with this purpose). The Common Lisp includes a set of tools ( toolkit) for object-oriented programming, the Common Lisp Object System or CLOS, which is one of the most powerful object systems available in any language.
Originally proposed as an add-on, CLOS was adopted as part of the Common Lisp ANSI standard. CLOS is a dynamic object system with multiple dispatch and multiple inheritance, and it differs radically from the object-oriented programming (OOP) facilities found in static languages such as C ++ or Java . As a dynamic object system, CLOS allows runtime changes to generic functions and classes. Methods can be added and removed, classes can be added and redefined, objects can be updated for class changes, and object class can be changed.
CLOS has been integrated into ANSI Common Lisp. Generic functions can be used like normal functions and are a first class data type. Each CLOS class is integrated into the Common Lisp type system. Many Common Lisp types have a corresponding class. There is more potential use of CLOS for the Common Lisp. The specification does not say if the conditions are implemented with the CLOS. The pathnames (names route ) and streams ( flows ) can be implemented with CLOS. These future possibilities of using CLOS for ANSI Common Lisp are not part of the standard. Actual Common Lisp implementations are using CLOS for pathnames , streams, entry / exit conditions, the implementation of the CLOS itself and more.
History
It all started in April of 1981 , following a meeting sponsored by DARPA of all communities Lisp: Symbolics, the SPICE project, NIL, the PROYECO S-1 ~ Lisp project. All communities came together and created Common Lisp. Initially led by Jonl White and Richard P. Gabriel (who also helped create CLOS), with great support from Scot Fahlman, Daniel Weinreb, David Moon, and Guy L. Steele. Common Lisp was designed as a description of a language family. The biggest influences on Common Lisp were Lisp Machine Lisp, MacLisp, NIL, S-1 ~ Lisp, Spice Lisp, and Scheme. Its semantics were poorly specified, by the way, in some places where an over-specification was thought to restrict the use and research of Common Lisp. In 1986 “ X3J13 was formed”, A technical working group to produce a draft of a Common Lisp ANSI standard. Due to the public acceptance of Common Lisp, the goals of this group differed from the goals of the original designers. These goals included stricter standardization to increase portability, an object-oriented system, a condition system, iteration facilities, and a way to handle large character sets.
characteristics
Common Lisp is a general-purpose programming language with the following
Features: Supports a combination of imperative, functional, and object-oriented programming. It is a dynamic language that facilitates rapid development, with iterative compilation to efficient programs at runtime. Includes CLOS, an object system that supports multi -methods and combination of methods. It is extensible by standard features like Lisp macros (compile-time code ordering is done by the program itself).
Type of data
Scalar Type : Numeric types include integers, ratios, floating point numbers, and complex numbers. Common Lisp uses ” bignums ” to represent arbitrary precision and size values. The ratio type represents fractions exactly, a feature that not many programming languages have.
The character type in Common Lisp is not limited to ASCII characters, which is not surprising since it was designed before ASCII code existed . Most modern implementations allow ” Unicode ” characters . The symbol type is common to all Lisp languages, but little known outside the scope of Lisp. A symbol is a unique and named data object, with several parts: name , value , function, property list, and package . Of these fields, “value” and “function” are the most important.
Symbols in Lisp are used similarly to identifiers in other languages: to save a value of a variable; although there are many other uses. Normally when a symbol is evaluated, its value is returned. Some symbols evaluate themselves, for example all symbols in keyword packages”They evaluate themselves. Boolean values in Common Lisp are represented by symbols that evaluate themselves: “T” and “NIL”. Data Structures: Sequential types in Common Lisp include list, vectors, bit vectors, and strings. There are many operations that can be done to any sequential type. In almost all Lisp dialects the lists are made up of “conses”, sometimes called “cons cells” or “pairs”. A “cons” is a data structure with two slots, called its “car” and “cdr”. A list is a linked string of “conses”. Each “cons car” refers to a member of the list (possibly another list). Each “cons cdr” refers to the following “cons”, except for the last “cons” whose value “cdr” will be nil. Conses can also be used to implement trees and other complex data structures. It is also possible to create circular data structures.
Common Lisp supports multi-dimensional arrays, and they can be dynamically resized if necessary. Multidimensional arrays can be used to form mathematical matrices. A vector is a one-dimensional array. Arrays can contain any type (even different types in the same array) or they can be specialized to contain a single type of data. Many implementations can optimize array functions when the array being used contains a single data type. There are two specialized types of standard arrays: a “string” is a character vector, and a “bit vector” is a bit vector.
Hash tables keep associations between data objects. Any object can be used as a key or value. Hash tables, like arrays, automatically adjust their size.
Packages are collections of symbols. A package can export some symbols, marking them as part of a public interface. Packages can use other packages.
Structures, similar to the use of “structs” in C, or “registers” in Pascal, represent arbitrary complex data structures with any number and type of fields (called “slots”). Structures allow singular inheritance.
Classes are similar to structures, but offer more dynamic features and multiple CLOS herenics. Classes have been added late to Common Lisp and can lead to conceptual confusion with structures. Objects made up of classes are called “instances”. A special case is the generic functions. Generic functions are functions and instances.
Features: Common Lisp supports first-class features. For example, you can create functions that take other functions as an argument or return a function. This allows defining very general operations. Common Lisp libraries rely heavily on these higher order functions.
The evaluation model for functions is very simple. When the evaluator encounters the form “(F A1 A2 …)” then it assumes that the symbol “F” is one of the following: A special operator (easy to check with a “fixed list”) A macro operator (should have been previously defined) The name of a function (default), which can be either a symbol, or some sub-form that begins with the lambda symbol. If “F” is the name of a function, then the arguments “A1, A2, …, An” are evaluated in left-right order, the function is found and called with those values as parameters.
Other types
Pathnames – Represents files or directories on the file system . The Common Lisp pathname is more general than file naming on most operating systems, so Lisp programs are more portable to other systems. Input and Output “streams”: represent binary sources or text data , such as terminal or open files. Common Lisp includes a “pseudo-random number generator (PRNG)”. Conditions: are a type that are used to represent errors, exceptions, and other “interesting” events that a program can respond to. Classes are a first-class object, and are themselves instances of classes called “metaclasses”.
Compiled Interpreted
There are many compilers available for Common Lisp, among the most used and important:
- KCL(Kyoto Common Lisp): is an implementation of Lisp. It is written in C to run under Unix-like operating systems.
- AKCL(Austin Kyoto Common Lisp): is a collection of “KCL” ports, bug fixes and performance improvements.
- CLiCC: Compiled from Common Lisp to C. Intended to be a supplement to CLISP systems to generate portable applications. To produce an executable, the C translated code must be linked to the CLiCC runtime library.
- CLISP: This package includes an interpreter, bytecode compiler, runtime library, and editor.
- CMUCommon Lisp: It is a “industrial power” Common Lisp programming environment in the public domain. Many of the X3j13 changes have been incorporated into CMU CL.
- Garnet: It is an interface development environment for Common Lisp and X11. Help create graphic and interactive interfaces for your software.
- WCL: An implementation of Common Lisp as a shared library. WCL is not 100% complete, but it does have a fully developed environment including dynamic file loading and debugging.
Features
Above was a function example. Here are some more:> gt; (+ 3 4 5 6); this function takes any number of arguments 18> gt; (+ (+ 3 4) (+ (+ 4 5) 6)); isn’t prefix notation fun? 22> gt; (defun foo (xy) (+ xy 5)); defining a function FOO> gt; (foo 5 0); calling a function 10> gt; (defun fact (x); a recursive function (if (> x 0) (* x (fact (- x 1))) 1)) FACT> gt; (fact 5) 120> gt; (defun a (x) (if (= x 0) t (b (- x)))); mutually recursive functions A> gt; (defun b (x) (if (> x 0) (a (- x 1)) (a (+ x 1)))) B> gt; (a 5) T> gt; (defun bar (x); a function with multiple statements in (setq x (* x 3)); its body – it will return the value (setq x (/ x 2)); returned by its final statement (+ x 4)) BAR> gt; (bar 6) 13
When we defined foo we gave it two arguments, x and y. Now when we call foo, we are required to supply exactly two arguments: the first will become the value of x for the duration period of the call to foo, and the second will become the value of y during the call. In LISP [NdT: in Common Lisp; in the original Lisp, no], most variables have lexical scope; that is, if foo calls bar and bar tries to reference ax, it will not get the value of foo for x.
The process of assigning a value to a symbol for the duration of a certain lexical scope is called association [NdT: not entirely true, either. That name has it even if the “allocation” was dynamic. Communisperos are continually using disinformation tricks of this kind to justify their defections against the Lisp tradition and to create the feeling that there is nothing else in the Lisp world]. Optional arguments can be specified for functions. Any argument after the & optional symbol is optional:> gt; (defun bar (x & optional y) (if yx 0)) BAR> gt; (defun baaz (& optional (x 3) (z 10)) (+ xz)) BAAZ> gt; (bar 5) 0> gt; (bar 5 t) 5> gt; (baaz 5) 15> gt; (baaz 5 6) 11> gt; (baath) 13
It is valid to call the bar function with either one or two arguments. If called with one, x will be associated with the value of that argument and y will be associated with nil; if called with two arguments, x and y will be associated with the values of the first and second arguments, respectively. The baaz function has two optional arguments. Specify a default value for each of them: if the caller specifies only one argument, z will be associated with 10 instead of nil, and if the caller does not specify arguments, x will be associated with 3 and z 10. It can be done that the function accepts any number of arguments by ending its argument list with the & rest parameter. LISP will list all the arguments not otherwise accounted for in a list and associate the & rest parameter with that list. Thus:> gt; (defun foo (x & rest y) y) FOO> gt; (foo 3) NIL> gt; (foo 4 5 6) (5 6)
Finally, the function can be given another type of optional argument called a keyword argument. The caller can give these arguments in any order, because they are tagged with keywords. > gt; (defun foo (& key xy) (cons xy)) FOO> gt; (foo: x 5: y 3) (5. 3)> gt; (foo: y 3: x 5) (5. 3)> gt; (foo: and 3) (NIL. 3)> gt; (foo) (NIL)
The & key parameters can also have default values:> gt; (defun foo (& key (x 5)) x) FOO> gt; (foo: x 7) 7> gt; (foo) 5
