on lisp

428 266 0
on lisp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Written by a Lisp expert, this is the most comprehensive tutorial on the advanced features of Lisp for experienced programmers. It shows how to program in the bottom-up style that is ideal for Lisp programming, and includes a unique, practical collection of Lisp programming techniques that shows how to take advantage of the language''s design for efficient programming in a wide variety of applications.

[...]... Arguments 13 Functions as Properties 15 Scope 16 Closures 17 Local Functions 21 Tail-Recursion 22 Compilation 24 Functions from Lists 27 6 Functions as Representation 76 6.1 6.2 6.3 3 Functional Programming 28 3.1 3.2 3.3 3.4 Common Lisp Evolves 61 Orthogonality 63 Memoizing 65 Composing Functions 66 Recursion on Cdrs 68 Recursion on Subtrees 70 When to Build Functions 75 Functional Design 28 Imperative... application until the two fit one another perfectly This book is about how to achieve a good fit between language and application Since everything we do toward this end ultimately depends on functions, functions are the natural place to begin 2.1 Functions as Data Two things make Lisp functions different One, mentioned above, is that Lisp itself is a collection of functions This means that we can add to Lisp. .. different from user-defined functions But Lisp has a single model, function application, to describe all the computation done by a program The Lisp + operator is a function, just like the ones you can define yourself In fact, except for a small number of operators called special forms, the core of Lisp is a collection of Lisp functions What’s to stop you from adding to this collection? Nothing at all: if you... Number of Evaluations 133 Order of Evaluation 135 Non-functional Expanders 136 Recursion 139 14 Anaphoric Macros 189 14.1 14.2 14.3 Anaphoric Variants 189 Failure 195 Referential Transparency 198 15 Macros Returning Functions 201 15.1 15.2 15.3 15.4 Building Functions 201 Recursion on Cdrs 204 Recursion on Subtrees 208 Lazy Evaluation 211 16 Macro-Defining Macros 213 16.1 16.2 16.3 Abbreviations 213 Properties... 238 xiii CONTENTS 19 A Query Compiler 246 19.1 19.2 19.3 19.4 19.5 The Database 247 Pattern-Matching Queries 248 A Query Interpreter 250 Restrictions on Binding 252 A Query Compiler 254 20 Continuations 258 20.1 20.2 20.3 Scheme Continuations 258 Continuation-Passing Macros 266 Code-Walkers and CPS Conversion 272 21 Multiple Processes 275 21.1 21.2 21.3 The Process Abstraction Implementation 277 The... tail-recursion and type declarations, existing Common Lisp compilers can generate code that runs as fast as, or faster than, C Richard Gabriel gives as ◦ an example the following function, which returns the sum of the integers from 1 to n: 2 The declaration (optimize speed) ought to be an abbreviation for (optimize (speed 3)) However, one Common Lisp implementation does tail-recursion optimization with... We don’t need defun to make functions, and functions don’t have to be 2.3 FUNCTIONAL ARGUMENTS 13 stored away as the value of some symbol Underlying defun, which resembles procedure definition in any other language, is a more general mechanism: building a function and associating it with a certain name are two separate operations When we don’t need the full generality of Lisp s notion of a function,... If it is inconvenient to give the arguments as a list, we can use funcall, which differs from apply only in this respect This expression (funcall #’+ 1 2) has the same effect as those above Many built-in Common Lisp functions take functional arguments Among the most frequently used are the mapping functions For example, mapcar takes two or more arguments, a function and one or more lists (one for each... through the functions which are components of cities: > (funcall (car cities) ’boston) US > (funcall (second cities) ’london ’england) LONDON > (funcall (car cities) ’london) ENGLAND Calling the car of a list is a bit ugly In real programs, the access functions might instead be entries in a structure Using them could also be cleaner—databases could be reached indirectly via functions like: (defun lookup... traditional data structures 2.7 LOCAL FUNCTIONS 21 2.7 Local Functions When we define functions with lambda-expressions, we face a restriction which doesn’t arise with defun: a function defined in a lambda-expression doesn’t have a name and therefore has no way of referring to itself This means that in Common Lisp we can’t use lambda to define a recursive function ◦ If we want to apply some function to

Ngày đăng: 13/06/2014, 16:04

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan