Lisp programming language: basic elements, training, fields of application

Lisp is the abbreviation for LISt Processing Language - the main list in the structure of the language. These family languages ​​allow professionals to write programs that are faster than other languages. The Lisp programming language and its dialects, such as Common, Scheme and Clojure, contribute to the creation of powerful and flexible software needed for complex and rapidly developing fields of science and technology.

There are several important key features that distinguish the languages ​​of this family from other programming languages ​​and make them ideal tools for applications of artificial intelligence and machine learning. Lisp has a series of DSL domain languages ​​that specialize in a specific field, facilitate the formulation of research problems, and help establish standards and programming best practices for a specific research area.

Story

LISP Family Language History




Lisp is the second oldest high-level language (after FORTRAN), first developed by John McCarthy (Massachusetts Institute of Technology). Although it is used as a programming language in many fields of science, but after the Dartmouth Conference of 1956, which is considered the birthplace of the discipline of artificial intelligence (AI), it is primarily identified with this field of science for many years.





In the early years, its heterogeneous dialects grew, because they found their application on different platforms. In 1984, the efforts of scientists to standardize programming languages ​​led to the development of Common Lisp, which in 1994 became the ANSI standard. Today, most applied areas try to adhere to this standard.

Another early dialect - Lisp-Scheme - has survived to this day, is a standardized and widely used language for programming from scratch. Although it is similar to Lisp, it differs from it in some elements that allow us to consider it as a separate language.

Key programming points

Lisp allows programmers to write faster. An empirical study shows that when specialists solve the same problems in Lisp, C / C ++ and Java, the Lisp programs are smaller, and therefore easier to maintain, and require less time to develop and run. The Lisp programming language simplifies the creation of macros that facilitate the creation of modular extensions to help professionals easily develop software plugins. This, in turn, paves the way for creating fault-tolerant domain languages ​​in applications of any field of research or specialization.

The current state of Lisp research in computer science and computer engineering is at a point where it is expected to be created on the basis of a universal language, which is extremely necessary, especially given the documented shortcomings of major programming languages ​​such as R and Python. The main elements of the language have several other functions that distinguish it from others:





  1. In Lisp, programmers usually work in a special incremental interactive programming environment called the eval-print (REPL) read loop. This means that the system continuously reads the expressions entered by the user, evaluates them and prints the results.
  2. Common Lisp was designed from the ground up to create large, complex and time-consuming applications and thus supports hot-swapping software - the code of an executable program can be changed without having to interrupt it.
  3. The Lisp programming language has invented exception handling, it has an error handling tool - a “condition system” that goes far beyond most other languages.
  4. Common Lisp implementations usually come with a complex “external function interface” (FFI) that allows direct access to Lisp code written in C or C ++, and sometimes Java code. This enables programmers to use libraries written in other languages, which makes these libraries dependent on Lisp.
  5. Lisp gives programmers the opportunity to implement complex data operations, and mathematical constructions in an expressive and natural idiom.

Basic concept

Basic programming concept




Lisp is the earliest representative of the functional programming language paradigm from scratch. Unlike procedural and object-oriented languages, the theoretical model of which is a Turing machine, the theoretical model of Lisp calculation is the Lambda calculus developed by the Alonso Church. This difference can be understood in the following ways:

  1. In procedural languages, code works with data.
  2. In object-oriented languages, objects encapsulate code and data by interacting with each other.
  3. In functional languages, data is transmitted through functions, but does not have a separate existence of its own.
  4. In pure functional languages, this is ephemeral.

However, most functional languages ​​(including Lisp) provide a mechanism for storing certain data even when it does not pass through functions. This takes the form of what Common Lisp calls “special variables,” and is equivalent to “global variables” in other programming languages. That is, although it is a functional language, it is not purely functional, although it can be used as one, avoiding imperative constructions.

Interactivity and flexibility

Language interactivity and flexibility




