收藏 分享(赏)

人工智能人工神经网络及其语言AI&ANNProgramminginEmacsLisp.pdf

上传人:李静文 文档编号:9843 上传时间:2018-05-30 格式:PDF 页数:258 大小:1.05MB
下载 相关 举报
人工智能人工神经网络及其语言AI&ANNProgramminginEmacsLisp.pdf_第1页
第1页 / 共258页
人工智能人工神经网络及其语言AI&ANNProgramminginEmacsLisp.pdf_第2页
第2页 / 共258页
人工智能人工神经网络及其语言AI&ANNProgramminginEmacsLisp.pdf_第3页
第3页 / 共258页
人工智能人工神经网络及其语言AI&ANNProgramminginEmacsLisp.pdf_第4页
第4页 / 共258页
人工智能人工神经网络及其语言AI&ANNProgramminginEmacsLisp.pdf_第5页
第5页 / 共258页
点击查看更多>>
资源描述

1、Programming in Emacs LispAn IntroductionProgramming in Emacs LispAn IntroductionEdition 1.05, 21 October 1997by Robert J. ChassellCopyright c1990, 91, 92, 93, 94, 95, 97 Free Software Foundation, Inc.Published bytheFree Software Foundation, Inc.59 Temple Place, Suite 330Boston, MA 02111-1307 USAISBN

2、-1882114-41-8Permission is granted to make and distribute verbatim copies of this manual provided thecopyright notice and this permission notice are preserved on all copies.Permission is grantedtocopy and distribute modi ed versions ofthis manual under the con-ditions for verbatim copying, provided

3、that the entire resulting derived work is distributedunder the terms of a permission notice identical to this one.Permission is grantedtocopy and distribute translations of this manual into another lan-guage, under the above conditions for modi ed versions, except that this permission noticemay be s

4、tated in a translation approved by the Free Software Foundation.Preface ixPrefaceMost of the GNU Emacs text editor is written in the programming language calledEmacs Lisp. The code written in this programming language is the software|the sets ofinstructions|that tell the computer what to do when you

5、 give it commands. Emacs isdesigned so that you can write new code in Emacs Lisp and easily install it as an extensionto the editor. This is why Emacs is called the extensible editor“.(Indeed, since Emacs does so much more than provide editing capabilities, it should per-haps be called an extensible

6、 computing environment“, but thatphrase is quite a mouthful.Also, everything you do in Emacs| nd the Mayan date and phases of the moon, simplifypolynomials, debug code, manage les, read letters, write books|all these activities arekinds of editing in the most general sense of the word.)Although Emac

7、s Lisp is usually thought of in association with the text editor, it is afull computer programming language. You can use it as you would any other programminglanguage.Perhaps you want to understand programming; perhaps you want to extend Emacs; orperhaps you want to become a programmer. This introdu

8、ction to Emacs Lisp is designedto get you started: to guide you in learning the fundamentals of programming, and moreimportantly, to showyou howyou can teachyourself to go further.All through this document, you will see little sample programs you can run inside ofEmacs. If you read this document in

9、Info inside of GNU Emacs, you can run the programsas they appear. (This is easy to do and is explained when the examples are presented.)Alternatively,you can read this introduction as a printed book while sitting beside a com-puter running Emacs. (This is what I like to do; I like printed books.) If

10、 you dont havearunning Emacs beside you, you can still read this book, but in this case, it is best to treatit as a novel or as a travel guide to a country not yet visited: interesting, but not the sameas being there.Much of this introduction is dedicated to walk-throughs or guided tours of code use

11、d inGNU Emacs. These tours are designed for two purposes: rst, to giveyou familiaritywithreal, working code (code you use every day); and, second, to giveyou familiarity with theway Emacs works. It is interesting to see how an editor is implemented. Also, I hope thatyou will pick up the habit of bro

12、wsing through source code. You can learn from it and mineit for ideas. Having GNU Emacs is likehaving a dragons cave of treasures.In addition to learning about Emacs as an editor and Emacs Lisp as a programminglanguage, the examples and guided tours will giveyou an opportunity to get acquaintedwith

13、Emacs as a Lisp programming environment. GNU Emacs supports programming andprovides tools that you will want to become comfortable using, suchasM-. (the key whichinvokes the find-tag command). You will also learn about bu ers and other objects thatare part of the editing environment. Learning about

14、these features of Emacs is likelearningnew routes around your home town.Finally, I hope to convey some of the skills for using Emacs to learn aspects of program-ming that you dont know. You can often use Emacs to help you understand what puzzlesx Prefaceyou or to nd out how to do something new. This

15、 self-reliance is not only a pleasure, butan advantage.For Whom This is WrittenThis text is written as an elementary introduction for people who are not programmers.If you are a programmer, you may not be satis ed with this primer. The reason is that youmayhave become expert at reading reference man

16、uals and be put o by the way this textis organized.An expert programmer who reviewed this text said to me:I prefer to learn from reference manuals. I diveinto“ each paragraph, andcome up for air“ between paragraphs.When I get to the end of a paragraph, I assume that that subject is done,nished, that

17、 I knoweverything I need (with the possible exception of the casewhen the next paragraph starts talking about it in more detail). I expect thatawell written reference manual will not have a lot of redundancy, and that itwill have excellent pointers to the (one) place where the information I want is.

18、This introduction is not written for this person!Firstly,Itrytosayeverything at least three times: rst, to introduce it; second, to showit in context; and third, to show it in a di erentcontext, or to review it.Secondly, I hardly ever put all the information about a subject in one place, much lessin

19、 one paragraph. Tomyway of thinking, that imposes too heavy a burden on the reader.Instead I try to explain only what you need to know at the time. (Sometimes I include alittle extra information so you wont be surprised later when the additional information isformally introduced.)When you read this

20、text, you are not expected to learn everything the rst time. Fre-quently,you need only make, as it were, a nodding acquaintance with some of the itemsmentioned. My hope is that I have structured the text and given you enough hints thatyou will be alert to what is important, and concentrateonit.You w

21、ill need to diveinto“ some paragraphs; there is no other way to read them. ButIhave tried to keep down the number of such paragraphs. This book is intended as anapproachable hill, rather than as a daunting mountain.This introduction to Programming in Emacs Lisp has a companion document, The GNUEmacs

22、 Lisp Reference Manual. Thereferencemanualhasmoredetail thanthisintroduction.In the reference manual, all the information about one topic is concentrated in one place.You should turn to it if you are like the programmer quoted above. And, of course, afteryou have read this Introduction,you will nd t

23、he Reference Manual useful when you arewriting your own programs.Thank You xiLisp HistoryLisp was rst developed in the late 1950s at the Massachusetts Institute of Technologyfor research in arti cial intelligence. The greatpower of the Lisp language makes it superiorfor other purposes as well, such

24、as writing editor commands.GNU Emacs Lisp is largely inspired by Maclisp, whichwas written at MIT in the 1960s.It is somewhat inspired by Common Lisp, which became a standard in the 1980s. However,EmacsLisp is muchsimpler thanCommonLisp. (ThestandardEmacsdistribution containsan optional extensions l

25、e, cl.el, that adds many Common Lisp features to Emacs Lisp.)A Note for NovicesIf you dont know GNU Emacs, you can still read this document pro tably.However, Irecommend you learn Emacs, if only to learn to move around your computer screen. Youcan teachyourself how to use Emacs with the on-line tuto

26、rial. To use it, type C-h t.(Thismeans you press and release the hCTRLi key and the h at the same time, and then press andrelease t.)Also, I often refer to one of Emacss standard commands by listing the keys whichyoupress to invoke the command and then giving the name of the command in parentheses,

27、likethis: M-C- (indent-region). What this means is that the indent-region command iscustomarily invoked bytyping M-C-.(You can, if you wish, change the keys that are typedto invoke the command; this is called rebinding. See Section 16.11, Keymaps“, page 186.)The abbreviation M-C- means that you type

28、 your hMETAi key, hCTRLi key and hi key all atthe same time. Sometimes a combination like this is called a keychord, since it is similarto the wayyou playachord on a piano. If your keyboard does not haveahMETAi key, thehESCi key pre x is used in place of it. In this case, M-C- means that you press a

29、nd releaseyour hESCi key and then type the hCTRLi key and the hi key at the same time.If you are reading this in Info using GNU Emacs, you can read through this wholedocument just by pressing the space bar, hSPCi.(To learn about Info, type C-h i and thenselect Info.)A note on terminology: when I use

30、 the word Lisp alone, I am usually referring to thevarious dialects of Lisp in general, but when I speak of Emacs Lisp, I am referring to GNUEmacs Lisp in particular.Thank YouMythankstoall whohelped mewith thisbook. Myespecial thankstoJim Blandy, NoahFriedman,Jim Kingdon,RolandMcGrath,Frank Ritter,R

