From ctian at common-lisp.net Tue Aug 28 02:13:03 2007 From: ctian at common-lisp.net (ctian at common-lisp.net) Date: Mon, 27 Aug 2007 22:13:03 -0400 (EDT) Subject: [cl-net-snmp-cvs] r24 - in books: . onlisp Message-ID: <20070828021303.CBAFC7A011@common-lisp.net> Author: ctian Date: Mon Aug 27 22:13:01 2007 New Revision: 24 Added: books/ books/onlisp/ books/onlisp/0-preface.tex books/onlisp/1-the_extensible_language.tex books/onlisp/2-functions.tex books/onlisp/24-prolog.tex books/onlisp/3-functional_programming.tex books/onlisp/notes.tex books/onlisp/onlisp.kilepr books/onlisp/onlisp.tex books/onlisp/packages.tex Log: Add onlisp translate (zh_CN) Added: books/onlisp/0-preface.tex ============================================================================== --- (empty file) +++ books/onlisp/0-preface.tex Mon Aug 27 22:13:01 2007 @@ -0,0 +1,186 @@ +\chapter*{??} +\label{chap:preface} + +????????????? Lisp ?????. ?????????? Lisp, ?????????????. +??????????????. ????????????? Lisp ??????, ?????????????????. + +????????????????????, ? John Foderato ????????: + +\begin{quote} + Lisp ???????????. +\end{quote} + +?? Lisp ????????, ????????? Lisp ???, ???????? Lisp ??????????. +??????????????, ??? Lisp ????????????\footnote{???: + ????????, ??? + ``As well as writing their programs down toward the language, + experienced Lisp programmers build the language + up toward their programs.''}. + +?????????????????, ???? Lisp ??????. + +\section*{???????} +\label{sec:bottom-up_design} + +??????????, ?????????????????. ????????????????????????. +??????,??????????????. ????????????, ?????????????????????: +?????????????????, ???????????????. X Window ? \TeX +?????????????. + +?????????: ??? Lisp ????????????????????????, +????????????? Lisp ??????????. \textsl{? Lisp} ?????????. +????????????????, ????????????????????. ?? Lisp ?????, +???????????? Lisp ???????????????. + +?????????????????? Lisp ????. ????? Lisp ??????, ???? \textsl{? Lisp} +???????, ??????????. + +???????????????????????, ? Lisp ?????????????????. ? Lisp ?, +?????????????????????????????. ????????????????????. +Lisp ?????????????. ????????????? Lisp ?????, ?????????????????. +??????, Lisp ?????????, ??? Lisp ?????. ???????????? Lisp ??? Lisp ??. + +???? Lisp ?????????????????????. ???????????????? \textsl{?} +????. ?????????? Lisp ???????????????????. ??? Lisp +?????????????????????: ???????????, ??????????????????????. +?????????????????????. +???????????????????????????????????. + +????? Lisp ??????? Lisp ????????, ?????????. +??????????????????? Pascal ???????????????. +????????????????????: ??? \texttt{defun} ????????????, +?????????????????????????????????????????????????????. + +???????????????? Lisp ???????. ????????, ???, ???????????, +?????? Lisp ??? C ? Pascal ? Fortran ????. ?????????????. +??????????????? Lisp ????????????, ??????????????. + +????? Louis Armstrong ???????, ???? ``??????????, ????????.'' +????????????????: ???? \textsl{??} ???????. ???????????? Lisp +???---??????????????????????????. ?????????---?? Lisp ????--- +????????????????????. \textsl{On Lisp} ?????????? Lisp ?????. +????, ??????, ?????, ?????, ?????---???? Lisp ??????????. + +??, ?????, ????????????????????????????. ??????????????????. +?????????????????????????, ?????????????????. + +???????????????????????????????, ?????????? ``???'', +????????????????. ????, ??????? C ??????????, ??????? C +??? Lisp ???. ????, C ??????? Prolog---?????????????? +? 24 ??????? 180 ? Lisp ????. + +??????????? Lisp ???????, ????, ????? \textsl{??} Lisp ????. +??????????---???????????? ``????'' ????????. +?????????????????????. + +\section*{????} +\label{sec:plan_of_the_book} + +????? Lisp ?????, ??????????????. +? 2 ??? Lisp ??????????????????. +? 3 ?????????????, ?? Lisp ????????. +? 4 ??????????? Lisp. +? 5 ??????????????????????????????. +??, ? 6 ????????????????????. + +????, ???????. ??????????????????????, +???????????????????. ? 7--10 ?????????????. +??????????????? Lisp ???????????????: ??????; ????, ??, ??????; +????????????; ??????; ?????????????; ?????????? Lisp ??; +?????????????????????. + +???????, ? 11--18 ?????????????????????. ? 11 ?????????--- +???????, ?????????????. ? 12 ???????????????. ? 13 +??????????????????????????. ? 14 ???? anaphoric(????) ?, +?????????????. ? 15 ????????? 5 ????????????????????. +? 16 ????????????????? Lisp ?????. ? 17 ??????, ??? 18 ?, ???. + +? 19 ???????????, ???????. ? 19 ??????????, ????????????, +??????, ???????????, ???????.? 20 ??????? continuation ???? +Common Lisp ??, ??????????????????. Continuation ?????????, +????????????????. ?????????? Lisp ???????? 21 ? 22 ?. +?????????????????, ???????????????. ? 23 ? 24 ???????????, +?????????????: ?? 200 ????????? ATN ???, ??????? Prolog. + +??????????????????????. ???????????????, ?????? 200 ????????. +????, ???????, ???????????, ????????? Lisp ??. ? 23 ? 24 +????????????????? ATN ?????????? Prolog, ?????????, +????????? Lisp ???????????. ??????????????????????????: +Lisp ????????????????????????, ????????????? Lisp ??????????. + +??????????????????, ??? \textsc{CLOS}, Common Lisp ????. ???????????, +???????????, ???????????? Lisp ??????????. ????? \textsl{? Lisp ?} +???????????. + +??????????????? \pageref{chap:notes} ?. ???????????, ?????????, +??? Lisp ????????????. ??????????????????, ????\footnote{ + ???????, ??...}. ????????? (packages) ???, ?? \pageref{chap:packages} ?. + +?????????????????????????????, ??? Lisp +???????????????????? Lisp ??. ?????????????? Lisp ?????, +??????????????????. ?????, ?????????????????, ????????? +Lisp ??????????????. + +\section*{??} +\label{sec:examples} + +Lisp ??????. ?? Common Lisp ??????????, ??????????? Common Lisp ??. +??????? 1984 ????? Guy Steele ???????? \textsl{Common Lisp: the Language} +(\textsc{CLTL1}) ?. ????? 1990 ?????? (\textsc{CLTL2}) ?????????, +\textsc{CLTL2} ???????? \textsc{ANSI} ??. + +?????????, ?????????????? Prolog ??. ??????????, ???????????? +Common Lisp ???\footnote{???: ????????????????????? Common Lisp ?????, +??? SBCL, LispWorks ????????, ????????????????????.}. +??????????? \textsc{CLTL1} ?????????????????????????. + +?????????? \textsc{FTP} ? \texttt{endor.harvard.edu} ??, ? \texttt{pub/onlisp} +???. ????????? \texttt{onlisp at das.harvard.edu}. + +\section*{??} +\label{sec:acknowledgements} + +????, ?????? Robert Morris ???. ???????????????????. +?????????????, ????? \texttt{for} ??, ??? \texttt{aand} ??, ??? +\texttt{match}, ??????? \texttt{true-choose}, ??? 24.2 ?? Prolog ???. +???, ???? (???????) ?????????? Robert ?????. (???, rtm!) + +????? David Moon ?????, ?????????????????????????. ? 12 +??????????????, ???????????????????. + +??????? David Touretzky ? Skoma Brittain ????????. ???????????????????. +???????????????????????? David Touretzky ?????. + +??????????????????, ?? Tom Cheatham, Richard Draves (?? 1985 ??????? +\texttt{alambda} ? \texttt{propmacro}), John Foderaro, David Hendler, George Luger, Robert +Muller, Mark Nitzberg, ?? Guy Steele. + +??? Cheatham ????????, ??????????????. ??? Aiken ????????, ?? +Tony Hartman, Janusz Juda, Harry Bochner, ?? Joanne Klys. + +Prentice Hall ???????. ??? Alan Apt ???????????????????. ????? +Mona Pompili, Shirley Michaels, ?? Shirley McGuire ???????????. + +?? Bow and Arrow ????????? Gino Lee ?????. ????????????????. + +???? \LaTeX ??, ????? Leslie Lamport ? Donald Knuth ? \TeX ????????, +????? L. A. Carr, Van Jacobson ? Scott Stanton ????. ??? John Vlissides ? +Scott Stanton ??? Idraw ??. ???? L. Peter Deutsch ? Ghostscript ????, ? Tim Theisen +? Ghostview ???. Chiron Inc. ??? Gary Bisbee ??????. + +??????????, ?? Paul Becker, Phil Chapnick, Alice Hartley, Glenn Holloway, Meichun Hsu, +Krzysztof Lenk, Arman Maghbouleh, Howard Mullings, Nancy Parmet, Robert Penny, Gary Sabot, +Patrick Slaney, Steve Strassman, Dave Watkins, Weickers ??, ? Bill Woods. + +??, ????????, ?????????; ?? Jackie, ?????????????????????????. + +?????????????. ??????????, ???? Lisp, ????????????. ??????? +Lisp ?? Lisp. ???????, ????????????. + +\textsl{Paul Graham} + +%%% Local Variables: +%%% coding: utf-8 +%%% mode: latex +%%% TeX-master: nil +%%% End: Added: books/onlisp/1-the_extensible_language.tex ============================================================================== --- (empty file) +++ books/onlisp/1-the_extensible_language.tex Mon Aug 27 22:13:01 2007 @@ -0,0 +1,239 @@ +\chapter{?????} +\label{chap:the_extensible_language} + +??????? Lisp ?????, ???????``??????''. ???, Lisp ????????????????. +Lisp ? John McCarthy ??, ??? ``????'' ????????. ????????? Lisp ???, +????????? \textsc{AI} ??. ???? 1980 ?? \textsc{AI} ???????????, +?????????. + +????, ?? \textsc{AI} ?? Lisp ????????????. ???????????? Lisp ???????: +????? GNU Emacs, Unix ?????????; AutoCAD, ?????? \textsc{CAD} ??; ?? Interleaf, +?????????. Lisp ?????????? \textsc{AI} ????????. + +?? Lisp ???? \textsc{AI} ??, ?????? ???? Lisp ?????????????, +????????????. ??????? Lisp ????????????? +Lisp ?????????????????????????. Lisp ?????? Lisp ??, Lisp ?????????, +??? Lisp ?????. ??, ???????????????? Lisp ??????, +?????????????????????. + +\section{?????} +\label{sec:design_by_evolution} + +?? Lisp ????????????, ??????????????????. ????????????, ????? +Lisp ???????????????. ?????? CAD ??, ????? Lisp ??????? CAD ?????. +?????????????????, ??? Lisp ???????. ?????????, ??????, Lisp +????????? \textsl{?} ??????. + +???????????????? ?????????????????\footnote{?? 88:barbieQ +???????????, ???``To some ears that sentence has an odd ring to it.}. +??????????????: ?????????, (1) ???????????, (2) ????. +??????, ?? Lisp ??????????????????????, ???????????????. + +??, ???????. ?????????????????????????, ????????????????????. +???? ???????????????. ???????????????????????. +?????????????????????????????: ??????????? $30\%$ ????, +?????????????, ???????????? $30\%$ ???, ? \textsl{??} ????. + +??????????????, ???????, ???????. ?????????????? +??????????????????????, ???????, ????????????????????. +????????????. ???????????????????????????. ??????????: +???????????, ???????????. ??????????????????????????????, +??????????????????????????. +??????????????????????????????????. + +????????, ???????????????. ???????????????????? +?????????????????????????????. ???????????????, ??????????? +????, ???????. Lisp ??????????????. ? Lisp ?, ??????????. + +???????????? ? Montaigne ??????, ?????????????????. +?????????????????????, ???????????????. ??????????????: +????????????, ????????????????????, ?????????????????; +??????????, ??????????????. ?????????????????????--- +???????????????????????????--- +??????????????????????????????????. + +Lisp ????????????????. ??, Lisp ????????????. ????? Lisp ????, +???????????????????????????????????, +???????????????????????. + +\section{??????} +\label{sec:programming_bottom-up} + +?????????????????????????????. ???????????????????????, +???????????????????, ??????????????????. ??????????, ????, +?????. + +??????, ?????????????, ????????????????. ??????????? +??????? \textsl{??????}: ?? ``????????????, ?????????????????. +????????????, ???????????????????,'' ????. +????????????????????---??????????????????, +???????????????????. + +???? Lisp ????????????????????. ???????????, ???????? +\textsl{???????} ?????---???????????. ? Lisp ?, ?????????????, +?????????????. ???????????? ``??? Lisp ??????????.'' +????????????. ???????????????????????????, ????. ?????????. +???????????, ?????????????, ?????????????????, +??????????????????. ????????????????????????. +????????????????, ????????, ????????. + +??????, ??????????????????????????. ?????????????, +????????????????. ?????????????????????, ????????????, +?????????????. ???????????. + +???????, ??????? bookkeeping ???????, ?????????; ?????????, +????????????. ????????: + +\begin{enumerate} +\item + ???????????, ?????????????????. ???????????????????, + ????????????????????. ???????????????????, ?????????????. + ??????????????????????????, ?????? Lisp + ????????????????????????????. +\item + ??????????????. ???????????, ????????????????????????. + ?????????????, ??????????????? Lisp ????????????. +\item + ????????????????. ???????????????????????, + ??????????????????????????. +\item + ???????????????????????, ???????????????????. + ???????????????????????, ???????????????????????????????. +\end{enumerate} + +???????????? Lisp ????????????. ??????????, ????????????. +????, Lisp ????????????, ? Lisp ??????????????????????--- +?? Lisp ???????????, ??????????????. + +?????????????????????????. ????, ???????, ?????????????????. +? \textsl{The Mythical Man--Month} ???, Frederick Brooks +??????????????????????????. ?????????, ??????????????. +Lisp ??????????????????????: ?????????, ??????????????. +???????, ????, ?????????. ????????? Lisp ?????????, ???????????. + +\section{?????} +\label{sec:extensible_software} + +??????????, Lisp ??????????????.????????????????????????????% +????????. ???????????????????????????, ???????????????. +????????????????????????, ?????????????????????????. + +????????????????????. ??????????????: ?????. ?????????????, +?????????????. ?????????????????, ???????????????????. +??????????????????, ???????????????, +?????????????????, ??????????????. + +X Window ? \TeX ?????????????. ? 1980 ??, ?????????? Lisp +?????????????????. ??? GNU Emacs, ??? Unix ?????. ???? AutoCAD, +????? Lisp ???????????????. 1991 ? Interleaf ???????????, ????? +Lisp ??????, ?????????? Lisp ???. + +Lisp ???????????????????, ??????????????????. ???? Lisp +?????????????????????, ?????????????????????. ??? Lisp +???? Lisp ??, ????????????????, ??????????????????????. +?????????????????????????????, ???????????????????????% +??????????????. ? Lisp ?, ?????????????????. ?????????????% +???????????---????????? \textsl{??} ????????????. + +??????????????????????, ???????????????. ???????????????, +?????????????, ?????????. ????????????????? ???????? Lisp +???, ???????????: ???????????; ?????????; ????????????????. +????????????????????---???????????, ???????. +????????????????, ????????????????. + +????????????, ????????, ????????????????. ?????????????, +??????????. + +\section{?? Lisp} +\label{sec:extending_lisp} + +???????? Lisp ??????: ????. ? Lisp ?, ????????????????????. +??????????? \texttt{mapcar}, ??????????????? \texttt{mapcar} ??????. +??, ???????????? 1 ? 10 ?????????????????????, +???????????????? \texttt{mapcar}: + +\begin{verbatim} +(mapcar fn + (do* ((x 1 (1+ x)) + (result (list x) (push x result))) + ((= x 10) (nreverse result)))) +\end{verbatim} + +??????????????.\footnote{?????? Common Lisp ? series ?????????, +???????????, ??????? Lisp ?????} ????????????????? +\texttt{map1-n} (???), ??????????: + +\begin{verbatim} +(map1-n fn 10) +\end{verbatim} + +??????????????. ?????????, ?????????????????. ??????????. +???????, ??????????????????. + +????????, ??????????????. ??????????. ??????????????????, +???????????????. ???????????????, ?????????????????. +???????????????? \textsl{??} ??. ?????????? Lisp ??????. +???????????????????????????????????. ????????????????????. +????????????????, ???????? ? Lisp ?, ??????, +??????????????????????. + +??????????????, ?????????. ?????????????, ????????????????. +???????????????? a ? b ??? x. Lisp ??? \texttt{do} ?????????. +???????????????????????: + +\begin{verbatim} +(do ((x a (+ 1 x))) + ((> x b)) + (print x)) +\end{verbatim} + +????, ???????????: + +\begin{verbatim} +(for (x a b) + (print x)) +\end{verbatim} + +???????. ?????? (???) ?????? \texttt{for} ???????, ?????????????. +???????????????, ??? \texttt{for} ????????????????????. + +?????????? Lisp ?????????. ?????, ???? Lisp ???????????, +??????????. Lisp ????????????????????, ?????????????????, +???????????????????: ???????? Lisp ???. ?? Lisp ??????????????? +(?????? I/O) ?????, ???????????? (??????). ???????????? +\textsl{?????}. + +???????????????????. Common Lisp ???????. ??????, \textsc{CLOS}, +?????????. ???????????????. ???????????????????, +?????????? Lisp ??????. + +\section{??? (?????) ? Lisp} +\label{sec:why_lisp} + +???????????????????. ??????, Lisp ??????. ????????? (??) +???????? ???????????; ?????. ?????, Lisp ???????????. +???????????????---???????????, ?????, ????, ??????????, +???????????????, ???????---? Lisp ????????????????. +????????????? Lisp ???????. + +???????, ?????????. ????---?????, ????, ??????????--- +???????????????? Lisp ??????. ??????????????????????. + +????, Lisp ? Fortran ???????????????????. +?????????????????????????????????. Fortran +??????????????. Lisp ???????????. ?????????????????????. +Fortran ????????????; ? Lisp ???????????. ?????, +???????????????. Fortran ? Lisp ???????????????. Fortran ?????? +Algol, ? Lisp ????????????????????. + +??? Fortran ? Lisp ?????????????. ????????? ``??! (??????????????.)'' +???????, ??? ``??! (???????, ????????.)'' ????????????????????, +????????????????. ???????? Lisp ???. ???? Lisp ???????????? +1970 ????????????????????. ????? \textsl{???? Lisp?}, ?? +\textsl{??? Lisp?} + +%%% Local Variables: +%%% coding: utf-8 +%%% mode: latex +%%% TeX-master: nil +%%% End: Added: books/onlisp/2-functions.tex ============================================================================== --- (empty file) +++ books/onlisp/2-functions.tex Mon Aug 27 22:13:01 2007 @@ -0,0 +1,10 @@ +\chapter{??} +\label{chap:functions} + +??? Lisp ???????. ???? Lisp ?????. + +%%% Local Variables: +%%% coding: utf-8 +%%% mode: latex +%%% TeX-master: nil +%%% End: Added: books/onlisp/24-prolog.tex ============================================================================== --- (empty file) +++ books/onlisp/24-prolog.tex Mon Aug 27 22:13:01 2007 @@ -0,0 +1,8 @@ +\chapter{Prolog} +\label{chap:prolog} + +%%% Local Variables: +%%% coding: utf-8 +%%% mode: latex +%%% TeX-master: nil +%%% End: Added: books/onlisp/3-functional_programming.tex ============================================================================== --- (empty file) +++ books/onlisp/3-functional_programming.tex Mon Aug 27 22:13:01 2007 @@ -0,0 +1,8 @@ +\chapter{?????} +\label{chap:functional_programming} + +%%% Local Variables: +%%% coding: utf-8 +%%% mode: latex +%%% TeX-master: nil +%%% End: Added: books/onlisp/notes.tex ============================================================================== --- (empty file) +++ books/onlisp/notes.tex Mon Aug 27 22:13:01 2007 @@ -0,0 +1,8 @@ +\chapter*{Notes} +\label{chap:notes} + +%%% Local Variables: +%%% coding: utf-8 +%%% mode: latex +%%% TeX-master: nil +%%% End: Added: books/onlisp/onlisp.kilepr ============================================================================== --- (empty file) +++ books/onlisp/onlisp.kilepr Mon Aug 27 22:13:01 2007 @@ -0,0 +1,32 @@ +[General] +img_extIsRegExp=false +img_extensions=.eps .pdf .dvi .ps .fig .gif .jpg .jpeg .png +kileprversion=1 +kileversion=1.9.3 +lastDocument=onlisp.tex +masterDocument= +name=onlisp +pkg_extIsRegExp=false +pkg_extensions=.cls .sty .dtx +src_extIsRegExp=false +src_extensions=.tex .ltx .bib .mp + +[Tools] +MakeIndex= +QuickBuild= + +[item:onlisp.kilepr] +archive=true +column=148039600 +encoding= +highlight= +line=0 +open=false + +[item:onlisp.tex] +archive=true +column=35 +encoding=UTF-8 +highlight=LaTeX +line=11 +open=true Added: books/onlisp/onlisp.tex ============================================================================== --- (empty file) +++ books/onlisp/onlisp.tex Mon Aug 27 22:13:01 2007 @@ -0,0 +1,34 @@ +\documentclass[a4paper,10pt]{book} +\usepackage{CJK} +\usepackage{indentfirst} + +\begin{document} +\begin{CJK}{UTF8}{song} +\CJKindent + +\begin{titlepage} +\title{On Lisp\footnote{????: \texttt{http://www.paulgraham.com/onlisp.html}}} +\author{Paul Graham ? + \and Chun Tian (binghe) ?\footnote{\texttt{E-mail: binghe.lisp at gmail.com}}} +\end{titlepage} + +\maketitle +\include{0-preface} +\tableofcontents +\setcounter{page}{0} +\include{1-the_extensible_language} +\include{2-functions} +\include{3-functional_programming} +\include{24-prolog} + +\include{packages} +\include{notes} + +\end{CJK} +\end{document} + +%%% Local Variables: +%%% coding: utf-8 +%%% mode: latex +%%% TeX-master: t +%%% End: Added: books/onlisp/packages.tex ============================================================================== --- (empty file) +++ books/onlisp/packages.tex Mon Aug 27 22:13:01 2007 @@ -0,0 +1,8 @@ +\chapter*{Appendix: Packages} +\label{chap:packages} + +%%% Local Variables: +%%% coding: utf-8 +%%% mode: latex +%%% TeX-master: nil +%%% End: From ctian at common-lisp.net Tue Aug 28 13:06:48 2007 From: ctian at common-lisp.net (ctian at common-lisp.net) Date: Tue, 28 Aug 2007 09:06:48 -0400 (EDT) Subject: [cl-net-snmp-cvs] r25 - books/onlisp Message-ID: <20070828130648.051FE7A011@common-lisp.net> Author: ctian Date: Tue Aug 28 09:06:47 2007 New Revision: 25 Modified: books/onlisp/1-the_extensible_language.tex books/onlisp/2-functions.tex books/onlisp/onlisp.tex Log: begin to section 2.3 Modified: books/onlisp/1-the_extensible_language.tex ============================================================================== --- books/onlisp/1-the_extensible_language.tex (original) +++ books/onlisp/1-the_extensible_language.tex Tue Aug 28 09:06:47 2007 @@ -151,22 +151,18 @@ ??????????? \texttt{mapcar}, ??????????????? \texttt{mapcar} ??????. ??, ???????????? 1 ? 10 ?????????????????????, ???????????????? \texttt{mapcar}: - \begin{verbatim} (mapcar fn (do* ((x 1 (1+ x)) (result (list x) (push x result))) ((= x 10) (nreverse result)))) \end{verbatim} - ??????????????.\footnote{?????? Common Lisp ? series ?????????, ???????????, ??????? Lisp ?????} ????????????????? \texttt{map1-n} (???), ??????????: - \begin{verbatim} (map1-n fn 10) \end{verbatim} - ??????????????. ?????????, ?????????????????. ??????????. ???????, ??????????????????. @@ -180,20 +176,16 @@ ??????????????, ?????????. ?????????????, ????????????????. ???????????????? a ? b ??? x. Lisp ??? \texttt{do} ?????????. ???????????????????????: - \begin{verbatim} (do ((x a (+ 1 x))) ((> x b)) (print x)) \end{verbatim} - ????, ???????????: - \begin{verbatim} (for (x a b) (print x)) \end{verbatim} - ???????. ?????? (???) ?????? \texttt{for} ???????, ?????????????. ???????????????, ??? \texttt{for} ????????????????????. Modified: books/onlisp/2-functions.tex ============================================================================== --- books/onlisp/2-functions.tex (original) +++ books/onlisp/2-functions.tex Tue Aug 28 09:06:47 2007 @@ -1,7 +1,153 @@ \chapter{??} \label{chap:functions} -??? Lisp ???????. ???? Lisp ?????. +??? Lisp ???????. ???? Lisp ?????. ?????? \texttt{+} (??) +???????????????????. ? Lisp ???????, ????, ????????????????. +? Lisp ?, \texttt{+} ?????, ???????????????. + +???, ??????? \textsl{???? (special form)} ??????, ?? Lisp ??????????. +???????????????????? ?????: ???????? Lisp ?????, ??????????, +?????????????????????. + +??????????????. ???????????????? Lisp ?????, ????????????. +?????, ?????? Lisp ?????????, ???????????????????????????. +??????????????????????. ?????????????????????????, +???????????. + +\section{??????} +\label{sec:functions_as_data} + +???? Lisp ??????. ????????, Lisp ?????????. ??????????? Lisp +??????. ????????????????????? Lisp ??. + +Lisp ???????????????????. ?????????, ???, ??, ?????. +? Lisp ??????????????????: ??. ?????????????????????. +???? Lisp ??????????? ????? Lisp ????????????????????????, +??????: ???????????, ?????????????, ?????????????, +?????????????. + +????????????????????. ??????????????, +??????????????????????????????. ??? Lisp ??, +????????????????????. + +\section{????} +\label{sec:defining_functions} + +???????? \texttt{defun} ?????. ???????????? \texttt{double} ???, +???????????. +\begin{verbatim} +> (defun double (x) (* x 2)) +DOUBLE +\end{verbatim} +????????? Lisp, ?????????????? \texttt{double}, ??????(toplevel): +\begin{verbatim} +> (double 1) +2 +\end{verbatim} +?? Lisp ????????????????????, ????? C ?? Pascal ????????????. +???????????. ?? \texttt{defun} ????????, ???? Lisp ??. ?????? +\texttt{defun} ?????????, ???????????. + +????????. \texttt{defun} ????????????????, ??????????????????. +??????? \texttt{double} ?, ????????????????????. ?????????????? +\sq (??--???) ???. ???????????????????????. ??????? +\texttt{double} ?????: +\begin{verbatim} +> #'double +# +\end{verbatim} +???????????????????. ???????????? Lisp ????????\footnote{ +???: ????????????????? Lisp ???????. ??????? CMUCL (CMU Common Lisp) ??, ??????????? \texttt{>}, ???????????????, ??????. ?? CMUCL +?????????????? (???? LispWorks ?)}, Common Lisp ?????? (first-class) ??, +?????????????????????????. ??, ????????????????, ??????, +?????????, ????: +\begin{verbatim} +> (eq #'double (car (list #'double))) +T +\end{verbatim} + +???????? \texttt{defun} ?????. ????? Lisp ????, ?????????. +????????????, ??????????. ????????, ???????????????????. +????????, ?????????? \textsl{\lexpr(lambda-expression)} ???. +?? \lexpr ????????????: \texttt{lambda} ??, ????, +??????????????. ???? \lexpr ?????? \texttt{double} ?????: +\begin{verbatim} +(lambda (x) (* x 2)) +\end{verbatim} +????????, ?????? $x$, ???? $2x$. + +?? \lexpr ???????????????. ?? \texttt{double} ????????, ??? +``?????'', ?? \texttt{(lambda (x) (* x 2))} ???????????, ?? +``????????????????''. ???????--???? \lexpr ???, ???????????: +\begin{verbatim} +> #'(lambda (x) (* x 2)) +# +\end{verbatim} +????? \texttt{double} ?????, ???????????. + +??????, ????????, ?????: +\begin{verbatim} +> (double 3) +6 +\end{verbatim} +?? \lexpr ?????????, ???????????????: +\begin{verbatim} +> ((lambda (x) (* x 2)) 3) +6 +\end{verbatim} + +? Common Lisp ?, ????????? \texttt{double} ????????. +\begin{verbatim} +> (setq double 2) +2 +> (double double) +4 +\end{verbatim} +???????????????, ?????? \sq ???, ?????????. ?????????????. + +????? Common Lisp ?????????? \textsl{???? (name-space)}. ?????????? +\texttt{foo} ??????? \texttt{foo} ???, ???????. ??????????, +????????????????, ??? Common Lisp ??????????.\footnote{ +???: ??????????????? Lisp ?? Lisp--2, ???? Lisp--1 ?, +????????????????, ?????? Lisp ??? Scheme. ?? Lisp--1 VS Lisp--2 +?????????, ?????? Lisp--1 ???????????.} + +??????, Common Lisp ???????????????????????????. \texttt{symbol-value} +??????????, ?????????: +\begin{verbatim} +> (symbol-value 'double) +2 +\end{verbatim} +? \texttt{symbol-function} ??????????????: +\begin{verbatim} +> (symbol-function 'double) +# +\end{verbatim} +???, ???????????, ?????????????: +\begin{verbatim} +> (setq x #'append) +# +> (eq (symbol-value 'x) (symbol-function 'append)) +T +\end{verbatim} + +??????, \texttt{defun} ???????????? \texttt{symbol-function} +??????????????. ????????????????: +\begin{verbatim} +(defun double (x) (* x 2)) + +(setf (symbol-function 'double) + #'(lambda (x) (* x 2))) +\end{verbatim} +?? \texttt{defun} ?????????????????---??????????????. +??????????. ?????? \texttt{defun} ?????, ??????????????????. +????????????? \texttt{defun}, ????????????????: +?????????????????????, ??????????. +??????????????????? Lisp ???, ? \texttt{defun} +???????????????????????. + +\section{?????} +\label{sec:functional-arguments} %%% Local Variables: %%% coding: utf-8 Modified: books/onlisp/onlisp.tex ============================================================================== --- books/onlisp/onlisp.tex (original) +++ books/onlisp/onlisp.tex Tue Aug 28 09:06:47 2007 @@ -1,11 +1,15 @@ \documentclass[a4paper,10pt]{book} \usepackage{CJK} \usepackage{indentfirst} +\usepackage{amsmath} \begin{document} \begin{CJK}{UTF8}{song} \CJKindent +\newcommand{\lexpr}{$\lambda$--???} +\newcommand{\sq}{\texttt{\#'}} + \begin{titlepage} \title{On Lisp\footnote{????: \texttt{http://www.paulgraham.com/onlisp.html}}} \author{Paul Graham ? From ctian at common-lisp.net Tue Aug 28 14:33:27 2007 From: ctian at common-lisp.net (ctian at common-lisp.net) Date: Tue, 28 Aug 2007 10:33:27 -0400 (EDT) Subject: [cl-net-snmp-cvs] r26 - books/onlisp Message-ID: <20070828143327.4096F68101@common-lisp.net> Author: ctian Date: Tue Aug 28 10:33:26 2007 New Revision: 26 Modified: books/onlisp/0-preface.tex books/onlisp/1-the_extensible_language.tex Log: Take suggest from Huang Jianshi Modified: books/onlisp/0-preface.tex ============================================================================== --- books/onlisp/0-preface.tex (original) +++ books/onlisp/0-preface.tex Tue Aug 28 10:33:26 2007 @@ -17,26 +17,26 @@ experienced Lisp programmers build the language up toward their programs.''}. -?????????????????, ???? Lisp ??????. +?????????????????, ???? Lisp ??????. -\section*{???????} +\section*{???????} \label{sec:bottom-up_design} -??????????, ?????????????????. ????????????????????????. +??????????, ?????????????????. ????????????????????????. ??????,??????????????. ????????????, ?????????????????????: -?????????????????, ???????????????. X Window ? \TeX +?????????????????, ???????????????. X Window ? \TeX ?????????????. -?????????: ??? Lisp ????????????????????????, -????????????? Lisp ??????????. \textsl{? Lisp} ?????????. +?????????: ??? Lisp ????????????????????????, +????????????? Lisp ??????????. \textsl{? Lisp} ?????????. ????????????????, ????????????????????. ?? Lisp ?????, ???????????? Lisp ???????????????. ?????????????????? Lisp ????. ????? Lisp ??????, ???? \textsl{? Lisp} ???????, ??????????. -???????????????????????, ? Lisp ?????????????????. ? Lisp ?, -?????????????????????????????. ????????????????????. +???????????????????????, ? Lisp ?????????????????. ? Lisp ?, +?????????????????????????????. ????????????????????. Lisp ?????????????. ????????????? Lisp ?????, ?????????????????. ??????, Lisp ?????????, ??? Lisp ?????. ???????????? Lisp ??? Lisp ??. @@ -106,7 +106,7 @@ ????, ???????, ???????????, ????????? Lisp ??. ? 23 ? 24 ????????????????? ATN ?????????? Prolog, ?????????, ????????? Lisp ???????????. ??????????????????????????: -Lisp ????????????????????????, ????????????? Lisp ??????????. +Lisp ????????????????????????, ????????????? Lisp ??????????. ??????????????????, ??? \textsc{CLOS}, Common Lisp ????. ???????????, ???????????, ???????????? Lisp ??????????. ????? \textsl{? Lisp ?} Modified: books/onlisp/1-the_extensible_language.tex ============================================================================== --- books/onlisp/1-the_extensible_language.tex (original) +++ books/onlisp/1-the_extensible_language.tex Tue Aug 28 10:33:26 2007 @@ -56,7 +56,7 @@ ???????????????????????????????????, ???????????????????????. -\section{??????} +\section{??????} \label{sec:programming_bottom-up} ?????????????????????????????. ???????????????????????, @@ -70,14 +70,14 @@ ???????????????????. ???? Lisp ????????????????????. ???????????, ???????? -\textsl{???????} ?????---???????????. ? Lisp ?, ?????????????, +\textsl{???????} ?????---???????????. ? Lisp ?, ?????????????, ?????????????. ???????????? ``??? Lisp ??????????.'' ????????????. ???????????????????????????, ????. ?????????. ???????????, ?????????????, ?????????????????, ??????????????????. ????????????????????????. ????????????????, ????????, ????????. -??????, ??????????????????????????. ?????????????, +??????, ??????????????????????????. ?????????????, ????????????????. ?????????????????????, ????????????, ?????????????. ???????????. @@ -86,22 +86,22 @@ \begin{enumerate} \item - ???????????, ?????????????????. ???????????????????, + ???????????, ?????????????????. ???????????????????, ????????????????????. ???????????????????, ?????????????. ??????????????????????????, ?????? Lisp - ????????????????????????????. + ????????????????????????????. \item - ??????????????. ???????????, ????????????????????????. + ??????????????. ???????????, ????????????????????????. ?????????????, ??????????????? Lisp ????????????. \item - ????????????????. ???????????????????????, + ????????????????. ???????????????????????, ??????????????????????????. \item - ???????????????????????, ???????????????????. + ???????????????????????, ???????????????????. ???????????????????????, ???????????????????????????????. \end{enumerate} -???????????? Lisp ????????????. ??????????, ????????????. +???????????? Lisp ????????????. ??????????, ????????????. ????, Lisp ????????????, ? Lisp ??????????????????????--- ?? Lisp ???????????, ??????????????. @@ -118,7 +118,7 @@ ????????. ???????????????????????????, ???????????????. ????????????????????????, ?????????????????????????. -????????????????????. ??????????????: ?????. ?????????????, +????????????????????. ??????????????: ?????. ?????????????, ?????????????. ?????????????????, ???????????????????. ??????????????????, ???????????????, ?????????????????, ??????????????. @@ -195,7 +195,7 @@ (?????? I/O) ?????, ???????????? (??????). ???????????? \textsl{?????}. -???????????????????. Common Lisp ???????. ??????, \textsc{CLOS}, +???????????????????. Common Lisp ???????. ??????, \textsc{CLOS}, ?????????. ???????????????. ???????????????????, ?????????? Lisp ??????. From ctian at common-lisp.net Tue Aug 28 16:50:53 2007 From: ctian at common-lisp.net (ctian at common-lisp.net) Date: Tue, 28 Aug 2007 12:50:53 -0400 (EDT) Subject: [cl-net-snmp-cvs] r27 - books/onlisp Message-ID: <20070828165053.B95F62D171@common-lisp.net> Author: ctian Date: Tue Aug 28 12:50:50 2007 New Revision: 27 Modified: books/onlisp/2-functions.tex Log: more text Modified: books/onlisp/2-functions.tex ============================================================================== --- books/onlisp/2-functions.tex (original) +++ books/onlisp/2-functions.tex Tue Aug 28 12:50:50 2007 @@ -146,9 +146,136 @@ ??????????????????? Lisp ???, ? \texttt{defun} ???????????????????????. -\section{?????} +\section{??????} \label{sec:functional-arguments} +????????????, ???????, ?????????????. ??????? Lisp +?????????????. + +???????????????????????????. ? Lisp ?, ????? \texttt{apply}. ????, +?????????? \texttt{apply}: ???????????. ??????????????: +\begin{verbatim} +(+ 1 2) + +(apply #'+ '(1 2)) + +(apply (symbol-function '+) '(1 2)) + +(apply #'(lambda (x y) (+ x y)) '(1 2)) +\end{verbatim} +? Common Lisp ?, \texttt{apply} ???????????, ???????, ???????????? cons +????????????????. ????? +\begin{verbatim} +(apply #'+ 1 '(2)) +\end{verbatim} +????????. ??????????????, ?????? \texttt{funcall}, ?? \texttt{apply} +?????????. ??? +\begin{verbatim} +(funcall #'+ 1 2) +\end{verbatim} +???????????. + +????? Common Lisp ??????????. ?????????????. ?? \texttt{mapcar} +????????, ????????????? (?????????????), +?????????????????????????: +\begin{verbatim} +> (mapcar #'(lambda (x) (+ x 10)) + '(1 2 3)) +(11 12 13) +> (mapcar #'+ + '(1 2 3) + '(10 100 1000)) +(11 102 1003) +\end{verbatim} +Lisp ???????????????????????????????????. +????????????????????: ??????????????, ??????????. + +????????????????????????. ??????, ??????? \texttt{mapcar} +?????????????, ?????????????????????. +?????????????????????? 10, ????????????, ?? \texttt{plus\_ten} +???????, ?????????. ?? \lexpr, ???????????. + +Common Lisp ???????????????????????????????????. ????????, +??????? \texttt{mapcar}, ?? \texttt{sort} ? \texttt{remove-if} ?. ??????????. +????????????, ????????????????????????. +\begin{verbatim} +> (sort '(1 4 2 5 6 7 3) #'<) +(1 2 3 4 5 6 7) +\end{verbatim} +?? \texttt{sort} ????????????, ???? $<$ ?????????????, ????? $<$ +??????????, ??????. + +?? \texttt{remove-if} ?????? Common Lisp ???, ??????????????. ??????????, +???????????????????????. +\begin{verbatim} +> (remove-if #'evenp '(1 2 3 4 5 6 7)) +(1 3 5 7) +\end{verbatim} + +?????????????????, ?????? \texttt{remove-if} ?????: +\begin{verbatim} +(defun our-remove-if (fn lst) + (if (null lst) + nil + (if (funcall fn (car lst)) + (our-remove-if fn (cdr lst)) + (cons (car lst) (out-remove-if fn (cdr lst)))))) +\end{verbatim} +????????? \texttt{fn} ????? \sq. ??????????, ????????????????. +??????????. \sq ???????????????---???? \texttt{defun} ?????. + +??? 4 ????????, ??????????????????????????????. Common Lisp +???????????, ?????????????. ????????? \texttt{sort} ?????????, +??????. Instead of wiring in functionality, pass a functional argument. + +\section{??????} +\label{sec:functions_as_properties} + +???? Lisp ?????????????????????????????????. +????????????????????????????. ???????, ???????????? \texttt{case} +??, ?????? Lisp ??????: +\begin{verbatim} +(defun behave (animal) + (case animal + (dog (wag-tail) + (bark)) + (rat (scurry) + (squeak)) + (cat (rub-legs) + (scratch-carpet)))) +\end{verbatim} + +?????????????????? ?????????????, ??? \texttt{behave} +??????????????: +\begin{verbatim} +(defun behave (animal) + (funcall (get animal 'behavior))) +\end{verbatim} +??????????????????????, ??????????????????: +\begin{verbatim} +(setf (get 'dog 'behavior) + #'(lambda () + (wag-tail) + (bark))) +\end{verbatim} +?????, ??????????????????????????. ?????????. + +???????, ??????, ?????????. ?????. ?????????, +???????????????, ????????????????????. (? 2.9 ??????????.) +??????????, ????????????????????? \texttt{case} ?????????. + +?????????????????? \textsl{??} ??. ????, ??????????????, +??????????. ????????????, ????????????????. +? 25 ??????????????????. + +??????????????????????. ????? Lisp ???????, ????????????. +??????????????????????, ?????? Lisp ???. + +\section{???} +\label{sec:scope} + +Common Lisp ???????? (lexically scope) ? Lisp. Scheme ???????????; ? Scheme ?? + %%% Local Variables: %%% coding: utf-8 %%% mode: latex From ctian at common-lisp.net Wed Aug 29 10:57:10 2007 From: ctian at common-lisp.net (ctian at common-lisp.net) Date: Wed, 29 Aug 2007 06:57:10 -0400 (EDT) Subject: [cl-net-snmp-cvs] r28 - books/onlisp Message-ID: <20070829105710.6DAC72107D@common-lisp.net> Author: ctian Date: Wed Aug 29 06:57:08 2007 New Revision: 28 Modified: books/onlisp/2-functions.tex Log: more chap 2 Modified: books/onlisp/2-functions.tex ============================================================================== --- books/onlisp/2-functions.tex (original) +++ books/onlisp/2-functions.tex Wed Aug 29 06:57:08 2007 @@ -274,7 +274,246 @@ \section{???} \label{sec:scope} -Common Lisp ???????? (lexically scope) ? Lisp. Scheme ???????????; ? Scheme ?? +Common Lisp ???????? (lexically scope) ? Lisp. Scheme ???????????; ? Scheme ??, +????? (dynamic scope) ??? Lisp ??????????. + +??????????????????????????. ??????????????? (bound) ?, +??????????????, ???????, ?????? \texttt{let} ? \texttt{do} ??????????. +???????, ???? \textsl{??} ?. ?????????????: +\begin{verbatim} +(let ((y 7)) + (defun scope-test (x) + (list x y))) +\end{verbatim} +???????, x ?????, ? y ????. ???????????????????????. +??????????????---? \texttt{scope-test} ????, x ?????????????. +? y ????????? ????????????????. + +??????? Lisp ?, ????? \texttt{scope-test} ?????????, ?????????????. +??????? y ???????, ?? y ?????? \texttt{scope-test} ??????. ????????, +????? y ????. ??, ????????? Lisp ?, ?????? y ????????: +\begin{verbatim} +> (let ((y 5)) + (scope-test 3)) +(3 5) +\end{verbatim} +???????, ? \texttt{scope-test} ???? y ???? 7 ????????. ? \texttt{scope-test} +???? y ?????, ?? 5. + +??????? Lisp ?, ????????????????, ???????????? \textsl{??} ??????. +???????? Lisp ?, ?????????? \texttt{scope-test} ?????? y ???. +???????????? Common Lisp ?: +\begin{verbatim} +> (let ((y 5)) + (scope-test 3)) +(3 7) +\end{verbatim} +??? y ??? 5 ??????????????. + +??????????????? \textsl{special} ????????, ?????? Common Lisp ?????. +????, Lisp ?????????????????????. ???????????????????? bug. +????????????????????. ??????, ??????????????????. + +\section{??} +\label{sec:closures} + +?? Common Lisp ???????, ?????????????????, ?????????????????????. +????????????????\textsl{??}. ????????????. + +??? Common Lisp ???????????????????????. ???? \texttt{mapcar} +??????????? \sq ? \lexpr ?, ???????. ??, ??????????, +????????????????????. ?? \texttt{list+} ?? +\begin{verbatim} +(defun list+ (lst n) + (mapcar #'(lambda (x) (+ x n)) + lst)) +\end{verbatim} +????????: +\begin{verbatim} +> (list+ '(1 2 3) 10) +(11 12 13) +\end{verbatim} +???????? \texttt{list+} ??? \texttt{mapcar} ?????, ????????. ?? n ????, +???????????. ???????, ????????????????????.\footnote{ +???????, ?????????????---?? \texttt{mapcar} ????????? x.} + +??? Abelson ? Sussman ????? \textsl{Structure and Interpretation of Computer Programs} +?????????????. ????????????. ??????????????????: +\begin{verbatim} +(let ((counter 0)) + (defun new-id () (incf counter)) + (defun reset-id () (setq counter 0))) +\end{verbatim} +??????????????. ????????????, ????????? 0. +???????????????????, ???????????????????????. + +????????????????????. ???? \texttt{make-adder} ?? +\begin{verbatim} +(defun make-adder (n) + #'(lambda (x) (+ x n))) +\end{verbatim} +????????, ????????, ???????, ???????????????. +????????????????????: +\begin{verbatim} +> (setq add2 (make-adder 2) + add10 (make-adder 10)) +# +> (funcall add2 5) +7 +> (funcall add10 3) +13 +\end{verbatim} +? \texttt{make-adder} ????????, ?????????, ????????????????????????. +\begin{verbatim} +(defun make-adderb (n) + #'(lambda (x &optional change) + (if change + (setq n x) + (+ x n)))) +\end{verbatim} +?????? \texttt{make-adder} ????????, ??????????, ???????????. +\begin{verbatim} +> (setq addx (make-adderb 1)) +# +> (funcall addx 3) +4 +\end{verbatim} +????, ?????????????????????, ???? n ??????????????????: +\begin{verbatim} +> (funcall addx 100 t) +100 +> (funcall addx 3) +103 +\end{verbatim} + +????????????????????. ? \ref{fig:make-dbms} ???????????????. +???????? (\texttt{db}), ????????????, ????????????????. + +\begin{figure} +\begin{verbatim} +(defun make-dbms (db) + (list + #'(lambda (key) + (cdr (assoc key db))) + #'(lambda (key val) + (push (cons key val) db) + key) + #'(lambda (key) + (setf db (delete key db :key #'car)) + key))) +\end{verbatim} +\caption{\label{fig:make-dbms}??????????} +\end{figure} + +? \texttt{make-dbms} ?????????????---?????????????????. +\begin{verbatim} +> (setq cities (make-dbms '((boston . us) (paris . france)))) +(# + # + #) +\end{verbatim} +??????????????????, ?????????????---????????? \texttt{cities} +????????: +\begin{verbatim} +> (funcall (car cities) 'boston) +US +> (funcall (second cities) 'london 'england) +LONDON +> (funcall (car cities) 'london) +ENGLAND +\end{verbatim} +??????? \texttt{car} ??????. ??????, ????????????????. +???????????????---???????????????????: +\begin{verbatim} +(defun lookup (key db) + (funcall (car db) key)) +\end{verbatim} +????, ????????????????. + +??????????????????? \texttt{make-adder} ? \texttt{make-dbms} ????????. +????????????????????????????????????????? + +??? Lisp ???????????. ?? Lisp ??, ???????, ????????????????, +????????????????????, ??????????????????. +????????????????. ? 5 ???????????????, ??? 6 +???????????????????. + +\section{????} +\label{sec:local_functions} + +???? \lexpr ??????, ?????????? \texttt{defun} ???????: ??? \lexpr +???????????, ?????????????. ????? Common Lisp ??????? \texttt{lambda} +???????. + +???????????????????????, ?????????? Lisp ??: +\begin{verbatim} +> (mapcar #'(lambda (x) (+ 2 x)) + '(2 5 7 3)) +(4 7 9 5) +\end{verbatim} +?????????????????????? \texttt{mapcar} ?? ??????? \texttt{defun} ???, +???????????????: +\begin{verbatim} +> (mapcar #'copy-tree '((a b) (c d e))) +((A B) (C D E)) +\end{verbatim} +????????????????, ??? \texttt{mapcar} ????????????. ???? \texttt{list+} +???, +\begin{verbatim} +(defun list+ (lst n) + (mapcar #'(lambda (x) (+ x n)) + lst)) +\end{verbatim} +\texttt{mapcar} ??????, \texttt{\sq(lambda (x) (+ x n))}, ????? \texttt{list+} +???????? \texttt{n} ???. ?????????, ??????? \texttt{mapcar} +???????????? \textsl{??} ??????? ??????????????? \texttt{defun} +?????, ?????????????. ????????? \texttt{lambda} ?????????, +????????????????. + +Common Lisp ????? \texttt{labels} ?????????. ???????, \texttt{labels} +??????? \texttt{let}. \texttt{labels} ???????????????????: +\begin{verbatim} +( . ) +\end{verbatim} +? \texttt{labels} ????, \texttt{} ?????????????: +\begin{verbatim} +#'(lambda . ) +\end{verbatim} +??, +\begin{verbatim} +> (labels ((inc (x) (1+ x))) + (inc 3)) +> 4 +\end{verbatim} +????, ? \texttt{let} ? \texttt{labels} ?????????. ? \texttt{let} ????, +?????????????? \texttt{let} ?????????---???, ???? +\begin{verbatim} +(let ((x 10) (y x)) + y) +\end{verbatim} +???????? $y$ ??????? $x$ ???. ??, ? \texttt{labels} ?????? $f$ +???????????????????, ?? $f$ ??, ?????????????. + +?? \texttt{labels} ????????? \texttt{list+} ??????, ??? \texttt{mapcar} +???????????: +\begin{verbatim} +(defun count-instances (obj lsts) + (labels ((instances-in (lst) + (if (consp lst) + (+ (if (eq (car lst) obj) 1 0) + (instances-in (cdr lst))) + 0))) + (mapcar #'instances-in lsts))) +\end{verbatim} +??????????????, ???????????????(????)??????, ??????: +\begin{verbatim} +> (count-instances 'a '((a b c) (d a r p a) (d a r) (a a))) +(1 2 1 2) +\end{verbatim} + +\section{???} +\label{sec:tail-recursion} + %%% Local Variables: %%% coding: utf-8 From ctian at common-lisp.net Wed Aug 29 11:39:10 2007 From: ctian at common-lisp.net (ctian at common-lisp.net) Date: Wed, 29 Aug 2007 07:39:10 -0400 (EDT) Subject: [cl-net-snmp-cvs] r29 - books/onlisp Message-ID: <20070829113910.EC4CA3701B@common-lisp.net> Author: ctian Date: Wed Aug 29 07:39:10 2007 New Revision: 29 Modified: books/onlisp/0-preface.tex books/onlisp/onlisp.tex Log: Merge fix from Jianshi Huang, thanks. Modified: books/onlisp/0-preface.tex ============================================================================== --- books/onlisp/0-preface.tex (original) +++ books/onlisp/0-preface.tex Wed Aug 29 07:39:10 2007 @@ -4,31 +4,30 @@ ????????????? Lisp ?????. ?????????? Lisp, ?????????????. ??????????????. ????????????? Lisp ??????, ?????????????????. -????????????????????, ? John Foderato ????????: +????????????????????, ? John Foderato ???????????: \begin{quote} - Lisp ???????????. + Lisp ???????????. (Lisp is a programmable programming language.) \end{quote} -?? Lisp ????????, ????????? Lisp ???, ???????? Lisp ??????????. -??????????????, ??? Lisp ????????????\footnote{???: - ????????, ??? +?? Lisp ????????, ????????? Lisp ???, ???????? Lisp ??????????. +???????????????, ?? Lisp ?????????????????\footnote{???: ??? ``As well as writing their programs down toward the language, experienced Lisp programmers build the language up toward their programs.''}. ?????????????????, ???? Lisp ??????. -\section*{???????} +\section*{??????? (Bottom-up Design)} \label{sec:bottom-up_design} ??????????, ?????????????????. ????????????????????????. -??????,??????????????. ????????????, ?????????????????????: +??????,??????????????. ????????????, ?????????????????????: ?????????????????, ???????????????. X Window ? \TeX ?????????????. -?????????: ??? Lisp ????????????????????????, -????????????? Lisp ??????????. \textsl{? Lisp} ?????????. +?????????: ??? Lisp ??????????????????????, +??????????????? Lisp ??????????. \textsl{On Lisp} ?????????. ????????????????, ????????????????????. ?? Lisp ?????, ???????????? Lisp ???????????????. @@ -37,23 +36,24 @@ ???????????????????????, ? Lisp ?????????????????. ? Lisp ?, ?????????????????????????????. ????????????????????. -Lisp ?????????????. ????????????? Lisp ?????, ?????????????????. +Lisp ?????????????. ??????????? Lisp ?????, ?????????????????. ??????, Lisp ?????????, ??? Lisp ?????. ???????????? Lisp ??? Lisp ??. -???? Lisp ?????????????????????. ???????????????? \textsl{?} +???? Lisp ???????????????????. ???????????? \textsl{?} ????. ?????????? Lisp ???????????????????. ??? Lisp -?????????????????????: ???????????, ??????????????????????. +?????????????????????: ???????????, ?????????????????????. ?????????????????????. -???????????????????????????????????. +???????????????????????????????. ????? Lisp ??????? Lisp ????????, ?????????. -??????????????????? Pascal ???????????????. -????????????????????: ??? \texttt{defun} ????????????, -?????????????????????????????????????????????????????. - -???????????????? Lisp ???????. ????????, ???, ???????????, -?????? Lisp ??? C ? Pascal ? Fortran ????. ?????????????. -??????????????? Lisp ????????????, ??????????????. +???????????????????? Pascal ???????????. +??????????????, ????????: ?? \texttt{defun} ????????????, +????????????????????????: +???????????????????????????????. + +???????????????? Lisp ???????. ?????? Lisp ???, ???????????, +????????? Lisp ??? C ? Pascal ? Fortran ????. ???????????????. +????????? Lisp ??????????????, ??????????. ????? Louis Armstrong ???????, ???? ``??????????, ????????.'' ????????????????: ???? \textsl{??} ???????. ???????????? Lisp @@ -61,60 +61,60 @@ ????????????????????. \textsl{On Lisp} ?????????? Lisp ?????. ????, ??????, ?????, ?????, ?????---???? Lisp ??????????. -??, ?????, ????????????????????????????. ??????????????????. -?????????????????????????, ?????????????????. +??, ?????, ????????????????????????????. ??????????????????. +?????????????????????????, ???????????????. ???????????????????????????????, ?????????? ``???'', ????????????????. ????, ??????? C ??????????, ??????? C -??? Lisp ???. ????, C ??????? Prolog---?????????????? +??? Lisp ???. ????, C ?????? Prolog---?????????????? ? 24 ??????? 180 ? Lisp ????. -??????????? Lisp ???????, ????, ????? \textsl{??} Lisp ????. -??????????---???????????? ``????'' ????????. -?????????????????????. +????????? Lisp ?????????, ????, ????? \textsl{??} Lisp ????. +??????????---???????????? ``????'' ????????. +??????????????. \section*{????} \label{sec:plan_of_the_book} ????? Lisp ?????, ??????????????. -? 2 ??? Lisp ??????????????????. -? 3 ?????????????, ?? Lisp ????????. +? 2 ??? Lisp ???????????????????????. +??? 3 ?????????????, ?? Lisp ????????. ? 4 ??????????? Lisp. -? 5 ??????????????????????????????. +? 5 ????????????, ?????????. ??, ? 6 ????????????????????. -????, ???????. ??????????????????????, -???????????????????. ? 7--10 ?????????????. -??????????????? Lisp ???????????????: ??????; ????, ??, ??????; -????????????; ??????; ?????????????; ?????????? Lisp ??; -?????????????????????. +?????????????. ???????????, +??????????????????. ? 7--10 ??????????????. +????????????? Lisp ???????????????: ??????; ????, ??, ??????; +????????????????; ??????; ?????????????; ?????????? Lisp ??; +?????????????????????. -???????, ? 11--18 ?????????????????????. ? 11 ?????????--- -???????, ?????????????. ? 12 ???????????????. ? 13 +??, ? 11--18 ????????????????????. ? 11 ??????????--- +???????, ?????????????. ? 12 ???????????????. ? 13 ??????????????????????????. ? 14 ???? anaphoric(????) ?, ?????????????. ? 15 ????????? 5 ????????????????????. -? 16 ????????????????? Lisp ?????. ? 17 ??????, ??? 18 ?, ???. +? 16 ??????????????? Lisp ?????. ? 17 ??????, ??? 18 ?, ???. ? 19 ???????????, ???????. ? 19 ??????????, ????????????, -??????, ???????????, ???????.? 20 ??????? continuation ???? -Common Lisp ??, ??????????????????. Continuation ?????????, +??????, ???????????, ???????.? 20 ????????? (continuation) ???? +Common Lisp ??, ??????????????. ???????????, ????????????????. ?????????? Lisp ???????? 21 ? 22 ?. ?????????????????, ???????????????. ? 23 ? 24 ???????????, -?????????????: ?? 200 ????????? ATN ???, ??????? Prolog. +???????????: ????? ATN ???, ??????? Prolog, ??? 200 ???. -??????????????????????. ???????????????, ?????? 200 ????????. -????, ???????, ???????????, ????????? Lisp ??. ? 23 ? 24 +??????????????????. ???????????????, ?????? 200 ????????. +????, ?????????????????????, ???????? Lisp ???, ???????. ? 23 ? 24 ????????????????? ATN ?????????? Prolog, ?????????, -????????? Lisp ???????????. ??????????????????????????: -Lisp ????????????????????????, ????????????? Lisp ??????????. +????????? Lisp ???????????. ????????????????????????????: +Lisp ??????????????????????, ??????????????? Lisp ??????????. -??????????????????, ??? \textsc{CLOS}, Common Lisp ????. ???????????, -???????????, ???????????? Lisp ??????????. ????? \textsl{? Lisp ?} -???????????. - -??????????????? \pageref{chap:notes} ?. ???????????, ?????????, -??? Lisp ????????????. ??????????????????, ????\footnote{ - ???????, ??...}. ????????? (packages) ???, ?? \pageref{chap:packages} ?. +????????????????, ????? \textsc{CLOS}, Common Lisp ????. ???????????, +???????????, ????????????????? Lisp ??????. ???????? +\textsl{? Lisp ?} ?????. + +??????????? \pageref{chap:notes} ?. ???????????, ?????????, +????? Lisp ????????????. ??????????????????, ???? +\footnote{???????, ??...}. ????????? (packages) ???, ?? \pageref{chap:packages} ?. ?????????????????????????????, ??? Lisp ???????????????????? Lisp ??. ?????????????? Lisp ?????, @@ -132,10 +132,12 @@ ?????????, ?????????????? Prolog ??. ??????????, ???????????? Common Lisp ???\footnote{???: ????????????????????? Common Lisp ?????, ??? SBCL, LispWorks ????????, ????????????????????.}. -??????????? \textsc{CLTL1} ?????????????????????????. +?????????? \textsc{CLTL1} ????????????????????????. +??????????? Scheme ?????, ????????????. ?????????? \textsc{FTP} ? \texttt{endor.harvard.edu} ??, ? \texttt{pub/onlisp} -???. ????????? \texttt{onlisp at das.harvard.edu}. +???. ????????? \texttt{onlisp at das.harvard.edu}. ???????????? BBS +(\texttt{bbs.newsmth.net}) ? \texttt{FuncProgram} ?. \section*{??} \label{sec:acknowledgements} Modified: books/onlisp/onlisp.tex ============================================================================== --- books/onlisp/onlisp.tex (original) +++ books/onlisp/onlisp.tex Wed Aug 29 07:39:10 2007 @@ -11,9 +11,16 @@ \newcommand{\sq}{\texttt{\#'}} \begin{titlepage} -\title{On Lisp\footnote{????: \texttt{http://www.paulgraham.com/onlisp.html}}} -\author{Paul Graham ? - \and Chun Tian (binghe) ?\footnote{\texttt{E-mail: binghe.lisp at gmail.com}}} +\title{On Lisp\thanks{????: \texttt{http://www.paulgraham.com/onlisp.html}}} +\author{Paul Graham [?] + \and Chun Tian (binghe) [?] + \thanks{E-mail: \texttt{binghe.lisp at gmail.com}}\\ + NetEase.com, Inc.\\ + ????? + \and Jianshi Huang [?] + \thanks{E-mail: \texttt{jianshi.huang at gmail.com}}\\ + ?????? ??????\\ + ?????} \end{titlepage} \maketitle From ctian at common-lisp.net Thu Aug 30 13:34:36 2007 From: ctian at common-lisp.net (ctian at common-lisp.net) Date: Thu, 30 Aug 2007 09:34:36 -0400 (EDT) Subject: [cl-net-snmp-cvs] r30 - books/onlisp Message-ID: <20070830133436.CD840111D9@common-lisp.net> Author: ctian Date: Thu Aug 30 09:34:36 2007 New Revision: 30 Added: books/onlisp/7-macros.tex Modified: books/onlisp/2-functions.tex books/onlisp/3-functional_programming.tex books/onlisp/onlisp.tex Log: finish chap 2, start chap 3 Modified: books/onlisp/2-functions.tex ============================================================================== --- books/onlisp/2-functions.tex (original) +++ books/onlisp/2-functions.tex Thu Aug 30 09:34:36 2007 @@ -352,7 +352,7 @@ (defun make-adder (n) #'(lambda (x) (+ x n))) \end{verbatim} -????????, ????????, ???????, ???????????????. +\label{fun:make-adder} ????????, ????????, ???????, ???????????????. ????????????????????: \begin{verbatim} > (setq add2 (make-adder 2) @@ -514,6 +514,168 @@ \section{???} \label{sec:tail-recursion} +??????????. ????????????, ???????\textsl{??? (tail-recursive)}. +???????????? +\begin{verbatim} +(defun our-length (lst) + (if (null lst) + 0 + (1+ (out-length (cdr lst))))) +\end{verbatim} +????????????????????? \texttt{1+}. ????????????? +\begin{verbatim} +(defun out-find-if (fn lst) + (if (funcall fn (car lst)) + (car lst) + (our-find-if fn (cdr lst)))) +\end{verbatim} +??????????????????. + +?????????, ???? Common Lisp ???????????????. ???????, +??????????????????????????????????. + +?????????????????????? \textsl{???} ?????, ??????????. +???????, ???????????????????. ?? \texttt{our-length} ????? +\begin{verbatim} +(defun our-length (lst) + (labels ((rec (lst acc) + (if (null lst) + acc + (rec (cdr lst) (1+ acc))))) + (rec lst 0))) +\end{verbatim} +???, ???????????????????? \texttt{acc} ???. ??????????, \texttt{acc} +????????, ????????. ?????????????????, ????????????, ?????? +\texttt{rec} ????. + +?? Common Lisp ???????????, ???????????. ????????????, ?????? +\begin{verbatim} +(proclaim '(optimize speed)) +\end{verbatim} +????????, ???????????????. + +??????????, ??? Common Lisp ??????????????????, ???? C. Richard Gabriel +??????????, ???? 1 ?? \texttt{n}: +\begin{verbatim} +(defun triangle (n) + (labels ((tri (c n) + (declare (type fixnum n c)) + (if (zerop n) + c + (tri (the fixnum (+ n c)) + (the fixnum (- n 1)))))) + (tri 0 n))) +\end{verbatim} +?????? Common Lisp ????????. ?????????????????. +???????????????????????, ????????, ?????????????. + +\section{??} +\label{sec:compilation} + +Lisp ???????????????. ?????? toplevel ????? \texttt{defun} ???. +\begin{verbatim} +> (defun foo (x) (1+ x)) +FOO +\end{verbatim} +?????????????. ????? \texttt{compiled-function-p} ?????????????: +\begin{verbatim} +> (compiled-function-p #'foo) +NIL +\end{verbatim} +?????????????? \texttt{compile} ??? \texttt{foo} +\begin{verbatim} +> (compile 'foo) +FOO +\end{verbatim} +?????? \texttt{foo} ????????????????????. +\begin{verbatim} +> (compiled-function-p #'foo) +T +\end{verbatim} +????????? Lisp ??, ?????????, ?? \texttt{compiled-function-p} ???. +????????????: \texttt{compile} ??????????????, ???????? \texttt{nil}, +????????????? \lexpr. +\begin{verbatim} +> (compile nil '(lambda (x) (+ x 2))) +# +\end{verbatim} +??????????????, \texttt{compile} ???????? \texttt{defun} ?: +\begin{verbatim} +> (progn (compile 'bar '(lambda (x) (* x 3))) + (compiled-function-p #'bar)) +T +\end{verbatim} + +? \texttt{compile} ?????????????????????????. ????, ???? \texttt{compile} +???????, ??? \texttt{eval} ????????.\footnote{???????????? \texttt{eval} +???????.} ?? \ref{sec:functions_as_data} ????????????????????, ??????? +\texttt{make-adder} ???????????, ??????????? \texttt{compile} ??????. ?? +\texttt{compile} ????????---????????. ???????????. ?????? Lisp +????????? (????????????), ??????????. + +?????????????? \texttt{compile}. ?? \textsc{CLTL2} (? 667 ?), ??????? +``?????????????????'' ??. ????, ? toplevel ???????? \texttt{let} ? +\texttt{foo} +\begin{verbatim} +> (let ((y 2)) + (defun foo (x) (+ x y))) +\end{verbatim} +?? \texttt{(compile 'foo)} ?????????.\footnote{??????????????????. +????????????????????????, ?????????????????????????.} +?????????????????? \texttt{compile}, \textsc{CLTL2} ????? ``???????''. + +???? Lisp ?????????? \texttt{compile} ???????, ???? \texttt{compile-file} +??????. ????????????????????????---????????????????????. +???????????, ???????????? \texttt{compiled-function-p} ?????. + +???????????????????: ??????????????, ??????????, +?????????????. \textsc{CLTL2} ??????????, ???????????. + +?????????????, ??????????????. ? \texttt{make-adder} +(? \pageref{fun:make-adder} ?) ????, ????????????: +\begin{verbatim} +> (compile 'make-adder) +MAKE-ADDER +> (compiled-function-p (make-adder 2)) +T +\end{verbatim} +?????????, ???????????????????. ????????????????, +??????????????, ????????????---???????????????. +(?????????????) + +?????????????, ??????????????. ?????????????????????????. +???????????: +\begin{verbatim} +(defun 50th (lst) (nth 49 lst)) +\end{verbatim} +??????: +\begin{verbatim} +(proclaim '(inline 50th)) +\end{verbatim} +???????????? \texttt{50th} ?????????????????. ??????????????? +\texttt{50th} ???, +\begin{verbatim} +(defun foo (lst) + (+ (50th lst) 1)) +\end{verbatim} +??? \texttt{foo} ????, \texttt{50th} ????????????. ???????????? +\begin{verbatim} +(defun foo (lst) + (+ (nth 49 lst) 1)) +\end{verbatim} +??. ????????????? \texttt{50th} ??, ??????? \texttt{foo}, ??????????. +??????????????? (?? \ref{sec:dependence_on_macros} ?). + +\section{???????} +\label{functions_from_lists} + +?????? Lisp ???, ??????????. ?????????????????????? Lisp ?????. +? Common Lisp ?, ?????????---??????????????. ????????????????, +???????????. + +???? Lisp ????? Lisp ??????????, ??????????????. ?????? Lisp +?????????????????????????. ?? \texttt{?} ???? Lisp ?????. +??????????????????? Lisp ?????????. %%% Local Variables: %%% coding: utf-8 Modified: books/onlisp/3-functional_programming.tex ============================================================================== --- books/onlisp/3-functional_programming.tex (original) +++ books/onlisp/3-functional_programming.tex Thu Aug 30 09:34:36 2007 @@ -1,6 +1,18 @@ \chapter{?????} \label{chap:functional_programming} +?????? Lisp ? Lisp ???????????????: ??. ?????????, +??????????????????, ???????????. + +????? Lisp ??????????. ???????????????????????????. +???????????????, ??? Lisp ???????: +????????????????????????. + +\section{?????} +\label{sec:functional_design} + + + %%% Local Variables: %%% coding: utf-8 %%% mode: latex Added: books/onlisp/7-macros.tex ============================================================================== --- (empty file) +++ books/onlisp/7-macros.tex Thu Aug 30 09:34:36 2007 @@ -0,0 +1,11 @@ +\chapter{Macros} +\label{chap:macros} + +\section{??????} +\label{sec:dependence_on_macros} + +%%% Local Variables: +%%% coding: utf-8 +%%% mode: latex +%%% TeX-master: nil +%%% End: Modified: books/onlisp/onlisp.tex ============================================================================== --- books/onlisp/onlisp.tex (original) +++ books/onlisp/onlisp.tex Thu Aug 30 09:34:36 2007 @@ -12,12 +12,12 @@ \begin{titlepage} \title{On Lisp\thanks{????: \texttt{http://www.paulgraham.com/onlisp.html}}} -\author{Paul Graham [?] - \and Chun Tian (binghe) [?] +\author{Paul Graham [??] + \and Chun Tian (binghe) [??] \thanks{E-mail: \texttt{binghe.lisp at gmail.com}}\\ NetEase.com, Inc.\\ ????? - \and Jianshi Huang [?] + \and Jianshi Huang [??] \thanks{E-mail: \texttt{jianshi.huang at gmail.com}}\\ ?????? ??????\\ ?????} @@ -30,6 +30,7 @@ \include{1-the_extensible_language} \include{2-functions} \include{3-functional_programming} +\include{7-macros} \include{24-prolog} \include{packages}