Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Lisp (programming language)

From Simple English Wikipedia, the free encyclopedia
"LISP" redirects here. For the speech disorder, seeLisp.

Lisp (used to be calledLISP) is aprogramming language. It is among the oldest programming languages that are still used today. OnlyFortran is one year older. Lisp was designed byJohn McCarthy in 1958. The best-known versions of LISP areCommon Lisp,Scheme andClojure. Many concepts that are used in modern programming languages were first created in Lisp.Linked lists are a very important data structure in Lisp. The basic concepts behind Lisp are easy to learn.Logo is another version of Lisp that was made for children. Logo can help young children develop skills and become efficient within the programming language.

Simple examples (Scheme)

[change |change source]

In Lisp, operations are written inprefix notation, and they start and end withparentheses. For example, the formula3+54{\displaystyle {\frac {3+5}{4}}} is written as:

(/(+35)4); returns 2

Because Lisp is afunctional language, Lisp programs often userecursion to solve problems. Here is aScheme program that finds thefactorial of a number. The function(factorial n) starts by testing ifn=0{\displaystyle n=0} or not. Ifn=0{\displaystyle n=0}, then(factorial 0) is 1. Ifn0{\displaystyle n\neq 0}, then(factorial n) returns theproduct ofn{\displaystyle n} and the factorial ofn1{\displaystyle n-1}.

(define(factorialn)(if(=n0)1(*n(factorial(-n1)))))(factorial6); returns the factorial of 6: 6! = 6*5*4*3*2*1 = 720

Linked lists are an important idea in Lisp. The list without any things in it is known as theempty ornil list, and is written as'(). A list that has things in it is written as'(dog cat).

The operationcar is used to get the first thing of a list. For example,

(car'(dogcatfish)); returns 'dog, which is the first thing in the list(car'(1234567)); returns 1(car'()); this code gives an error because the list is empty/nil

The operationcdr returns everything in the list except for the first thing.

(cdr'(dogcatfish)); returns '(cat fish)(cdr'(6)); returns '(), because there is nothing in the list after the first thing (6)(cdr'()); gives an error because the list is empty/nil

Here is ahello world program in Scheme:

(display"Hello world!")
Thisshort article abouttechnology can be made longer. You can help Wikipedia byadding to it.
Retrieved from "https://simple.wikipedia.org/w/index.php?title=Lisp_(programming_language)&oldid=9556810"
Category:
Hidden category:

[8]ページ先頭

©2009-2025 Movatter.jp