31、andy Smith,Richard M. Stallman,and Melissa Weisshaus. My thanks also go to both Philip Johnson and David Stampe fortheir patient encouragement. My mistakes are myown.Lisp Atoms 11 List ProcessingTo the untutored eye, Lisp is a strange programming language. In Lisp code there areparentheses everywher

32、e. Some people even claim that the name stands for Lots of IsolatedSilly Parentheses. But the claim is unwarranted. Lisp stands for LISt Processing and theprogramminglanguagehandles lists (andlistsoflists)byputtingthembetweenparentheses.The parentheses mark the boundaries of the list. Sometimes a li

33、st is preceded by a singleapostrophe or quotation mark, . Lists are the basis of Lisp.1.1 Lisp ListsIn Lisp, a list looks like this: (rose violet daisy buttercup). This list is precededby a single apostrophe. It could just as well be written as follows, which looks more likethe kind of list you are

34、likely to be familiar with:(rosevioletdaisybuttercup)The elements of this list are the names of the four di erent owers, separated from eachother by whitespace and surrounded by parentheses, like owers in a eld with a stone wallaround them.Lists can also havenumbers in them, as in this list: (+ 2 2)

35、. This list has a plus-sign,+, followed bytwo2s, each separated by whitespace.In Lisp, bothdataandprogramsarerepresentedthesameway;thatis, theyarebothlistsof words, numbers, or other lists, separated by whitespace and surrounded by parentheses.(Since a program looks like data, one program may easily

36、 serve as data for another; thisisavery powerful feature of Lisp.) (Incidentally, these two parenthetical remarks are notLisp lists, because they contain ; and . as punctuation marks.)Here is another list, this time with a list inside of it:(this list has (a list inside of it)The components of this

37、list are the words this, list, has, and the list (a listinside of it). The interior list is made up of the words a, list, inside, of, it.1.1.1 Lisp AtomsIn Lisp, what wehave been calling words are called atoms. This term comes from thehistorical meaning of the word atom, which means indivisible. As

38、far as Lisp is concerned,the words wehave been using in the lists cannot be divided into any smaller parts andstill mean the same thing as part of a program; likewise with numbers and single charactersymbols like+. On the other hand, unlike an atom, a list can be split into parts. (SeeChapter 7, car

39、 cdr ; but it has been found that physical atoms are not indivisible.Parts can split o an atom or it can ssion into two parts of roughly equal size. Physicalatoms were named prematurely, before their truer nature was found. In Lisp, certain kindsof atom, such as an array, can be separated into parts

40、; but the mechanism for doing thisis di erent from the mechanism for splitting a list. As far as list operations are concerned,the atoms of a list are unsplittable.As in English, the meanings of the component letters of a Lisp atom are di erent fromthe meaning the letters makeasaword. For example, t

41、he word for the South Americansloth, the ai, is completely di erent from the twowords, a, and i.There are many kinds of atom in nature but only a few in Lisp: for example, numbers,such as 37, 511, or 1729, and symbols, suchas+, foo, or forward-line. The wordswehave listed in the examples above are a

42、ll symbols. In everyday Lisp conversation, theword atom“ is not often used, because programmers usually try to be more speci c aboutwhat kind of atom they are dealing with. Lisp programming is mostly about symbols (andsometimes numbers) within lists. (Incidentally, the preceding three word parenthet

43、icalremark is a proper list in Lisp, since it consists of atoms, which in this case are symbols,separated by whitespace and enclosed by parentheses, without any non-Lisp punctuation.)In addition, text between double quotation marks|even sentences or paragraphs|is anatom. Here is an example:(this lis

44、t includes “text between quotation marks.“)In Lisp, all of the quoted text including the punctuation mark and the blank spaces is asingle atom. This kind of atom is called a string (for string of characters) and is the sortof thing that is used for messages that a computer can printforahuman to read. Stringsare a di erent kind of atom than numbers or symbols and are used di erently.1.1.2 Whitespace in ListsThe amount of whitespace in a list does not matter. From the point of view of the Lisplanguage,

展开阅读全文
相关资源
相关搜索
资源标签

当前位置:首页 > 网络技术 > 热门技术

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:文库网官方知乎号:文库网

经营许可证编号: 粤ICP备2021046453号世界地图

文库网官网©版权所有2025营业执照举报