$Id: lisp_tut.txt 66 2007-02-23 17:32:26Z raido $ http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/doc/intro/lisp_tut.txt Common LISP Hints Geoffrey J. Gordon Friday, February 5, 1993 Note: This tutorial introduction to Common Lisp was written for the CMU environment, so some of the details of running lisp toward the end may differ from site to site. 注記: このCommon LispのチュートリアルはCMU環境を想定し記述されています。 そのため終盤につれてLispの実行結果が異なる場合があるかもしれません。 ■Further Information 更なる情報 The best LISP textbook I know of is 私の知る最良のLISPのテキストは Guy L. Steele Jr. _Common LISP: the Language_. Digital Press. 1984. The first edition is easier to read; the second describes a more recent standard. (The differences between the two standards shouldn't affect casual programmers.) 初版は第二版よりも読みやすいでしょう。第二版にはより最近の規格についての 記述してあります。(両者の違いは入門者が気にするような内容ではありません) A book by Dave Touretsky has also been recommended to me, although I haven't read it, so I can't say anything about it. Dave Touretskyによって薦められた本もありますが、読んだことが無いので、何 も言及できません。 Some LISPS have online manuals. See "Getting Started" at the end of this document. LISP処理系によってはオンラインマニュアルがあります。この文書の最後の「さ あはじめよう」の章を参照してください。 Symbols ■シンボル A symbol is just a string of characters. There are restrictions on what you can include in a symbol and what the first character can be, but as long as you stick to letters, digits, and hyphens, you'll be safe. (Except that if you use only digits and possibly an initial hyphen, LISP will think you typed an integer rather than a symbol.) Some examples of symbols: シンボルは単なる文字の連続です。シンボルの構成要素になれる文字の制限はあ りますし、先頭の文字の制限はあります。しかしながら、文字と数字とハイフン のみを使う限り、大丈夫です。(ただし、数字だけの場合や先頭にハイフンを使 った場合、LISP処理系はシンボルではなく整数値が入力されたと判断してしまう かもしれません。)シンボルの例です: a b c1 foo bar baaz-quux-garply Some things you can do with symbols follow. (Things after a ">" prompt are what you type to the LISP interpreter, while other things are what the LISP interpreter prints back to you. The ";" is LISP's comment character: everything from a ";" to the next carriage return is ignored.) シンボルに対してできることは次のようなことです。(「>」プロンプトの後に 書いてあることがlisp処理系に対する入力です。一方、プロンプトのない行の記 述がlisp処理系が返したものです。「;」はlispのコメント文字です。「;」の次 から行末までは全部無視されます) > (setq a 5) ;store a number as the value of a symbol ; シンボルに数値を設定 5 > a ;take the value of a symbol ; シンボルから値を取得 5 > (let ((a 6)) a) ;bind the value of a symbol temporarily to 6 ; 一時的にシンボルを6に束縛 6 > a ;the value returns to 5 once the let is finished ; letは終わったので5が返る 5 > (+ a 6) ;use the value of a symbol as an argument to a function ; シンボルの値を関数の引数として使う 11 > b ;try to take the value of a symbol which has no value ; 値のないシンボルの値を取得しようとすると Error: Attempt to take the value of the unbound symbol B There are two special symbols, t and nil. The value of t is defined always to be t, and the value of nil is defined always to be nil. LISP uses t and nil to represent true and false. An example of this use is in the if statement, described more fully later: tとnilという特別なシンボルがあります。tの値は常にtと、nilの値は常にnilと 定義されています。LISPではtとnilを真偽値の代表として使います。使用例は以 下のif文です。詳しい説明は後ほど行います。 > (if t 5 6) 5 > (if nil 5 6) 6 > (if 4 5 6) 5 The last example is odd but correct: nil means false, and anything else means true. (Unless we have a reason to do otherwise, we use t to mean true, just for the sake of clarity.) 最後の例は奇妙に見えるかもしれません。しかし正しいのです。nilは偽を意味 し、nil以外の全てが真を意味します。(特別な理由が無い限り、分かりやすい ように真を表すのにはtを使います) Symbols like t and nil are called self-evaluating symbols, because they evaluate to themselves. There is a whole class of self-evaluating symbols called keywords; any symbol whose name starts with a colon is a keyword. (See below for some uses for keywords.) Some examples: tやnilのようなシンボルは自己評価シンボルと呼びます。評価した結果が自分自 身になるからです。必ず自己評価シンボルがあり、それはキーワードと呼ばれま す。コロンで始まるシンボルは全てキーワードです。(キーワードの使用例は後 述します)キーワードの例を示します。 > :this-is-a-keyword :THIS-IS-A-KEYWORD > :so-is-this :SO-IS-THIS > :me-too :ME-TOO Numbers ■数値 An integer is a string of digits optionally preceded by + or -. A real number looks like an integer, except that it has a decimal point and optionally can be written in scientific notation. A rational looks like two integers with a / between them. LISP supports complex numbers, which are written #c(r i) (where r is the real part and i is the imaginary part). A number is any of the above. Here are some numbers: 整数は数字の連続です。ただし、先頭に「+」や「-」の符号がつくこともありま す。実数はほとんど整数と同じですが、小数点がついています。また、科学表記 で書かれていることもあります。有理数は「/」をはさんだ二つの整数で表され ます。そして、LISP処理系は複素数もサポートします。それは「#c(r i)」とい う形で書かれます。(rの部分が複素数の実部で、iの部分が虚部です)上記のす べてが数値です。例を示します。 5 17 -34 +6 3.1415 1.722e-15 #c(1.722e-15 0.75) The standard arithmetic functions are all available: +, -, *, /, floor, ceiling, mod, sin, cos, tan, sqrt, exp, expt, and so forth. All of them accept any kind of number as an argument. +, -, *, and / return a number according to type contagion: an integer plus a rational is a rational, a rational plus a real is a real, and a real plus a complex is a complex. Here are some examples: 基本的な算術関数はすべて揃っています。+、-、 *、/、floor、ceiling、mod、 sin、cos、tan、sqrt、exp、exptなどなど。これらはあらゆる種類の数値を引数 として受け付けます。+、-、 *、/は型変換に従って答えの数値を返します。整 数足す有理数は有理数に、有理数足す実数は実数に、実数足す複素数は複素数に なります。以下に例を示します。 > (+ 3 3/4) ;type contagion 15/4 > (exp 1) ;e 2.7182817 > (exp 3) ;e*e*e 20.085537 > (expt 3 4.2) ;exponent with a base other than e 100.90418 > (+ 5 6 7 (* 8 9 10)) ;the fns +-*/ all accept multiple arguments There is no limit to the absolute value of an integer except the memory size of your computer. Be warned that computations with bignums (as large integers are called) can be *slow*. (So can computations with rationals, especially compared to the corresponding computations with small integers or floats.) 整数の絶対値の大きさには制限がありません。ただし、計算機のメモリサイズの 制限は受けます。bignums(大きな整数の事をこう呼びます)の計算は時間がか かることがあるので注意してください。(有理数の計算も同様です。特に同じく らいの大きさの小さな整数や小数と比較をする場合は注意しましょう) Conses ■コンスセル A cons is just a two-field record. The fields are called "car" and "cdr", for historical reasons. (On the first machine where LISP was implemented, there were two instructions CAR and CDR which stood for "contents of address register" and "contents of decrement register". Conses were implemented using these two registers.) consは二つの記憶領域を持ちます。歴史的な理由によってそれらは「car」「cdr」 と呼ばれます。(LISPが実装された最初の計算機上でCARとCDRという命令があり ました。それぞれ「contents of address register」と「contents of decrement register」という意味でした。consはその二つの命令を使って実装さ れていました) Conses are easy to use: consは簡単に使えます。 > (cons 4 5) ;Allocate a cons. Set the car to 4 and the cdr to 5. ; consを割り当てます。carに4を設定し、cdrに5を設定します (4 . 5) > (cons (cons 4 5) 6) ((4 . 5) . 6) > (car (cons 4 5)) 4 > (cdr (cons 4 5)) 5 Lists ■リスト You can build many structures out of conses. Perhaps the simplest is a linked list: the car of each cons points to one of the elements of the list, and the cdr points either to another cons or to nil. You can create such a linked list with the list fuction: consを使っていろいろな構造を作ることができます。もっともシンプルなのはお そらくリンクリストです。各consのcarがリストの要素の一つを指し、cdrが別の consかnilを指します。このようなリンクリストはlist関数で作ることができま す。 > (list 4 5 6) (4 5 6) Notice that LISP prints linked lists a special way: it omits some of the periods and parentheses. The rule is: if the cdr of a cons is nil, LISP doesn't bother to print the period or the nil; and if the cdr of cons A is cons B, then LISP doesn't bother to print the period for cons A or the parentheses for cons B. So: LISP処理系はリンクリストを特別な表記で出力します。一部のピリオドや括弧を 省略します。それは次のルールにしたがって行われます。もし、cdrがnilだった ら、処理系はピリオドもnil自体も出力しません。もし、consのAのcdrがconsのB だったら、処理系はconsのAの方のピリオドとconsのBの方の括弧を出力しません。 ですから、以下のようになります。 > (cons 4 nil) (4) > (cons 4 (cons 5 6)) (4 5 . 6) > (cons 4 (cons 5 (cons 6 nil))) (4 5 6) The last example is exactly equivalent to the call (list 4 5 6). Note that nil now means the list with no elements: the cdr of (a b), a list with 2 elements, is (b), a list with 1 element; and the cdr of (b), a list with 1 element, is nil, which therefore must be a list with no elements. 最後の例は(list 4 5 6)の呼び出しと完全に等価です。nilは要素の無いリスト を意味します。二つの要素を持つリスト(a b)のcdrは(b)という一つの要素を持 つリストです。一つの要素を持つリスト(b)のcdrはnilです。よってnilは要素が ゼロのリストなければいけません。 The car and cdr of nil are defined to be nil. nilのcarやcdrはnilであると定義されています。 If you store your list in a variable, you can make it act like a stack: 変数aにリストを設定したとき、aをスタックのように振舞わせることもできます。 > (setq a nil) NIL > (push 4 a) (4) > (push 5 a) (5 4) > (pop a) 5 > a (4) > (pop a) 4 > (pop a) NIL > a NIL Functions ■関数 You saw one example of a function above. Here are some more: 関数の例はすでに見てきましたが、さらに示しましょう。 > (+ 3 4 5 6) ;this function takes any number of arguments ; この関数は引数をいくつでも受け付けます 18 > (+ (+ 3 4) (+ (+ 4 5) 6)) ;isn't prefix notation fun? ; 前置記法って楽しくない? 22 > (defun foo (x y) (+ x y 5)) ;defining a function ; 関数の定義 FOO > (foo 5 0) ;calling a function ; 関数の呼び出し 10 > (defun fact (x) ;a recursive function ; 再帰関数 (if (> x 0) (* x (fact (- x 1))) 1)) FACT > (fact 5) 120 > (defun a (x) (if (= x 0) t (b (- x)))) ;mutually recursive functions ; 相互再帰関数 A > (defun b (x) (if (> x 0) (a (- x 1)) (a (+ x 1)))) B > (a 5) T > (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 ; body部分に複数のステートメントがある関数です。 ; -- この場合、最後のステートメントの戻り値が関数自体の戻り値になります。 (+ x 4)) BAR > (bar 6) 13 When we defined foo, we gave it two arguments, x and y. Now when we call foo, we are required to provide exactly two arguments: the first will become the value of x for the duration of the call to foo, and the second will become the value of y for the duration of the call. In LISP, most variables are lexically scoped; that is, if foo calls bar and bar tries to reference x, bar will not get foo's value for x. 関数fooを定義したとき、仮引数はxとyの二つにしました。この関数を呼び出す 時はきっかり二つの引数を指定する必要があります。最初の引数がfooの呼び出 しの間xの値になり、二番目の引数がyの値になります。LISPではほとんどの変数 はレキシカルスコープを持ちます。すなわちfooが変数xを参照しようとする関数 barを呼び出すとしても関数はfooのxの値を取得できません。 The process of assigning a symbol a value for the duration of some lexical scope is called binding. レキシカルスコープに従ってシンボルに値を代入する処理のことをバインディン グと呼びます。 You can specify optional arguments for your functions. Any argument after the symbol &optional is optional: 関数にはオプショナル引数を設定できます。&optionalの後の引数は全てオプシ ョナル引数です。 > (defun bar (x &optional y) (if y x 0)) BAR > (defun baaz (&optional (x 3) (z 10)) (+ x z)) BAAZ > (bar 5) 0 > (bar 5 t) 5 > (baaz 5) 15 > (baaz 5 6) 11 > (baaz) 13 It is legal to call the function bar with either one or two arguments. If it is called with one argument, x will be bound to the value of that argument and y will be bound to nil; if it is called with two arguments, x and y will be bound to the values of the first and second argument, respectively. barの引数が一つだったり二つだったりしていますが正しい呼び出しです。引数 一つで呼び出された場合はxが引数の値に束縛され、yはnilに束縛されます。引 数二つで呼び出された場合はxとyのそれぞれが引数の値に束縛されます。 The function baaz has two optional arguments. It specifies a default value for each of them: if the caller specifies only one argument, z will be bound to 10 instead of to nil, and if the caller specifies no arguments, x will be bound to 3 and z to 10. 関数baazはオプショナル引数を二つ持ちます。この関数にはそれぞれにデフォル トの値が指定されています。もし、この関数が呼び出される際に一つしか引数が 与えられなかったら、zはnilではなく10に束縛されます。もし、この関数が引数 無しで呼び出されたら、xは3に束縛され、zは10に束縛されます。 You can make your function accept any number of arguments by ending its argument list with an &rest parameter. LISP will collect all arguments not otherwise accounted for into a list and bind the &rest parameter to that list. So: 引数リストが&restパラメータで終わっているとき、関数はいくつでも引数を受 け取るようになります。LISP処理系は対応する仮引数の無い引数をすべてリスト に集め、そのリストと&restパラメータを結び付けます。 > (defun foo (x &rest y) y) FOO > (foo 3) NIL > (foo 4 5 6) (5 6) Finally, you can give your function another kind of optional argument called a keyword argument. The caller can give these arguments in any order, because they're labelled with keywords. 最後にオプショナル引数に似た別の引数を紹介します。キーワード引数と呼ばれ るものです。呼び出し側ではこれらの引数を順不動で指定できます。なぜならキ ーワードで識別可能だからです。 > (defun foo (&key x y) (cons x y)) FOO > (foo :x 5 :y 3) (5 . 3) > (foo :y 3 :x 5) (5 . 3) > (foo :y 3) (NIL . 3) > (foo) (NIL) An &key parameter can have a default value too: キーワード引数もデフォルト値を設定することができます。 > (defun foo (&key (x 5)) x) FOO > (foo :x 7) 7 > (foo) 5 Printing ■出力 Some functions can cause output. The simplest one is print, which prints its argument and then returns it. 出力のための関数もあります。最も簡単なのはprintです。引数を出力しそれを 返します。 > (print 3) 3 3 The first 3 above was printed, the second was returned. 上の記述において最初の3は出力されたものです。二番目は関数の戻り値です。 If you want more complicated output, you will need to use format. Here's an example: より複雑な出力をしたいときはformatを使います。以下に例を示します。 > (format t "An atom: ~S~%and a list: ~S~%and an integer: ~D~%" nil (list 5) 6) An atom: NIL and a list: (5) and an integer: 6 The first argument to format is either t, nil, or a stream. T specifies output to the terminal. Nil means not to print anything but to return a string containing the output instead. Streams are general places for output to go: they can specify a file, or the terminal, or another program. This handout will not describe streams in any further detail. formatの最初の引数はtかnilかストリームです。tはターミナルへの出力の指示 になります。nilは何も出力せず、出力に相当する文字列を返します。ストリー ムというのは出力の一般的な場所です。それはファイルだったり、ターミナルだ ったり、別のプログラムだったりします。このテキストではストリームについて これ以上詳しい説明は行いません。 The second argument is a formatting template, which is a string optionally containing formatting directives. 二つ目の引数は整形のテンプレートです。基本的に文字列ですが、フォーマット 指定子も含みます。 All remaining arguments may be referred to by the formatting directives. LISP will replace the directives with some appropriate characters based on the arguments to which they refer and then print the resulting string. 残りの引数は全てフォーマット指定子に参照されます。LISP処理系は指定子を対 応する引数に基づいた適切な表現で置き換えます。そして、その結果を出力しま す。 Format always returns nil unless its first argument is nil, in which case it prints nothing and returns a string. formatは基本的にnilを返します。例外は最初の引数がnilの場合です。この場合、 formatは何も出力せずに文字列を返します。 There are three different directives in the above example: ~S, ~D, and ~%. The first one accepts any LISP object and is replaced by a printed representation of that object (the same representation which is produced by print). The second one accepts only integers. The third one doesn't refer to an argument; it is always replaced by a carriage return. 上の例では三つの異なる指定子を紹介しました。「~S」と「~D」と「~%」です。 最初の「~S」はすべてのLISPオブジェクトを受け付けます。そしてそのオブジェ クトの印字表現で置き換えます。(printによる表現と同じものです)二つ目の 「~D」は整数のみを受け付けます。三つ目の「~%」は引数を参照しません。これ は常に改行で置き換えられます。 Another useful directive is ~~, which is replaced by a single ~. もうひとつのよく使う指定子は「~~」です。これはひとつの「~」に置き換えら れます。 Refer to a LISP manual for (many, many) additional formatting directives. フォーマット指定子はもっとたくさんの種類がありますので、LISPのマニュアル を参照してください。 Forms and the Top-Level Loop ■フォームとトップレベルループ The things which you type to the LISP interpreter are called forms; the LISP interpreter repeatedly reads a form, evaluates it, and prints the result. This procedure is called the read-eval-print loop. LISP処理系に打ち込んだものはフォームと呼ばれます。LISP処理系はフォームを 読み込み、それを評価し、結果を出力するということを繰り返します。この一連 の動作をread-eval-print loopと呼びます。 Some forms will cause errors. After an error, LISP will put you into the debugger so you can try to figure out what caused the error. LISP debuggers are all different; but most will respond to the command ":help" by giving some form of help. フォームによってはエラーが発生することもあるでしょう。エラーが発生すると デバッガに入りますので、エラーが発生した原因を調べることができます。デバ ッガは処理系によって全く異なります。しかし、たいていの処理系は":help"コ マンドを入力すればヘルプを出力してくれるでしょう。 In general, a form is either an atom (for example, a symbol, an integer, or a string) or a list. If the form is an atom, LISP evaluates it immediately. Symbols evaluate to their value; integers and strings evaluate to themselves. If the form is a list, LISP treats its first element as the name of a function; it evaluates the remaining elements recursively, and then calls the function with the values of the remaining elements as arguments. 一般的に、フォームはアトム(例えば、シンボルや整数や文字列)かリストです。 もしフォームがアトムであれば、LISP処理系はそれを即座に評価します。シンボ ルは評価してその値になり、整数や文字列は評価してそれ自身になります。フォ ームがリストであれば、LISP処理系は最初の要素を関数名として扱います。残り の要素は再帰的に評価されます。そしてそれらの値を引数として関数を呼び出し ます For example, if LISP sees the form (+ 3 4), it treats + as the name of a function. It then evaluates 3 to get 3 and 4 to get 4; finally it calls + with 3 and 4 as the arguments. The + function returns 7, which LISP prints. 例えば「(+ 3 4)」というフォームの場合、「+」を関数名として扱います。そし て「3」を評価して3を得て、「4」を評価して4を得ます。最後に3と4を引数にし て+を呼びます。関数+は7を返し、LISP処理系はそれを出力します。 The top-level loop provides some other conveniences; one particularly convenient convenience is the ability to talk about the results of previously typed forms. LISP always saves its most recent three results; it stores them as the values of the symbols *, **, and ***. For example: トップレベルループには他にも便利な機能があります。特に便利なのは前に入力 したフォームの結果を記録していることです。LISP処理系は常に最新の3つの結 果を保存しています。それらは「*」と「**」と「***」というシンボルの値とし て保存されています。例えば、 > 3 3 > 4 4 > 5 5 > *** 3 > *** 4 > *** 5 > ** 4 > * 4 Special forms ■スペシャルフォーム There are a number of special forms which look like function calls but aren't. These include control constructs such as if statements and do loops; assignments like setq, setf, push, and pop; definitions such as defun and defstruct; and binding constructs such as let. (Not all of these special forms have been mentioned yet. See below.) 関数と同じように呼び出しができるけれど関数ではないスペシャルフォームとい うものがあります。if文やdoループのような制御構造、setqやsetfやpushやpop のような代入文、defunやdefstructのような定義文、letのような束縛の構築、 といったものがスペシャルフォームになります。(この中にはまだ説明していな いスペシャルフォームもありますが、それについては後述します) One useful special form is the quote form: quote prevents its argument from being evaluated. For example: quoteはよく使用するスペシャルフォームです。quoteは引数が評価されるのを抑 止します。 > (setq a 3) 3 > a 3 > (quote a) A > 'a ;'a is an abbreviation for (quote a) ; 'a は(quote a)の省略表記です。 A Another similar special form is the function form: function causes its argument to be interpreted as a function rather than being evaluated. For example: よく似たスペシャルフォームとしてfunctionがあります。functionの引数は評価 されるのではなく、関数として処理されるようにします。 > (setq + 3) 3 > + 3 > '+ + > (function +) # > #'+ ;#'+ is an abbreviation for (function +) ;#'+ は (function +) の省略表記です。 # The function special form is useful when you want to pass a function as an argument to another function. See below for some examples of functions which take functions as arguments. functionスペシャルフォームは関数を別の関数に引数として渡すときに便利です。 関数を引数として受け取る関数の例については後述します。 Binding ■バインディング Binding is lexically scoped assignment. It happens to the variables in a function's parameter list whenever the function is called: the formal parameters are bound to the actual parameters for the duration of the function call. You can bind variables anywhere in a program with the let special form, which looks like this: バインディングとはレキシカルスコープでの代入です。関数が呼び出されるタイ ミングで関数の引数リストに対して起こります。関数呼び出しの間、仮引数に実 際の値が束縛します。また、letスペシャルフォームを使えばプログラムのどこ ででも変数を束縛できます。例えばこのように (let ((var1 val1) (var2 val2) ...) body) Let binds var1 to val1, var2 to val2, and so forth; then it executes the statements in its body. The body of a let follows exactly the same rules that a function body does. Some examples: letはvar1をval1に束縛し、var2をval2に束縛し、以下同様に変数を値に束縛し ます。そのあとでbodyのステートメントをを実行します。letのbody部分の実行 は関数のそれと全く同じルールに従います。 > (let ((a 3)) (+ a 1)) 4 > (let ((a 2) (b 3) (c 0)) (setq c (+ a b)) c) 5 > (setq c 4) 4 > (let ((c 5)) c) 5 > c 4 Instead of (let ((a nil) (b nil)) ...), you can write (let (a b) ...). (let ((a nil) (b nil)) ...)と記述する代わりに(let (a b) ...)とも書けます。 The val1, val2, etc. inside a let cannot reference the variables var1, var2, etc. that the let is binding. For example, let内のval1、val2などの部分では同じletで束縛しているvar1、var2といった変 数を参照できません。 > (let ((x 1) (y (+ x 1))) y) Error: Attempt to take the value of the unbound symbol X If the symbol x already has a global value, stranger happenings will result: もしシンボルxにすでにグローバル値があったら、奇妙な結果になることでしょ う。 > (setq x 7) 7 > (let ((x 1) (y (+ x 1))) y) 8 The let* special form is just like let except that it allows values to reference variables defined earlier in the let*. For example, let*スペシャルフォームはletとほとんど同じです。違うのはlet*内で先に定義 された変数を参照できるところです。 > (setq x 7) 7 > (let* ((x 1) (y (+ x 1))) y) 2 The form (let* ((x a) (y b)) ...) is equivalent to 上のフォームは以下のフォームと等価です。 (let ((x a)) (let ((y b)) ...)) Dynamic Scoping ■ダイナミックスコーピング The let and let* forms provide lexical scoping, which is what you expect if you're used to programming in C or Pascal. Dynamic scoping is what you get in BASIC: if you assign a value to a dynamically scoped variable, every mention of that variable returns that value until you assign another value to the same variable. letフォームとlet*フォームはレキシカルスコープを提供します。それはCや Pascalのプログラミングで期待するようなスコープです。ダイナミックスコープ というのはちょうどBASICのそれです。すなわちダイナミックスコープの変数に 値を代入したら、同じ名前の変数が全てその代入された値になり、再び別の値が 代入されるまで続くということです。 In LISP, dynamically scoped variables are called special variables. You can declare a special variable with the defvar special form. Here are some examples of lexically and dynamically scoped variables. LISPではダイナミックなスコープを持つ変数のことをスペシャル変数と呼びます。 スペシャル変数はdefvarスペシャルフォームで宣言できます。レキシカルスコー プの変数とダイナミックスコープの変数の例をいくつか示します。 In this example, the function check-regular references a regular (ie, lexically scoped) variable. Since check-regular is lexically outside of the let which binds regular, check-regular returns the variable's global value. この例では、関数check-regularは正規の(つまり、レキシカルスコープの)変 数を参照します。check-regularは変数regularを束縛するletの外側にあるので、 check-regularはグローバルの値を返します。 > (setq regular 5) 5 > (defun check-regular () regular) CHECK-REGULAR > (check-regular) 5 > (let ((regular 6)) (check-regular)) 5 In this example, the function check-special references a special (ie, dynamically scoped) variable. Since the call to check-special is temporally inside of the let which binds special, check-special returns the variable's local value. この例では、関数check-specialはスペシャル変数(つまりダイナミックなスコ ープの変数)を参照します。check-specialの呼び出しが変数specialを束縛する letの内側にあるので、check-specialはローカルの値を返します。 > (defvar *special* 5) *SPECIAL* > (defun check-special () *special*) CHECK-SPECIAL > (check-special) 5 > (let ((*special* 6)) (check-special)) 6 By convention, the name of a special variable begins and ends with a *. Special variables are chiefly used as global variables, since programmers usually expect lexical scoping for local variables and dynamic scoping for global variables. 慣習的にスペシャル変数の先頭と末尾には*がつけられます。プログラマは普段 ローカル変数はレキシカルなスコープを持ち、グローバル変数はダイナミックな スコープを持ってることを期待しているので、スペシャル変数は主にグローバル 変数として使われます。 For more information on the difference between lexical and dynamic scoping, see _Common LISP: the Language_. レキシカルスコープとダイナミックスコープの違いについてもっと知りたい場合 は、CLtL2を参照してください。 Arrays ■配列 The function make-array makes an array. The aref function accesses its elements. All elements of an array are initially set to nil. For example: make-array関数は配列を作成します。aref関数はその配列の要素にアクセスしま す。配列のすべての要素はnilで初期化されます。 > (make-array '(3 3)) #2a((NIL NIL NIL) (NIL NIL NIL) (NIL NIL NIL)) > (aref * 1 1) NIL > (make-array 4) ;1D arrays don't need the extra parens ;一次元配列の場合は括弧で囲む必要はありません #(NIL NIL NIL NIL) Array indices always start at 0. 配列のインデックスは常に0からスタートします。 See below for how to set the elements of an array. 配列の要素に値を設定する方法については後述します。 Strings ■文字列 A string is a sequence of characters between double quotes. LISP represents a string as a variable-length array of characters. You can write a string which contains a double quote by preceding the quote with a backslash; a double backslash stands for a single backslash. For example: 文字列とはダブルクオートで囲まれた文字の連続です。LISPでは文字列 は文字の可変長配列として扱われます。文字列中にダブルクオートを含みたい場 合はダブルクオートの前にバックスラッシュを記述します。バックスラッシュを 含みたい場合はバックスラッシュを2つ連続して記述します。例えば、 "abcd" has 4 characters "\"" has 1 character "\\" has 1 character Here are some functions for dealing with strings: これらは文字列を処理する関数です。 > (concatenate 'string "abcd" "efg") "abcdefg" > (char "abc" 1) #\b ;LISP writes characters preceded by #\ ;LISPは文字型には#\を前置して印字します > (aref "abc" 1) #\b ;remember, strings are really arrays ;文字列は配列でもあります The concatenate function can actually work with any type of sequence: concatenate関数は実際にはあらゆるシーケンスに対して実行できます。 > (concatenate 'string '(#\a #\b) '(#\c)) "abc" > (concatenate 'list "abc" "de") (#\a #\b #\c #\d #\e) > (concatenate 'vector '#(3 3 3) '#(3 3 3)) #(3 3 3 3 3 3) Structures ■構造体 LISP structures are analogous to C structs or Pascal records. Here is an example: LISPの構造体はCの構造体やPascalのレコードに似ています。以下に例を示しま す。 > (defstruct foo bar baaz quux) FOO This example defines a data type called foo which is a structure containing 3 fields. It also defines 4 functions which operate on this data type: make-foo, foo-bar, foo-baaz, and foo-quux. The first one makes a new object of type foo; the others access the fields of an object of type foo. Here is how to use these functions: この例ではfooという名前のデータ型を定義しています。そしてそれは3つのフィ ールドを持っています。このデータ型を作る操作をすると同時に4つの関数が定 義されます。make-fooとfoo-barとfoo-baazとfoo-quuxです。最初のmake-fooは foo型のオブジェクトを新たに作ります。残りの関数はfoo型のオブジェクトの各 フィールドにアクセスします。関数の使い方を以下に示します。 > (make-foo) #s(FOO :BAR NIL :BAAZ NIL :QUUX NIL) > (make-foo :baaz 3) #s(FOO :BAR NIL :BAAZ 3 :QUUX NIL) > (foo-bar *) NIL > (foo-baaz **) 3 The make-foo function can take a keyword argument for each of the fields a structure of type foo can have. The field access functions each take one argument, a structure of type foo, and return the appropriate field. make-foo関数はfoo型の構造体が持つフィールドをそれぞれキーワード引数で与 えることが可能です。フィールドへのアクセス関数はそれぞれ一つのfoo型の構 造体を引数として受け付けます。そして、適切なフィールドを返します。 See below for how to set the fields of a structure. 構造体のフィールドに値を設定する方法については次を参照してください。 Setf ■setf Certain forms in LISP naturally define a memory location. For example, if the value of x is a structure of type foo, then (foo-bar x) defines the bar field of the value of x. Or, if the value of y is a one- dimensional array, (aref y 2) defines the third element of y. LISPのあるフォームではメモリ配置が定義されています。例えば、xがfoo型の構 造体である場合は、(foo-bar x)はxのbarフィールドになります。また、yが一次 元の配列である場合は、(aref y 2)はyの3番目の要素になります。 The setf special form uses its first argument to define a place in memory, evaluates its second argument, and stores the resulting value in the resulting memory location. For example, setfスペシャルフォームは第一引数で得たメモリ上の場所に第二引数を評価して 得た値を配置します。例えば、 > (setq a (make-array 3)) #(NIL NIL NIL) > (aref a 1) NIL > (setf (aref a 1) 3) 3 > a #(NIL 3 NIL) > (aref a 1) 3 > (defstruct foo bar) FOO > (setq a (make-foo)) #s(FOO :BAR NIL) > (foo-bar a) NIL > (setf (foo-bar a) 3) 3 > a #s(FOO :BAR 3) > (foo-bar a) 3 Setf is the only way to set the fields of a structure or the elements of an array. setfは構造体のフィールドや配列の要素に設定する唯一の方法です。 Here are some more examples of setf and related functions. setfとそれに関連する関数の例をいくつか示します。 > (setf a (make-array 1)) ;setf on a variable is equivalent to setq ;setfはsetqと同様に変数に値を設定できます #(NIL) > (push 5 (aref a 1)) ;push can act like setf ;pushはsetfど同じように振舞います (5) > (pop (aref a 1)) ;so can pop ;popも同様です 5 > (setf (aref a 1) 5) 5 > (incf (aref a 1)) ;incf reads from a place, increments, 6 ;and writes back ;incfはその箇所を読み取り、加算して、元の箇所に書き込みます > (aref a 1) 6 Booleans and Conditionals ■真偽値と条件式 LISP uses the self-evaluating symbol nil to mean false. Anything other than nil means true. Unless we have a reason not to, we usually use the self-evaluating symbol t to stand for true. LISPでは自身を返すシンボルnilを偽の意味で使用します。nil以外はすべて真と して扱われます。特に意味の無い場合は、通常、自身を返すシンボルtを真の代 表として使用します。 LISP provides a standard set of logical functions, for example and, or, and not. The and and or functions are short-circuiting: and will not evaluate any arguments to the right of the first one which evaluates to nil, while or will not evaluate any arguments to the right of the first one which evaluates to t. LISPではandやorやnotのような標準的な論理関数を提供しています。and関数や or関数は短絡的です。つまり、andは引数の評価値にnilが現れたら、それ以降の 引数を評価しません。また、orは引数の評価値にnil以外が現れたら、それ以降 の引数を評価しません。 LISP also provides several special forms for conditional execution. The simplest of these is if. The first argument of if determines whether the second or third argument will be executed: LISPでは条件式のためにスペシャルフォームもいくつか提供しています。その中 でもっとも単純なのがifです。ifの最初の引数によって、二番目の引数が実行さ れるのか、それとも三番目の引数が実行されるのかが決まります。 > (if t 5 6) 5 > (if nil 5 6) 6 > (if 4 5 6) 5 If you need to put more than one statement in the then or else clause of an if statement, you can use the progn special form. Progn executes each statement in its body, then returns the value of the final one. ifステートメントのthen節やelse節に2つ以上のステートメントを配置したいと きは、prognスペシャルフォームが利用できます。prognは引数のそれぞれのステ ートメントを順に実行していき、最後の評価値を戻り値にします。 > (setq a 7) 7 > (setq b 0) 0 > (setq c 5) 5 > (if (> a 5) (progn (setq a (+ b 7)) (setq b (+ c 8))) (setq b 4)) 13 An if statement which lacks either a then or an else clause can be written using the when or unless special form: then節やelse節のどちらか一方が欠けたifステートメントはwhenまたはunlessス ペシャルフォームで書くことができます。 > (when t 3) 3 > (when nil 3) NIL > (unless t 3) NIL > (unless nil 3) 3 When and unless, unlike if, allow any number of statements in their bodies. (Eg, (when x a b c) is equivalent to (if x (progn a b c)).) ifと異なりwhenやunlessではbodyにいくつでもステートメントを記述することが できます。(例: (when x a b c) は (if x (progn a b c)) と等価です。) > (when t (setq a 5) (+ a 6)) 11 More complicated conditionals can be defined using the cond special form, which is equivalent to an if ... else if ... fi construction. より複雑な条件式としてcondスペシャルフォームが使用できます。これは「もし 〜ならば〜、それとももし〜ならば〜」という構造です。 A cond consists of the symbol cond followed by a number of cond clauses, each of which is a list. The first element of a cond clause is the condition; the remaining elements (if any) are the action. The cond form finds the first clause whose condition evaluates to true (ie, doesn't evaluate to nil); it then executes the corresponding action and returns the resulting value. None of the remaining conditions are evaluated; nor are any actions except the one corresponding to the selected condition. For example: condステートメントにはシンボルのcondの後に、いくつかのcond節が続きます。 それぞれはリストです。cond節の最初の要素は条件式です。そして、残りの要素 は(もしあれば)動作にあたります。condフォームはまず条件式が真になる(つ まり、評価値がnilにならない)cond節を探します。それから、続く動作部分を 実行し、結果を戻り値とします。残りの条件式は評価されません。また、真にな ったcond節以外の動作部分も評価されません。例: > (setq a 3) 3 > (cond ((evenp a) a) ;if a is even return a ((> a 7) (/ a 2)) ;else if a is bigger than 7 return a/2 ((< a 5) (- a 1)) ;else if a is smaller than 5 return a-1 (t 17)) ;else return 17 2 If the action in the selected cond clause is missing, cond returns what the condition evaluated to: もしも、真になるcond節に動作の記述がなかったら、その条件式の評価値がその ままcondの戻り値になります。 > (cond ((+ 3 4))) 7 Here's a clever little recursive function which uses cond. You might be interested in trying to prove that it terminates for all integers x at least 1. (If you succeed, please publish the result.) ここにcondを使用した再帰関数があります。一以上のどんな整数を入力してもこ の関数が停止するかどうか実験してみてください。(可能なら結果を出力してみ ましょう) > (defun hotpo (x steps) ;hotpo stands for Half Or Triple Plus One ;hotpoは「Half Or Triple Plus One(2で割るか3倍して1足すか)」の略です。 (cond ((= x 1) steps) ((oddp x) (hotpo (+ 1 (* x 3)) (+ 1 steps))) (t (hotpo (/ x 2) (+ 1 steps))))) A > (hotpo 7 0) 16 The LISP case statement is like a C switch statement: LISPのcaseステートメントはCのswitchステートメントのようなものです。 > (setq x 'b) B > (case x (a 5) ((d e) 7) ((b f) 3) (otherwise 9)) 3 The otherwise clause at the end means that if x is not a, b, d, e, or f, the case statement will return 9. 最後のotherwise節の意味はもしxがaでもbでもcでもdでもeでもfでもなければ、 そのcaseステートメントは9を返すということを意味します。 Iteration ■繰り返し The simplest iteration construct in LISP is loop: a loop construct repeatedly executes its body until it hits a return special form. For example, LISPにおける単純な繰り返し構造はloopです。loopはreturnスペシャルフォーム が評価されるまで、繰り返しそのbodyを実行しつづけます。 > (setq a 4) 4 > (loop (setq a (+ a 1)) (when (> a 7) (return a))) 8 > (loop (setq a (- a 1)) (when (< a 3) (return))) NIL The next simplest is dolist: dolist binds a variable to the elements of a list in order and stops when it hits the end of the list. つづく単純な繰り返しというとdolistです。dolistは順番にリストの各要素に変 数を束縛します。そして、リストの終端に達したときに終了します。 > (dolist (x '(a b c)) (print x)) A B C NIL Dolist always returns nil. Note that the value of x in the above example was never nil: the NIL below the C was the value that dolist returned, printed by the read-eval-print loop. dolistは常にnilを返します。上記の例ではxの値は決してnilにはなりません。C の後にあるNILはdolistの戻り値です。それがread-eval-print loopによって印 字されています。 The most complicated iteration primitive is called do. A do statement looks like this: 最も複雑な繰り返し構造はdoです。doステートメントはこのように記述されます。 > (do ((x 1 (+ x 1)) (y 1 (* y 2))) ((> x 5) y) (print y) (print 'working)) 1 WORKING 2 WORKING 4 WORKING 8 WORKING 16 WORKING 32 The first part of a do specifies what variables to bind, what their initial values are, and how to update them. The second part specifies a termination condition and a return value. The last part is the body. A do form binds its variables to their initial values like a let, then checks the termination condition. As long as the condition is false, it executes the body repeatedly; when the condition becomes true, it returns the value of the return-value form. doの最初の部分は変数の束縛とその変数の初期値、更新の仕方を記述します。次 の部分には終了条件と戻り値を記述します。最後の部分がbodyです。doフォーム はletのようにまず変数に初期値を束縛します。それから、終了条件をチェック します。条件が偽になっている間は繰り返しbodyを実行します。条件が真になっ たら、return-valueフォームを評価し、その値を戻り値にします。 The do* form is to do as let* is to let. do*フォームとdoフォームの関係はlet*フォームとletフォームの関係のようなも のです。 Non-local Exits ■大域脱出 The return special form mentioned in the section on iteration is an example of a nonlocal return. Another example is the return-from form, which returns a value from the surrounding function: 繰り返しの項で言及したスペシャルフォームのreturnは大域脱出の例の一つです。 他の例としてはreturn-fromフォームがあります。これは関数から脱出して値を 返します。 > (defun foo (x) (return-from foo 3) x) FOO > (foo 17) 3 Actually, the return-from form can return from any named block -- it's just that functions are the only blocks which are named by default. You can create a named block with the block special form: 実は、return-fromフォームはどんな名前つきのブロックからでも脱出できます。 要するに関数にはデフォルトで関数名と同じ名前をつけられたブロックがあると いうことです。名前つきブロックはblockスペシャルフォームで作ることができ ます。 > (block foo (return-from foo 7) 3) 7 The return special form can return from any block named nil. Loops are by default labelled nil, but you can make your own nil-labelled blocks: returnスペシャルフォームはnilという名前のついたブロックから脱出できます。 ループにはnilという名前のブロックがデフォルトで存在します。ただし、その ブロックにはnil以外の名前は付けられません。 > (block nil (return 7) 3) 7 Another form which causes a nonlocal exit is the error form: 大域脱出を伴うフォームは他にはerrorフォームがあります。 > (error "This is an error") Error: This is an error The error form applies format to its arguments, then places you in the debugger. errorフォームはその引数をformat関数に渡して呼び出し、その結果をデバッガ に表示します。 Funcall, Apply, and Mapcar ■funcallとapplyとmapcar Earlier I promised to give some functions which take functions as arguments. Here they are: 前に関数を引数に取れる関数があるといいましたが、こちらがそうです。 > (funcall #'+ 3 4) 7 > (apply #'+ 3 4 '(3 4)) 14 > (mapcar #'not '(t nil t nil t nil)) (NIL T NIL T NIL T) Funcall calls its first argument on its remaining arguments. funcallは最初の引数に与えられた関数に残りの引数を渡して呼び出します。 Apply is just like funcall, except that its final argument should be a list; the elements of that list are treated as if they were additional arguments to a funcall. applyはfuncallにとてもよく似ています。ただし、最後の引数がリストになって います。そのリストの各要素はまるでfuncallに対する追加の引数であるかのよ うに扱われます。 The first argument to mapcar must be a function of one argument; mapcar applies this function to each element of a list and collects the results in another list. mapcarの一番目の引数は引数が一つ関数でなければなりません。mapcarはリスト の各要素を引数にしてこの関数を実行します。そして、その結果をまとめて別の リストを作ります。 Funcall and apply are chiefly useful when their first argument is a variable. For instance, a search engine could take a heuristic function as a parameter and use funcall or apply to call that function on a state description. The sorting functions described later use funcall to call their comparison functions. funcallやapplyが便利なのは主に一番目の引数が変数のときです。例えば、検索 エンジンはパラメータとしてヒューリスティックな関数を取得して、状況に応じ その関数をfuncallまたはapplyで呼び出すことができます。後述のソート関数等 はその比較関数を呼ぶのにfuncallを使用しています。 Mapcar, along with nameless functions (see below), can replace many loops. mapcarを無名の関数(次項を参照)と一緒に使った場合は、たいていループに置 き換えることができます。 Lambda ■lambda If you just want to create a temporary function and don't want to bother giving it a name, lambda is what you need. もしもテンポラリの関数を作りたくて、しかもそれに名前をつけるのが面倒な場 合、lambdaを使うのが最適です。 > #'(lambda (x) (+ x 3)) (LAMBDA (X) (+ X 3)) > (funcall * 5) 8 The combination of lambda and mapcar can replace many loops. For example, the following two forms are equivalent: lambdaとmapcarのコンビネーションはたいていのloopを置き換えることができま す。例えば、以下の2つのフォームは等価です。: > (do ((x '(1 2 3 4 5) (cdr x)) (y nil)) ((null x) (reverse y)) (push (+ (car x) 2) y)) (3 4 5 6 7) > (mapcar #'(lambda (x) (+ x 2)) '(1 2 3 4 5)) (3 4 5 6 7) Sorting and Merging ■ソートとマージ LISP provides two primitives for sorting: sort and stable-sort. LISPはソートのために二つの関数を用意しています。sortとstable-sortです。 > (sort '(2 1 5 4 6) #'<) (1 2 4 5 6) > (sort '(2 1 5 4 6) #'>) (6 5 4 2 1) The first argument to sort is a list; the second is a comparison function. The sort function does not guarantee stability: if there are two elements a and b such that (and (not (< a b)) (not (< b a))), sort may arrange them in either order. The stable-sort function is exactly like sort, except that it guarantees that two equivalent elements appear in the sorted list in the same order that they appeared in the original list. sortの一つ目の引数はリストで、二つ目の引数は比較関数です。sort関数は安定 ではありません。もし、二つの要素aとbがあり、それらが(and (not (< a b)) (not (< b a)))という関係を満たしている場合、sortが両者をどういった順番で 並べるのか分かりません。stable-sort関数はsortによく似ています。ただし、 stable-sortはソートするリストに等価な要素があった場合に、元のリストで現 れる順番で並べることを保証しています。 If you already have two sorted sequences, you can merge them with the merge function. Merge is guaranteed to be stable: if an element in the first sequence is equivalent to one in the second, the element from the first sequence appears first in the output. In the following example, char-lessp considers #\a equivalent to #\A. merge関数はソート済みの二つのシーケンスをマージします。mergeは安定である ことが保証されています。一つ目のシーケンスの要素と等価な要素が二つ目のシ ーケンスにも合った場合、その要素については一つ目のシーケンスの要素の法が 先に出力されます。以下の例をご覧ください。char-lessp関数は#\aと#\Aを等価 とみなします。 > (merge 'string "abc" "ABC" #'char-lessp) "aAbBcC" Merge, like concatenate, will work with any type of sequence. mergeはconcatenateのようにどの種類のシーケンスに対しても使用できます。 Be careful: sort and merge are allowed to destroy their arguments, so if the original sequences are important to you, make a copy with the copy-list or copy-seq function. 注意: sortとmergeは引数を破壊します。ですから、元のシーケンスが大事なも のである場合はcopy-listやcopy-seqを使ってシーケンスのコピーを引数に渡す ようにしましょう。 Equality ■等式 LISP has many different ideas of equality. Numerical equality is denoted by =. Two symbols are eq if and only if they are identical. Two copies of the same list are not eq, but they are equal. LISP処理系には意図の異なる等号がいくつもあります。数式の等号は=です。二 つのシンボルがまったく同一のときはeqです。同じリストの二つのコピーはeqで はありません。しかし、equalです。 > (eq 'a 'a) T > (eq 'a 'b) NIL > (= 3 4) T > (eq '(a b c) '(a b c)) NIL > (equal '(a b c) '(a b c)) T > (eql 'a 'a) T > (eql 3 3) T The eql predicate is equivalent to eq for symbols and to = for numbers. eqlの述語はシンボルに対してeqを使用し、数値に対して=を使用するのと等価で す。 The equal predicate is equivalent to eql for symbols and numbers. It is true for two conses if and only if their cars are equal and their cdrs are equal. It is true for two structures if and only if the structures are the same type and their corresponding fields are equal. equalの述語はシンボルや数値に対してはeqlを使用するのと等価です。さらに、 コンスセルを比較する場合、両者のcar部がequalでかつ両者のcdr部もequalなら ば真になります。また構造体を比較する場合は、両者の型が同じで、その対応す るフィールド同士がequalの時に真になります。 Some Useful List Functions ■便利なリスト関数 These functions all manipulate lists. これらの関数はすべてリストを処理します。 > (append '(1 2 3) '(4 5 6)) ;concatenate lists リストの結合 (1 2 3 4 5 6) > (reverse '(1 2 3)) ;reverse the elements of a list リストの要素の反転 (3 2 1) > (member 'a '(b d a c)) ;set membership -- returns the first tail 構成要素 -- 最初に見つかったものとそれ以降を返す (A C) ;whose car is the desired element そのcarが欲しい要素 > (find 'a '(b d a c)) ;another way to do set membership 構成要素を得るためのもうひとつの方法 A > (find '(a b) '((a d) (a d e) (a b d e) ()) :test #'subsetp) (A B D E) ;find is more flexible though ただし find はもっと融通が利く > (subsetp '(a b) '(a d e)) ;set containment 包含集合 NIL > (intersection '(a b c) '(b)) ;set intersection 共通集合 (B) > (union '(a) '(b)) ;set union 和集合 (A B) > (set-difference '(a b) '(a)) ;set difference 差集合 (B) Subsetp, intersection, union, and set-difference all assume that each argument contains no duplicate elements -- (subsetp '(a a) '(a b b)) is allowed to fail, for example. substepとintersectionとunion、そしてset-differenceはすべて、引数のリスト の要素に重複が無いことを仮定しています。-- 例えば、(subsetp '(a a) '(a b b)) では失敗してしまうでしょう。 Find, subsetp, intersection, union, and set-difference can all take a :test keyword argument; by default, they all use eql. findとsubsetpとintersectionとunion、そしてset-differenceはすべてキーワー ド引数 :test を受け付けます。デフォルトでは、それらはすべて eql で比較し ています。 Getting Started ■さあはじめよう You can use Emacs to edit LISP code: most Emacses are set up to enter LISP mode automatically when they find a file which ends in .lisp, but if yours isn't, you can type M-x lisp-mode. LISPコードを書くにはEmacsが便利です。たいていのEmacsは拡張子が「.lisp」 のファイルを開けば、自動的にLISPモードになります。もしそうならなくても、 「M-x lisp-mode」と入力してLISPモードにすることができます。 You can run LISP under Emacs, too: make sure that there is a command in your path called "lisp" which runs your favorite LISP. For example, you could type Emacsの中でLISP処理系を動かすこともできます。「lisp」とコマンドを打って、 お気に入りのLISP処理系が実行されるようにしましょう。例えば、以下のように 入力します。 ln -s /usr/misc/.allegro/bin/cl ~/bin/lisp Then in Emacs type M-x run-lisp. You can send LISP code to the LISP you just started, and do all sorts of other cool things; for more information, type C-h m from any buffer which is in LISP mode. それからEmacsで「M-x run-lisp」と入力します。するとLISP処理系が起動し、 その処理系にLISPコードを送って、いろいろとできるようになります。詳しい情 報はLISPモードのバッファで「C-h m」と入力してください。 Actually, you don't even need to make a link. Emacs has a variable called inferior-lisp-program; so if you add the line 実際は、シンボリックリンクを作る必要はありません。Emacsには 「inferior-lisp-program」という変数があります。 (setq inferior-lisp-program "/usr/misc/.allegro/bin/cl") to your .emacs file, Emacs will know where to find Allegro LISP when you type M-x run-lisp. という記述を.emacsファイルに書いておけばEmacsにはAllegro LISPがどこにあ るか分かります。 Allegro Common LISP has an online manual for use with Emacs. To use it, add the following to your .emacs file: Allegro Common LISPにはEmacsでコード書くときのためにオンラインマニュアル が用意されています。それを使用するには.emacsに以下の記述を追加します。 (setq load-path (cons "/afs/cs/misc/allegro/common/omega/emacs" load-path)) (autoload 'fi:clman "fi/clman" "Allegro Common LISP online manual." t) Then the command M-x fi:clman will prompt you for a LISP topic and print the appropriate documentation. M-x fi:clmanコマンドで望みの見出しを指示すれば、適切な文章が表示されます。