The speed of Lisp languages ​​is usually equivalent to interpreted languages. It is also the source of the old myth that if it is interpreted, it must therefore be slow, but it is not. Compilers for Lisp have existed since 1959, and now all the main implementations of Common Lisp can be compiled directly with machine code, which often coincides with C code. For example, the CL — PPCRE expression library written in Common Lisp is faster than the regular expression engine Perl on some tests in C, and learning Lisp is a lot easier.

Programmers who use interpreted languages ​​such as Python or Perl should resort to writing C / C ++ for critical parts of their code for convenience and flexibility and have unique capabilities for this. This was shown with direct benchmarking by the creator of the R programming language, Ross Ihaki, who provided tests demonstrating that an optional Lisp type declaration and a machine code compiler can use them 380 times faster than R and 150 times faster than Python.

And not only the code created by default compilers is efficient. Common Lisp, in particular, offers unique opportunities to optimize those parts of the code that really need to be very fast. This includes the so-called compiler macros, which can convert function calls into more efficient code at runtime and a mandatory disassembler, which allows programmers to fine-tune time-critical functions until the compiled code meets their expectations.

Assessment of special forms and macros

If the first character in the list to be evaluated is the name of a special form or macro, because the interpreter does not evaluate the arguments. However, a special form or macro can evaluate some of the arguments, how it is processed varies in a special macro form. For example, the special form setq evaluates the second argument, but not the first. Example: consider the second line of the following code fragment: (setq a 1) (setq a (+ 2 3)).

Since the special form setq evaluates its second argument, the form (+ 2 3) evaluates to 5. However, the form is not rated 5, but assigned. If setq was a function or a special form that evaluated both arguments, the operation would mean that 5 should be equal to 1, which is obviously an absurd operation!

Some forms and functions

Some forms and functions




Listed below are just a few of the special forms, macros, and lisp functions. Some of the special forms and macros Quote are a special form that simply conveys its invaluable argument. For example, the value (quote a) of the character a. For convenience, it is believed that the expression of the form anything is equivalent to (quote anything).

Setq is a special form that evaluates its second argument, and then assigns a value to a variable called its argument.

Let is a special form that creates lexical variables. It has the following basic form: (let ({(variable expression)} *) {form} *). Forms are evaluated in a context in which each of the variables is a lexical variable associated with the indicated initial value. All expressions are evaluated before any variable is bound, so the expression cannot use the previously declared let variable.

If is a special form that selects one of two expressions for evaluation based on the result of a test, and its value becomes the value of the entire expression. This is similar to the conditional expression of the languages ​​of the C-family. Two forms should be single s-expressions, however, progn can be used to group several forms (similar to {...} Java), although this, of course, is not a purely functional style.

The else form may be omitted, in which case, if the test is false, the result will be nil. Cond is a macro that selects one series of expressions from several for evaluation. It has the following basic form (cond {(test {form} *)} *). Each test is evaluated in turn until a result other than nil is returned - at this point the following form will be evaluated. The value of the last evaluated form becomes the value of cond.

And - a macro with any number of arguments, which are usually all tests - true.

Or - a macro with any number of arguments, the evaluation of the arguments stops as soon as the true (not zero) happens.

Defun is a macro for defining named functions. The main syntax is (defun name ({parameter} *) {form} *).

Lambda is a macro for defining anonymous functions.

List Operations

List Operations




Functional Lisp programming languages ​​mean that arguments are evaluated before the cons-2 operation of an argument of any type. Creates a dotted pair (cons cell) consisting of 2 arguments:

  • (cons' a 3) is (a. 3) car-1 argument, which must be a true or dashed list. Retrieves the car of the first cell of the list.
  • (car '(a 3)) is a. cdr- 1 argument, which must be a true or dashed list. Retrieves the cdr of the first cell in the list. If a list consists of more than one cell, its cdr itself will be a list.

(cdr '(a 3)) - is (3). caar, cdar, cadr, cddr and a few more - any combination of up to four elements.

List - a different number of arguments of any type. Converts its arguments to a real list. For example, (list 'a' b '(1 2)) is (ab (1 2)) append - any number of arguments - all but the last should be true lists. Combines his arguments into one list, which will be true. For example, (append '(1 2)' (3 4)) is (1 2 3 4).

Arithmetic operations

Arithmetic operations




Lisp is a programming language that supports the arithmetic operations found in most programming languages, as well as many unique ones. Most operations take any number of arguments, for example, (* 2 3 4 5) are evaluated to 120.

All are functions in which arguments are evaluated before the operation is performed:

  • Addition - any number of arguments, without arguments gives a single element for addition, 0 - negation - one argument, subtraction - two or more arguments, illegal without arguments.
  • Multiplication - any number of arguments, without arguments gives a single element for multiplication, 1. / mutual - one argument.
  • Division is two or more arguments.

Uses in AutoCAD

Uses in AutoCAD




Creating a folder outside of AutoCAD is necessary to save all Autolisp files and any other user files. Before starting Lisp, do the following:

  1. Create a folder to host custom files C: \ autocad_custom \.
  2. Create a subfolder for Lisp files. C: \ autocad_custom \ autolisp \.
  3. Place the custom Lisp file in the autolisp folder.
  4. Launch Lisp autocad.
  5. Go to the “Tools-> Options” section and select the “FILES” tab.
  6. Expand the support file search path, then click "ADD" on the right side.
  7. Click “VIEW” and find the autolisp folder created earlier, and click to make changes.

Download the Lisp file of a programming language:

  1. Enter APPLOAD on the command line and press Enter.
  2. Go to the autolisp folder and click on the desired Lisp file, then press LOAD and then CLOSE.

Using a Lisp File:

  1. Usually, after loading, the Lisp file name is entered to use it. Sometimes after loading a message is displayed that you need to enter an ordered one to use the Lisp file.
  2. If the name minus the .lsp extension does not work, and there is no message what to enter, then you will need to open the Lisp file either in VLIDE or NOTEPAD and see the defun c part to determine, you need to enter it to start the file after loading.

Artificial Intelligence Franz

Artificial Intelligence Franz




Franz Lisp is the first artificial intelligence invention from leading technology provider Semantic Graph Database. AllegroGraph is a super-scalable, high-performance and transactional semantic graphic database that turns complex data into effective business ideas. Allegro CL provides the ideal Lisp programming environment for creating complex mission-critical applications that solve real-world problems.

Franz Inc. strives to develop products based on the market, the highest level of product quality and flexible support and customer service. Franz customers include dozens of Fortune 500 companies that span healthcare, intelligence agencies, life sciences, telecommunications, and promising research organizations and are looking for solutions to complex problems.

Areas of use

In the 1980s and 1990s, tremendous efforts were made to bring together the fields of application of the Lisp language. The result was the standardization of the Common Lisp, the ANSI standard of which was published in 1994, as well as the more widely known ISO extension of the ISOLISP ISO released in 1997 and the ISO / IEC 13816: 2007 (E) revised in 2007.

At that time, Lisp was much more popular than it is now. Despite the more popular languages ​​close to the machine (C, C ++), Lisp remains a fairly used language, especially as an embedded language in applications where it serves as an extension language. The most famous case of Lisp is embedded using the Emacs text editor and AutoLISP in AutoCAD.

Lisp is fourth in the lines of code used to implement the 8,600 source packages available on the Debian operating system released in June 2005. The first eight languages ​​are distributed as follows: C (57%), C ++ (16.8%), Shell (9%), Lisp (3%), Perl (2.8%), Python (1.8%) , Java (1.6%), Fortran (1.2%). In July 2013, Lisp was in the 15th position of the TIOBE index.

Today there are several more popular Lisp options, for example:

  1. Common lisp
  2. Scheme
  3. EmacsLisp, for programming the Emacs editor.

In addition, there are libraries for various programming languages ​​that implement subsets of Lisp or Scheme, or at least some functions.




All Articles