Service Manuals, User Guides, Schematic Diagrams or docs for : honeywell multics CJ52-00_Emacs_Extension_Writers'_Guide_Jan80

<< Back | Home

Most service manuals and schematics are PDF files, so You will need Adobre Acrobat Reader to view : Acrobat Download Some of the files are DjVu format. Readers and resources available here : DjVu Resources
For the compressed files, most common are zip and rar. Please, extract files with Your favorite compression software ( WinZip, WinRAR ... ) before viewing. If a document has multiple parts, You should download all, before extracting.
Good luck. Repair on Your own risk. Make sure You know what You are doing.




Image preview - the first page of the document
CJ52-00_Emacs_Extension_Writers


>> Download CJ52-00_Emacs_Extension_Writers'_Guide_Jan80 documenatation <<

Text preview - extract from the document
                                                         SERIES 60 (LEVEL.68)
                                                 MULTICS
                           EMACS EXTENSION WRITERS GUIDE




     SUBJECT
          Guide for Programmers Writing Extensions and 'Ibrminal Control Modules
          (CTL) in the LISP Programming Language for the Emacs %xt Editor


     SPECIAL INSTRUCTIONS
          This manual presupposes thorough familiarity with the Emacs text editor,
          which is described in the E m s lkzt Editor Users' Guide. Extensions and CTLs
          can be written by those without programming experience, but familiarity with
          some programming language is valuable. Experience with Lisp is useful, but
          not necessary.


     SOFTWARE SUPPORTED
..        Multics Software Release 8.0




     ORDER NUMBER
          CJ52-00                                                        January 1980



                                                                 Honeywell
                                                                                                                       I
                                                PREFACE
                                                                                                                       i
         T h i s manual d e s c r i b e s how t o w r i t e u s e r e x t e n s i o n s t o t h e
M u l t i c s Emacs e d i t o r . The r e a d e r should be t h o r o u g h l y f a m i l i a r
w i t h t h e Emacs e d i t o r , p r o f i c i e n t i n i t s u s e , and a c q u a i n t e d w i t h
i t s visible organization.                   The Emacs Text E d i t o r U s e r s 1 Guide,
Order No.           CH27, p r o v i d e s t h i s n e c e s s a r y i n f o r m a t i o n .      The
methods f o r w r i t i n g t e r m i n a l c-ontrol modules ( C T L s ) t o s u p p o r t
additional terminal types a r e a l s o described here.

          Programming knowledge i s not n e c e s s a r y t o w r i t e e x t e n s i o n s
s u c c e s s f u l l y , although i t i s h e l p f u l .                  Section 1 is a s h o r t
introduction t o extension writing. Section 2 provides a s h o r t
c o u r s e i n L i s p , t h e programming language used f o r w r i t i n g
e x t e n s i o n s , and t h e language i n which t h e Emacs e d i t o r i t s e l f i s
written.             B a s i c a l l y , t h e e x t e n s i o n w r i t e r o n l y needs t o l e a r n
enough about L i s p t o be a b l e t o i m i t a t e examples.
                                                                                                               1
        . S e c t i o n 3 shows, b y example, how t o w r i t e e x t e n s i o n s . It
i n c l u d e s t h e f u n c t i o n s and forms most l i k e l y t o be needed b y t h e
e x t e n s i o n w r i t e r . S e c t i o n 4 d e s c r i b e s LDEBUG.mode, t h e Emacs
mode f o r debugging t h e L i s p code used i n e x t e n s i o n s . F i n a l l y ,
S e c t i o n 5 d e m o n s t r a t e s how t o w r i t e a CTL t o s u p p o r t a new
t e r m i n a l t y p e . Again, t h e CTL w r i t e r u s e s e x i s t i n g C T L s t o l e a r n
t o w r i t e h i s own.

          T h i s manual c o n t a i n s s u f f i c i e n t i n f o r m a t i o n t o e f f e c t i v e l y
w r i t e and debug M u l t i c s Emacs e x t e n s i o n s . However, i t i s not
i n t e n d e d t o be a r e f e r e n c e document f o r e i t h e r L i s p , i n g e n e r a l ,
o r M u l t i c s MacLisp.             Reference documentation f o r MacLisp i s
a v a i l a b l e from:                                                                                            I


        M I T I n f o r m a t i o n P r o c e s s i n g Center
        Publications Office
        60 Vassar S t r e e t
        Cambridge, MA 02139




 @    Honeywell I n f o r m a t i o n Systems I n c . , 1980                         F i l e No.:     1L13
                             CONTENTS

                                                             Page
Section 1   Introduction .   . . . . . . . . . . . . . .     1-1
Section 2   An Introduction to Lisp  . . . . . . . . .
               Predicates . . . . . . . . . . . . .   .
                  Predicates for Numbers . . . . . .  .
                  Predicates for Strings . . . . . .  .
                  Predicates for Any Objects .....
               Lisp Special Forms  . . . . . . . . . .
                  The if Special Form  . . . . . . . .
                  The setq special Form . . . . . .   .
                  The do-forever and stop-doing
                   Special Forms ...........
                  The let Special Form . . . . . . .  .
                  The prog and go Special Forms   . . .
                  The or And and Special Forms. And
                   not ................
                  The progn and prog2 Special Forms   .
               Symbols .........         : . . . . .  .
               LispLists    ..............
Section 3   Writing Emacs Extensions . . . . . . . . .
               Using Emacs Requests in Extension
                Coding . . . . . . . . . . . . . . . .
               Marks and Their Management . . . . . .
                  The set.mark.  release-mark and
                   wipe-point-mark Functions . . . . .
                  The with-mark Special Form . . . . .
                  The save-excursion Special Form . .
               Cleanup Handlers . . . . . . . . . . .
                  The unwind-protect Special Form . .
               Useful Predicates . . . . . . . . . . .
               Whitespace Management . . . . . . . . .
               Extracting Text From the Buffer . . . .
               Talking to the User . . . . . . . . .    .
                  Message Printing Functions . . . .    .
               Variables . . . . . . . . . . . . . .    .
                     Example o f Local Variables . .    .
               Registered Variables     . . . . . . . . ..
               Large Scale Output . . . . . . . . . .
               Manipulating Buffers . . . . . . . .     .
                  Creating a Temporary Buffer . . .     .
                  Variable for Buffer Manipulation    . .
                  The save-excursion-buffer Special

                                iii
                            CONTENTS ( c o n t )

                                                                                       Page

                        Form. .      .   ..  .    . . . . . . . . .
                C a l l i n g t h e Redisplay     . . . . . . . . .
                EISTables     .      .   ..  .    . . . . . . . . .
                     F u n c t i o n s Using t h e C h a r s c a n T a b l e .
                Options   . . .      .   ..  .    .   .   .   .   .   .   .   .   .
                Name Scope I s s u e s    .  .    .   .   .   .   .   .   .   .   .
                Modes   . . . .      .   ..  .    .   .   .   .   .   .   .   .   .
                     Major Modes         ..  .    .   .   .   .   .   .   .   .   .
                     Minor Modes         ..  .    .   .
                                               . . . . . .                        .
                Character Dispatching             .   .
                                               . . . . . .                        .
                Program Development       .       .   .
                                               . . . . . .                        .
                     Coding Problems      .       .   .
                                               . . . . . .                        .
                Compilation       . . . . .       .   .
                                               . . . . . .                        .
                Documenting R e q u e s t s       .   .
                                                . . . . .                         .
                Window Management       . .       .   .
                                               . . . . . .                         .
                Writing Searches        . .       .   .
                                               . . . . . .                        .
                                               . . . . . .
                C a l l i n g M u l t i c s Commands                              .
                Multics Error Table       .       .   .
                                               . . . . . .                        .
                                                   . . . .
                D e f i n i n g R e q u e s t s w i t h defcom                    .
Section 4   Ldebug Mode        . . . . . . . . . . . . . .                        .
               LDEBUG B u f f e r s      . . . . . . . . . .                  .   .
               Emacs and L i s p Debug Mode        . . . . .                  .   .
                                                       . . .
               E r r o r T r a p E n t r i e s t o LDEBUG                     .   .
               Code B r e a k p o i n t s  . . . . . . . . .                  .   .
                                                       . . .
               F u n c t i o n T r a c i n g w i t h LDEBUG                   .   .
Section 5   W r i t i n g Emacs T e r m i n a l C o n t r o l Modules
             (CTLs)     . . . . . . . . . . . . . . . .
Index
                                                     SECTION 1

                                                  INTRODUCTION



                An e d i t o r e x t e n s i o n i s a u s e r - p r o v i d e d c a p a b i l i t y , w h i c h i s
      a d d e d t o t h e e d i t o r t o e x t e n d i t s Dower. I t i s d i f f e r e n t f r o m a
      macro, which is s i m p l y ~ l e c t i o ' n o f e d i t o r r e q u e s t s g a t h e r e d
      u p a n d ( p e r h a p s ) g i v e n a name. E x t e n s i o n s a r e p r o g r a m s ; t h e y a r e
      w r i t t e n i n t h e l a n g u a g e o f t h e M u l t i c s Emacs e n v i r o n m e n t . An
                                         - -
      extension is                a body o f c o d e              t h a t augments t h e e d i t o r ' s
      c a p a b i l i t y , b u t d o e s n o t embed o r r e q u i r e k n o w l e d g e o f how d a t a
      i n t h e e d i t o r is s t o r e d o r manipulated.                     In t h i s sense, a l l of
      t h e word, s e n t e n c e , p a r a g r a p h , and L i s p - l i s t          r e q u e s t s , and t h e
      v a r i o u s llmodesll ( e . g . , PL/I mode) a r e e x t e n s i o n s .

           T h e p e r s o n who w i s h e s t         o    a d d t o h i s Emacs e n v i r o n m e n t a n y
      powerful o r          sophisticated               c a p a b i l i t y must        l e a r n t o write
      extensions.          The keyboard                macro f a c i l i t y X             ,    "X))  is n o t
      intended f o r such usage.                       T h i s m a n u a l e x p l a i n s how t o w r i t e
      extensions.

                One o f t h e g u i d i n g d e s i g n p r i n c i p l e s i n t h e Emacs e d i t o r w a s
      t h a t t h e c r e a t i o n o f e d i t o r e x t e n s i o n s , e i t h e r by t h e e d i t o r
      implementors o r end u s e r s , s h o u l d be i n a programming l a n g u a g e o f
      e s t a b l i s h e d e l e g a n c e and power. L i s p was t h e l a n g u a g e c h o s e n .
      T h i s p r i m e r g i v e s you a s t a r t i n g p o i n t f o r w r i t i n g L i s p c o d e t o
      r u n a s e d i t o r e x t e n s i o n s i n t h e Emacs e n v i r o n m e n t .    If y o u h a v e
      some knowledge o f L i s p a l r e a d y , i t w i l l b e o f v a l u e .           However, i t
      is assumed i n t h i s manual t h a t t h e r e a d e r h a s no f a m i l i a r i t y w i t h
      L i s p , b u t d o e s , p e r h a p s , w i t h P L / I o r BASIC.

                For examples o f e x t e n s i o n c o d i n g , t h e e x t e n s i o n writer's
      u l t i m a t e r e f e r e n c e m a t e r i a l w i l l b e t h e Emacs s o u r c e . T h e Emacs
      m a i l s y s t e m (RMAIL), FORTRAN a n d P L / I m o d e s , a n d t h e c o d e f o r t h e
      word, s e n t e n c e , and paragraph r e q u e s t s ( a l o n g w i t h most o f t h e
      o t h e r c o d e i n t h e Emacs m o d u l e e m a c o p s . l i s p ) a r e s t a n d a r d
      examples o f e x t e n s i o n code. Techniques, s z y l e s , and s u b t l e t i e s
      d i f f i c u l t t o c o n v e y i n p r i n t may b e g l e a n e d b y c a r e f u l s t u d y o f
(-.   t h i s code.
                                                         SECTION 2

                                             AN 1,NTRODUCTION TO L I S P




                   L i s p programs a r e b u i l t o f f u n c t i o n s , which a r e s i m i l a r t o
         p r o c e d u r e s o r s u b r o u t i n e s i n o t h e r l a n g u a g e s , a l t h o u g h more a k i n
         t o PL/I           a n d ALGOL f u n c t i o n s . You w r i t e a L i s p p r o g r a m b y
         c r e a t i n g a f i l e f u l l o f f u n c t i o n d e f i n i t i o n s . - A- f u n c t i o h
         d e f i n i t i o n s p e c i f i e s t h e name o f a f u n c t i o n , a n d w h a t i t d o e s .
         Here i s a s a m p l e f u n c t i o n d e f i n i t i o n :
                  (defun addandmult ( a b c )                                 ; T h i s i s a comment
                         (* (- a b)
                            (+ a b c ) ) )

         T h i s d e f i n e s a f u n c t i o n named a d d a n d m u l t t h a t t a k e s t h r e e
         a r g u m e n t s , c a l l e d a , b , a n d c . The a d d a n d m u l t f u n c t i o n c o m p u t e s
         t h e r e s u l t o f m u l t i p l y i n g t h e d i f f e r e n c e o f a a n d b b y t h e sum o f
         a , b , a n d c , a n d r e t u r n s t h a t number a s a r e s u l t , o r v a l u e . T h e
         s e m i c o l o n on t h e f i r s t l i n e a b o v e b e g i n s a comment; comments
         t h r o u g h o u t t h e e x a m p l e s p r o v i d e some a d d i t i o n a l i n f o r m a t i o n a b o u t
         t h e code.

                 Here i s a n o t h e r f u n c t i o n d e f i n i t i o n :
                  (defun squareprint (arg)
                         ( p r i n t "The s q u a r e o f w )
                         (print arg)
                         ( p r i n t ltisU)
                         (print (* arg arg))
                         5

                  T h i s f u n c t i o n p r i n t s t h e message nThe s q u a r e o f 1 ? , p r i n t s t h e
         v a l u e o f i t s a r g u m e n t , p r i n t s t h e word l l i s f l , a n d p r i n t s t h e v a l u e
         o f t h e s q u a r e o f its argument.                I n a d d i t i o n , it r e t u r n s t h e value
         5.       The f u n c t i o n l 1 s q u a r e p r i n t l 1 h a s s i d e e f f e c t s :      it c a u s e s
         o u t p u t on t h e t e r m i n a l . It a l s o r e t u r n s a v a l u e , t h e number 5 .
         N o t e t h a t a l l L i s p f u n c t i o n s produ.ce a v a l u e ; o n l y some p r o d u c e
     .   side e f f e c t s .       The f i r s t f u n c t i o n d e f i n e d r e t u r n s t h e p r o d u c t o f
(-       t h o s e numbers a s a v a l u e ; t h e second r e t u r n s 5.
       If y o u l o o k a t s q u a r e p r i n t ,     you see t h a t it c o n s i s t s o f
several statements, the "print statements" t h a t p r i n t things.
These s t a t e m e n t s a r e c a l l e d f o r m s , and t h e y a r e , i n f a c t , c a l l s
t o other functions, in t h i s case the builtin print function.                                In
t h e form:
        ( p r i n t "The s q u a r e o f n )
t h e s t r i n g "The s q u a r e o f r f i s b e i n g p a s s e d a s a n a r g u m e n t t o t h e
p r i n t f u n c t i o n . Like a l l f u n c t i o n s , p r i n t r e t u r n s a v a l u e , which
is n o t used i n t h i s c a s e .          The s i d e effect o f p r i n t i n g s o m e t h i n g
d o e s o c c u r . I n t h e form:


y o u a r e i n v o k i n g t h e lf+" f u n c t i o n , w h i c h i s a l s o b u i l t i n . T h e
v a l u e s o f t h e p a r a m e t e r v a r i a b l e s a , b , and c a r e p a s s e d t o it a s
a r g u m e n t s . I t r e t u r n s a v a l u e , which i s t h e r e q u e s t e d sum, and
produces no s i d e effects.

    There a r e               five      forms       in      the      function-definition                 for
sauare~rint:
        (print      "The s q u a r e o f r f )
        (print      arg)
        (print      ffisff)
        (print      (* arg arg))
        5

           Forms i m m e d i a t e l y i n s i d e a f u n c t i o n d e f i n i t i o n a r e e x e c u t e d
s e q u e n t i a l l y , l i k e s t a t e m e n t s i n o t h e r programming l a n g u a g e s .
T h e v a l u e p r o d u c e d by t h e l a s t f o r m i s t h e o n e t h e f u n c t i o n
i t s e l f r e t u r n s . What d o e s i t mean t o " e x e c u t e t ' a 5 ? E x e c u t e i s
n o t e x a c t l y t h e r i g h t term; w h a t r e a l l y h a p p e n s i s t h a t t h e s e
f o r m s a r e e v a l u a t e d . T h i s means t h a t a v a l u e i s produced from
t h e m . E v a l u a t i n g a 5 p r o d u c e s t h e number 5 ; e v a l u a t i n g t h e f o r m :


c a l l s t h e If+" f u n c t i o n w i t h . t h e a p p r o p r i a t e a r g u m e n t s , a n d
p r o d u c e s w h a t e v e r v a l u e t h e "+If f u n c t i o n r e t u r n s .  The v a l u e
p r o d u c e d by t h e f f p r i n t t l f u n c t i o n i s s o m e t h i n g t h a t is n o t
i n t e r e s t i n g , b u t a value is produced.


      Numbers, l i k e 5 , and s t r i n g s , l i k e "The s q u a r e o f t f , a r e s a i d
t o evaluate t o themselves.       Things between p a r e n t h e s e s , l i k e :
        (+   a b c)
        ( p r i n t "The s q u a r e o f f 1 )
a r e c a l l s t o f u n c t i o n s , w h i c h a r e e v a l u a t e d by c a l l i n g t h e
f u n c t i o n i n d i c a t e d , and producing t h e v a l u e it r e t u r n s .
                  Function c a l l s have t h e syntax:

(--             (FUNCTIONNAME ARGFORMl ARGFORM2 ARGFORM3                           ...   ARGFORMn)
          w h e r e FUNCTIONNAME i s t h e name o f t h e f u n c t i o n t o c a l l and t h e
          ARGFORMs a r e t h e m s e l v e s f o r m s , w h i c h a r e e v a l u a t e d t o p r o d u c e t h e
          arguments t o g i v e t o t h e function.                           Thus, t o e v a l u a t e ( i . e . ,
          t t e x e c u t e l l and f i n d t h e v a l u e r e t u r n e d ) a form l i k e :




                          e v a l u a t e t h e i n n e r form ( * a b ) t o produce a v a l u e
                          e v a l u a t e t h e 15 t o p r o d u c e 1 5 ( r e m e m b e r ,    numbers and
                          s t r i n g s evaluate t o themselves)
                          e v a l u a t e t h e v a r i a b l e c t o produce its value
                          p a s s t h e s e t h r e e y a l u e s on     t o the             function,        and
                          r e t u r n what i t r e t u r n s .
          The n e w l i n e s a r e i g n o r e d .

(1'' ,j        T h u s , f o r m s a r e e i t h e r n u m b e r s l i k e 5 , s t r i n g s l i k e " i s t t,
          variables l i k e b, or function c a l l s l i k e (* a b).

                    V a r i a b l e s a r e much l i k e v a r i a b l e s i n o t h e r l a n g u a g e s .      A
          v a r i a b l e h a s a v a l u e , which i s c a l l e d i t s b i n d i n g .                At this
          s t a g e , a s s u m e t h a t t h i s v a l u e m u s t b e a s t r i n g o r a number. When
          a f u n c t i o n i s i n v o k e d , t h e p a r a m e t e r v a r i a b l e s ( l i k e a , b , and c
          above) o f t h e function acquire t h e arguments of t h e function c a l l
          a s bindings.               Evaluating a v a r i a b l e produces its binding a s a
          v a l u e . F o r i n s t a n c e , i f s o m e p l a c e i n a f u n c t i o n you e v a l u a t e t h e
          form:
                  (addandmult 2           (+   3 2) 6 )
          a , b , and c w i l l h a v e t h e b i n d i n g s 2 , 5 , and 6 w h i l e t h e f o r m s i n
          t h e d e f i n i t i o n o f addandmult a r e b e i n g e v a l u a t e d .         This is not
          u n l i k e t h e s u b r o u t i n e p a r a m e t e r mechanism i n o t h e r l a n g u a g e s . It
          i s d i f f e r e n t i n s o f a r a s i t s p e c i f i e s what v a l u e a v a r i a b l e h a s
          during "subroutinet1 execution.                          I n P L / I o r FORTRAN, a p a r a m e t e r
          is a s s o c i a t e d with a v a r i a b l e i n t h e c a l l i n g program, n o t a
          value, during subroutine execution.

                    There a r e parameter v a r i a b l e s , a s used above, temporary
(     I   v a r i a b l e s , d e s c r i b e d b e l o w , and g l o b a l v a r i a b l e s . Regardless of
          t h e k i n d o f v a r i a b l e , t h e y a l l - have b i n d i n g s ( v a l u e s ) , and
          evaluation of t h e v a r i a b l e produces t h a t value.
                                                                                                                I
       To summarize:                                                                                            1

       1.      L i s p programs a r e b u i l t o f f u n c t i o n s .                                   1 1
                                                                                                          -
       2.      F u n c t i o n d e f i n i t i o n s c o n s i s t o f t h e word n d e f u n n , t h e         I

               f u n c t i o n ' s name, a p a r a m e t e r l i s t , and a number o f                         I


               f o r m s , which a r e t o be s e q u e n t i a l l y e v a l u a t e d a t
               f u n c t i o n c a l l time, w i t h a p a i r of p a r e n t h e s e s around
               t h e whole t h i n g .                                                                          i
                                                                                                                I
       3.      The v a l u e o f t h e l a s t form i n a            function is t h e value                  . I
               r e t u r n e d by t h a t f u n c t i o n .                                                     I



       4.      Forms can be s t r i n g s , numbers, v a r i a b l e s , o r c a l l s t o
               functions.    Forms a r e e v a l u a t e d t o p r o d u c e v a l u e s ,
               which a r e p a s s e d between f u n c t i o n s a s a r g u m e n t s and
               results.
       5.      S t r i n g s and numbers e v a l u a t e t o t h e m s e l v e s .
       6.      V a r i a b l e s e v a l u a t e t o t h e datum t o which t h e y a r e
               bound, w h i c h , f o r a p a r a m e t e r , i s t h e c o r r e s p o n d i n g
               argument t o t h e c o n t a i n i n g f u n c t i o n .
       7.      F u n c t i o n c a l l s c o n t a i n t h e name o f a f u n c t i o n t o c a l l                 I

               and f o r m s t h a t a r e e v a l u a t e d t o p r o d u c e t h e a r g u m e n t s
               t o the function.                   F u n c t i o n c a l l s may p r o d u c e s i d e
               effects.            L i k e any f o r m , when a f u n c t i o n c a l l i s
                                                                                                                    I
               e v a l u a t e d , it produces a value.
                                                                                                                    i

PREDICATES
          Programming l a n g u a g e s need c o n d i t i o n a l e x e c u t i o n . I n o r d e r
t o c o n t r o l c o n d i t i o n a l e x e c u t i o n , you need t h i n g s upon which t o
base a decision.                Two d a t a o b j e c t s i n t h e L i s p world c o r r e s p o n d
t o t r u t h and f a l s i t y , f o r t h e p u r p o s e s of p a r t s o f t h e L i s p
s y s t e m t h a t d e a l w i t h c o n d i t i o n s . A s e t of f u n c t i o n s c a l l e d
predicates return these objects a s values.                                  For i n s t a n c e , a
function called                     invoked a s :


r e t u r n s t h e i n d i c a t o r o f f a l s i t y , and when invoked a s :


r e t u r n s t h e i n d i c a t o r of t r u t h . P r e d i c a t e s work j u s t l i k e o t h e r
b u i l t i n and         nonbuiltin functions, l i k e                   p r i n t , addandrnult,
s q u a r e p r i n t , and +. They t a k e a r g u m e n t s , and p r o d u c e a r e s u l t .
I n t h e c a s e o f p r e d i c a t e s . , however, t h e r e s u l t i s n o t a s t r i n g o r
a number, b u t an i n d i c a t i o n of t r u t h o r f a l s i t y . The r e s u l t o f a
p r e d i c a t e can be used b y t h e i f s p e c i a l form ( s e e below) t o                         ]
c o n t r o l t h e execution of a f u n c t i o n .
               The f o l l o w i n g a r e some o f t h e m o s t u s e f u l L i s p p r e d i c a t e s .
      I n a l l o f t h e s e e x a m p l e s , A l , A2, S 1 , 0 1 , e t c . , s t a n d f o r f o r m s ,
(.-   w h i c h means t h e y c a n b e 1 2 , ( + 6 q ) , (myfun 33 ( - a b ) ) , e t c .
      "A1      i s a n u m b e r , " b e l o w , means t h a t A1 i s some f o r m w h i c h
      e v a l u a t e s t o a n u m b e r , s u c h a s 3 , ( + 6 2 1 , o r x 4 9 , i f ~ 4 9 ' sv a l u e
      i s i n d e e d a number.

      P r e d i c a t e s f o r Numbers
              A 1 a n d A2 a r e n u m b e r s :
         predicate            Example          R e t u r n s TRUTH i f    ...,   otherwise f a l s i t y .

              -
              -               (=   A1 A2)             A1 and A2 a r e t h e same n u m b e r .
              >               (>   A1 A2)             A1 i s a b i g g e r number t h a n A2.
              <               (<   A1 A2)             A 1 i s a s m a l l e r number t h a n A2.


      Predicates - Strings
                 for
              S1 a n d S 2 a r e s t r i n g s :
              samepnamep
              (samepnamep S1 S 2 )
                   S1 and        S2 a r e s t r i n g s of i d e n t i c a l c o n t e n t , i . e . , t h e
                   "same s t r i n g 1 ! . T h i s i s t h e s t a n d a r d way t o see i f t w o
                   s t r i n g s a r e t h e s a m e , a s i n (sarnepnamep t e s t " - h o l d f f )
              alphalessp
              ( a l p h a l e s s p S1 S 2 )
                       $1 c o l l a t e s b e f o r e S 2 a l p h a b e t i c a l l y , e . g . ,
                        ( a l p h a l e s s p "Ablef1 llBakerfl) r e t u r n s t r u t h , b u t
                        ( a l p h a l e s s p I1Zekew I f J o e " ) d o e s n o t .

      P r e d i c a t e s ' f o r Any O b j e c t s
           0 1 i s some o b j e c t ,                 o f perhaps;     unknown t y p e       (objects are
      discussed l a t e r ) :

              eq              ( e q 01 0 2 )             01 a n d 0 2 a r e t h e same s y m b o l
                                                         o r t h e same c o n s .
              fixp            ( f i x p 01)              01 i s a n u m b e r , a s o p p o s e d t o
                                                         some o t h e r k i n d o f o b j e c t .
              stringp         ( s t r i n g p 01)        0 1 i s a s t r i n g , a s op.posed t o
                                                         anythin,g else.
              symbolp         (symbolp 0 1 )             01 i s a s y m b o l , a s o p p o s e d t o
                                                         anything else.
        null          ( n u l l 01)             01 is not only a symbol, but
                                                t h e important and
                                                c r i t i c a l s y m b o l named f f n i l u .

L I S P SPECIAL FORMS
         A number o f s p e c i a l f o r m s i n L i s p d o n o t go by t h e s i m p l e
rules           given   above.            You      have already        seen  one.    The
function-defining            f o r m , which b e g i n s w i t h t h e word I1defunff, i s
not simply a function c a l l with forms t o produce t h e f u n c t i o n f s
a r g u m e n t s . By a l l r i g h t s , a f o r m l i k e :
        (defun square (x)
               (* x XI)

s h o u l d e v a l u a t e , i n o r d e r , t o produce arguments f o r I1defunff:
        1.     A v a r i a b l e named u s q u a r e f l .

        2.      The form, ( x ) ,          calling a         f u n c t i o n named      ffxtfw i t h no
                arguments.
        3.      The form, ( * x x ) , m u l t i p l y i n g t h e v a l u e o f a v a r i a b l e
                named " x W b y i t s e l f ,
T h i s form s h o u l d t h e n p a s s t h e s e t h r e e v a l u e s on t o t h e d e f u n                 I
function.               T h i s , however,            is not      what a c t u a l l y happens.            -1   1
E v a l u a t i n g t h e d e f u n f o r m c a u s e s a f u n c t i o n named s q u a r e t o b e
d e f i n e d , w h o s e p a r a m e t e r l i s t a n d "bodyIf a r e a s g i v e n . D e f u n i s           I
                                                                                                                I
a s p e c i a l f o r m , a n d when L i s p s e e s " d e f u n W a s t h e f u n c t i o n n a m e
i n a f o r m , i t a c t s i n a s p e c i a l way.          I n t h i s case, L i s p d e f i n e s           ~
a f u n c t i o n b u i l t o u t o f t h i s form itself.                The a b o v e i s - a
                                                                                              not               I
c a l l t o d e f u n w i t h a r g u m e n t s . I t may seem u n u s u a l , b u t y o u m u s t
have a t l e a s t one such s p e c i a l form i n o r d e r t o have an o p e r a t i v e
Lisp system.

                                                                                                                    I
The i f S p e c i a l Form                                                                                          ~
       A s p e c i a l f o r m i n t h e M u l t i c s Emacs L i s p e n v i r o n m e n t , c a l l e d            I

i f , controls conditional evaluation.
-                                                         An e x a m p l e o f i t s u s e :
        (defun which-is-greater (first second)
               ( i f (> first second)
                     ( p r i n t "The f i r s t o n e i s t h e g r e a t e r . " )
                     else
                     ( i f (> second first)
                             ( p r i n t !?The s e c o n d o n e i s g r e a t e r " )
                             else
                             ( p r i n t " T h e y a r e e q u a l f f1 )
          The s y n t a x o f - i s a s f o l l o w s :
                              if
                  ( i f 
                         
                         
                                ...
                       
                     else
                       
                       
                                .. .
                                       )


                   Any n u m b e r , i n c l u d i n g n o n e , o f THEN-FORMS c a n b e s u p p l i e d .
          S i m i l a r l y , a n y n u m b e r , i n c l u d i n g n o n e , o f t h e ELSE-FORMS c a n b e
          given.          I f t h e r e a r e n o ELSE-FORMS, t h e n t h e k e y w o r d " e l s e " may
          be omitted, too.

                    Note t h a t a l l t h e forms i n t h e i f are n o t s e q u e n t i a l l y
          e v a l u a t e d ; t h e word e l s e i s n o t e v e n i n t e n d e d t o b e a f o r m .          If
          a l l o f t h e f o r m s i n s i d e t h e i f were e v a l u a t e d , i t w o u l d b e
          u s e l e s s , f o r e v a l u a t i o n w o u l d n o t b e c o n d i t i o n a l . T h a t i s why i f
          i s a s p e c i a l f o r m ; t h e r e a r e s p e c i a l r u l e s a b o u t how f o r m s i n s i d e
          it a r e t o b e e v a l u a t e d . The r u l e f o r a l l n o n s p e c i a l f o r m s i s t h e
          same: y o u e v a l u a t e a l l t h e s u b f o r m s s e q u e n t i a l l y t o p r o d u c e t h e
    (..   a r g u m e n t s t o t h e f u n c t i o n . E a c h s p e c i a l f o r m h a s i t s own r u l e s .
\

                    T h e i f s p e c i a l f o r m e v a l u a t e s t h e PREDICATE:    i f it r e s u l t s
          i n truth,          t h e THEN-FORMS a r e s e q u e n t i a l l y e v a l u a t e d , a n d t h e
          v a l u e o f t h e l a s t o n e i s r e t u r n e d a s t h e v a l u e of t h e i f .
          O t h e r w i s e , t h e ELSE-FORMS a r e e v a l u a t e d s e q u e n t i a l l y , a n d t h e
          v a l u e of t h e l a s t r e t u r n e d .         If t h e r e a r e none, t h e symbol n i l
          (see below) is r e t u r n e d , b u t is u s e l e s s i n t h e s e cases.

                    There are two g l o b a l v a r i a b l e s                in Lisp, called         n t ua n d
          I!n i 1? t ,      whose b i n d i n g s         a r e always         the   t r u t h and     fal.sity
          i n d i c a t o r s , r e s p e c t i v e l y . Thus:.
                  (if t
                       ( p r i n t ?lTruthff
                     else
                       ( p r i n t "Not s o t r u t h n ) )
          when e v a l u a t e d , a l w a y s p r i n t s ? ? T r u t h H .
The s e t q S p e c i a l Form
         V a r i a b l e s a c q u i r e v a l u e s by b e i n g p a r a m e t e r s , and a c q u i r i n g
v a l u e s a t f u n c t i o n c a l l time. I n a d d i t i o n , v a r i a b l e v a l u e s c a n
                                                                                                                1
b e c h a n g e d by t h e s p e c i a l f o r m s e t q :
        (defun adder-of-one ( x )
               ( p r i n t "The v a l u e o f x i s t 1 )
               (print x)
               ("And t h e v a l u e o f x p l u s o n e i s f 1 )
               (setq x (+ x 1))
               (printx))          "



A s e t q form    h a s t h e word I 1 s e t q u , t h e name o f a v a r i a b l e , a n d a n
i n s i d e form.      The i n s i d e f o r m i s e v a l u a t e d , and t h a t v a l u e
assigned t o the variable.            I t is l i k e an a s s i g n m e n t s t a t e m e n t i n
other languages.

T h e d o - f o r e v e r and s t o p - d o i n g S p e c i a l Forms
        The c o n s t r u c t f o r l o o p i n g i n t h e        Emacs L i s p e n v i r o n m e n t i s
a l s o a s p e c i a l form, c a l l e d do-forever:
        (do-forever
            ( p r i n t llYay M u l t i c s w )
            ( p r i n t " s c i t l u M yayf1)
When e v a l u a t e d , i t p r i n t s t h e s e t w o s a y i n g s f o r e v e r . The way you                  /


s t o p doing i n a do-forever               is t o e v a l u a t e t h e stop-doing s p e c i a l
form:
        (defun print-n-times (n)
               (do-forever
                 ( i f ( = n O)(stop-doing))
                 ( p r i n t "foolt)
                 (setq n (- n 1))))
T h i s f u n c t i o n , g i v e n a number a s a n a r g u m e n t , p r i n t s I1foo1l t h a t
many t i m e s . The " = I t          b u i l t i n f u n c t i o n / p r e d i c a t e compares i t s two
a r g u m e n t s , w h i c h m u s t b e n u m b e r s , and r e t u r n s t r u t h o r f a l s i t y
d e p e n d i n g on w h e t h e r o r n o t t h e y a r e n u m e r i c a l l y e q u a l . The
a r g u m e n t s t o = a r e - n and 0 , b u t r a t h e r , t h e n u m b e r s t h a t a r e
                                  not
t h e b i n d i n g s o f n a n d 0 . The number w h i c h i s t h e b i n d i n g o f n i s
d i f f e r e n t e a c h time a r o u n d t h e l o o p ; t h a t i s t h e p o i n t o f t h e
program.            I t i s s e t q t h a t c h a n g e s t h e v a l u e o f n e a c h time
around, a s do-forever                     executes t h e loop.                       A do-forever form
g e n e r a l l y r e t u r n s s o m e t h i n g . u s e l e s s ( n i l ) , u n l e s s you e x i t by
saying (return 5 ) o r (return n i l ) , or (return a ) . In the l a t t e r
c a s e , t h e value of t h e variable a is returned.
       -- Special
       The l e t                 Form
/

(..-           You     can      acquire temporary               variables         via the        -special
                                                                                                 let
       form:
               (defun sumtimesdif. (x y)
                  ( l e t ((sum (+ x y ) )
                            (dif (- x y ) ) )
                          ( p r i n t Ifsum times d i f f e r e n c e i s " 1
                          ( p r i n t ( * sum' d i f ) )
                          ( p r i n t llSum s q u a r e d i s 1 ' )
                          ( p r i n t ( * sum s u m ) ) ) )
       T h i s f u n c t i o n h a s two t e m p o r a r y v a r i a b l e s , ' s u r n and d i f , which a r e
       i n i t i a l i z e d t o t h e v a l u e s o f ( + x y ) a n d ( - x y ) . The g e n e r a l
       s y n t a x o f l e t is:
               ( l e t ((VAR1 VAL11
                         (VAR2 VAL2)




(                The t e m p o r a r y v a r i a b l e s VAR1. ..VARn e x i s t o n l y w i t h i n t h e
       let.        They g e t t h e i n i t i a l v a l u e s o f VAL1-VALn,        which a r e f o r m s
       mt w i l l b e e v a l u a t e d . A l l t h e V A L s a r e e v a l u a t e d b e f o r e a n y o f
       t h e i r values a r e assigned t o the VARs.                        Then, w i t h a l l t h e s e
       t e m p o r a r y v a r i a b l e s s e t u p and i n i t i a l i z e d , e a c h FORMi i s
       e v a l u a t e d s e q u e n t i a l l y , a n d t h e v a l u e o f t h e l a s t FORMi i s
       r e t u r n e d by -let.


       - p r o g - go S p e c i a l Forms
       The       and
                A n o t h e r , l e s s u s e f u l way o f a c q u i r i n g t e m p o r a r y v a r i a b l e s i s
       v i a t h e s p e c i a l f o r m p r o g . Forms . i n s i d e a p r o g a r e e v a l u a t e d
       s e q u e n t i a l l y , l i k e f o r m s i n a f u n c t i o n d e f i n i t i o n . However, t h e
       f i r s t form i n a p r o g i s n o t r e a l l y a form a t a l l , b u t a l i s t o f
       temporary v a r i a b l e s used i n t h e prog, such a s "(a b c ) " . That is
       why p r o g i s a s p e c i a l f o r m . The v a l u e r e t u r n e d by p r o g i s
       usually useless, unless (return ...I                            is used t o r e t u r n something
       meaningful.

               I n s i d e a p r o g , you c a n p u t l a b e l s , t o u s e f o r g o - t o ' s :
(defun bar2 (x y)
       (prog 0                                ; n o t e t h e empty v a r i a b l e l i s t
             ( i f (< x y)(go l a b l ) )
             ( p r i n t IfX i s n o t l e s s t h a n Y v )
             (return n i l )                  ; r e t u r n f f f a l s e f fi n d i c a t i o n
        labl
             ( p r i n t lVso b e i t If)
             (return t ) ) )                  ;return "trueff indication
I n t h e s p e c i a l f o r m -g o i t s o p e r a n d ( n o t a r g u m e n t ) i s a l a b e l t o
                                 9

which t o go, i . e . , c o n t i n u e s e q u e n t i a l e v a l u a t i o n o f forms i n t h e
prog.       L a b e l s are r a r e l y needed, due t o t h e powerful - and                 if
do-forever constructs.


T h e o r And a n d S p e c i a l ' F o r m s ,   And n o t

          There a r e s p e c i a l forms f o r or-ing and and-ing p r e d i c a t e
results:          they a r e s p e c i a l because they s t o p evaluating t h e i r
o p e r a n d s ( f r o m w h i c h a r g u m e n t s a r e p r o d u c e d ) when t h e y " k n o w f f
t h e i r answer for c e r t a i n :

       ( i f (and (not ( = x 0 ) )
                  ( > ( / / 10 x ) 5 ) )
             (print ffQuotienttoo large."))

The - f u n c t i o n i n v e r t s t r u t h and f a l s i t y .
      not                                                         The d o u b l e s l a s h
indicates d i v i s i o n , because s l a s h is t h e escape character i n
Lisp.

          The and d o e s n o t a t t e m p t . t o e v a l u a t e t h e s e c o n d form w i t h i n
it i f t h e i r s t p r o d u c e s f a l s i t y . T h i s p r e v e n t s a n e r r o r t h a t
w o u l d r e s u l t i f a n a t t e m p t were made t o d i v i d e b y z e r o .
S e q u e n t i a l e x e c u t i o n and s t o p p i n g a t an i n t e r m e d i a t e r e s u l t a r e
d e f i n e d and u s e f u l f e a t u r e s h e r e , a s opposed t o t h e l o g i c a l
o p e r a t o r s o f , s a y , PL/I.


The p r o g n and p r o g 2 S p e c i a l Forms

         Two m o r e s p e c i a l f o r m s a r e p r o g n a n d p r o g 2 .        To f o r c e
s e q u e n t i a l e x e c u t i o n o f forms and r e t u r n t h e v a l u e o f t h e l a s t ,
use progn.            For i n s t a n c e :
        ( i f (and ( > x 3)
                   ( p r o g n ( p r i n t IfOh d e a r t h i s i s g e t t i n g s e r i o u s f f )
                               0 y 5))
                   ( p r i n t " F a t a l d i f f i c u l t y f f )1 )
I n t h e above, progn r e t u r n s t h e v a l u e o f i t s l a g t form. Thus,
t h e - tests whether x i s g r e a t e r t h a n 3 , and y is g r e a t e r t h a n
        and
5 , b e f o r e t h e " p r i n t w o f " F a t a l d i f f i c u l t y M i s e v a l u a t e d . The
p r i n t i n g o f "Oh d e a r . . . " occurs a s part of the evaluation of the
     p r o g n , b u t t h e and s e e s o n l y t h e s e c o n d v a l u e i n t h e p r o g n .          The
     progn is used t o f o r c e e v a l u a t i o n o f t h e p r i n t form.
.-
'




              A prog2 is ~ ~ l i k e t progn, except t h a t it r e t u r n s its
                                                   s
     second argument, e v a l u a t e d , r a t h e r t h a n i t s l a s t . I t must have
     a t l e a s t t w o a r g u m e n t s . I t i s u s e f u l f o r s a v i n g some v a l u e t h a t
     i s s u b s e q u e n t l y g o i n g t o b e d e s t r o y e d . The f o l l o w i n g f o r m , when
     e v a l u a t e d , i n t e r c h a n g e s t h e v a l u e s o f x and y :
     ( s e t q x (prog2 0                              ;   t h i s z e r o i s evaluated t o 0,
                                                       ;   and i t s v a l u e t h r o w n away.
                              Y                        ;   t h e value o f y is obtained h e r e ,
                                                       ;   and reriiembered a s i t i s h e r e .
                              (setq y X I ) )          ;   x i s e v a l u a t e d , and t h a t v a l u e
                                                       ;   a s s i g n e d t o y . The v a l u e o f
                                                       ;   s e t q form i s t h a t v a l u e .
     I n t h e above, however, t h e value o f prog2 i s t h a t value o f y a s
     i t was b e f o r e i t was a s s i g n e d i n t o y , a n d now t h e o u t e r s e t q
     a s s i g n s t h a t t o x.

     SYMBOLS
        - Another t y p e o f d a t a o b j e c t i n L i s p is c a l l e d t h e symbol.
     S y m b o l s a r e named d a t a o b j e c t s k e p t i n a r e g i s t r y o f s y m b o l s , by
(    Lisp.         For c u r r e n t p u r p o s e s , t h e r e i s o n l y one symbol o f any
     name. S y m b o l s a r e u s e d i n Emacs t o r e p r e s e n t b u f f e r n a m e s , a n d
     v a r i o u s q u a n t i t i e s a s s o c i a t e d w i t h b u f f e r s . L i s p uses s y m b o l s t o
     k e e p t r a c k o f f u n c t i o n s , qnd i n t e r n a l l y t o k e e p t r a c k o f g l o b a l
     variables.

               To u s e a s y m b o l i n a p r o g r a m , g i v e t h e name             o f t h e symbol
     p r e c e d e d by t h e ASCII q u o t e c h a r a c t e r ,            .
                                                                           For             instance, the
     form:
             (setq x 'Brunhilde)
     a s s i g n s t h e s y m b o l named         Brunhilde          t o x.       Note t h a t      this is
     d i f f e r e n t from:
             ( s e t q x "Brunhilde")
     w h i c h a s s i g n s t h e string B r u n h i l d e t o x , a n d f r o m :
             (setq x Brunhilde)
     which a s s i g n s t h e v a l u e o f t h e v a r i a b l e B r u n h i l d e t o x.
LISP LISTS

          The f i n a l L i s p d a t a t y p e o f i m p o r t a n c e i n w r i t i n g e x t e n s i o n s
is t h e c o n s ( f o r c o n s t r u c t ) , and t h e l a r g e r d a t a t y p e b u i l t o u t
                                                                                                                .>\
                                                                                                                    '
o f i t , t h e l i s t . A c o n s i s a b l o c k t h a t r e l a t e s t o two ( u s u a l l y
o t h e r ) o b j e c t s i n t h e e n v i r o n m e n t , known a s i t s - a n d i t s -
                                                                                 car                 cdr.
T h e f u n c t i o n c o n s , g i v e n t w o o b j e c t s , p r o d u c e s a new c o n s , w h o s e
c a r and c d r , r e s p e c t i v e l y , a r e t h e two o b j e c t s g i v e n . For
instance, if the                         variable x has a value                   of. the string
l f B r u n h i l d e f f, a s a b o v e , t h e n :
        (cons 7 x)                                                                                                -   I


p r o d u c e s a c o n s w h o s e c a r i s t h e number 7 a n d w h o s e c d r i s t h e
s t r i n g l l B r u n h i l d e t f , r e t u r n i n g it a s a v a l u e . The f u n c t i o n s c a r        -   1
a n d c d r c a n b e u s e d t o o b t a i n t h e c a r a n d c d r o f a c o n s . If y o u                        I

set t h e v a r i a b l e c t o t h e r e s u l t o f t h e form (cons 7 x) above,
then :                                                                                                                1
        (car c)                                                                                                       I

p r o d u c e s t h e number 7 a s a v a l u e .

          U s u a l l y , y o u make l a r g e r a n d l a r g e r s t r u c t u r e s o u t o f
c o n s e s , by s e t t i n g u p c o n s e s w h o s e c a r a n d c d r a r e m o r e c o n s e s ,
and s o f o r t h , u n t i l you h a v e a l a r g e enough s t r u c t u r e t o
r e p r e s e n t a l l t h e v a l u e s you n e e d .       The r e s u l t i n g c o n s t r u c t i o n     .)
s e r v e s t h e same p u r p o s e a s a PL/I s t r u c t u r e :         its various p a r t s
h a v e meaning a s s i g n e d by t h e programmer.

          T h e m o s t common c o n s t r u c t i o n o f c o n s e s i s t h e l i s t . A l i s t
i s d e f i n e d a s a c h a i n of c o n s e s , e a c h o f w h i c h h a s t h e n e x t o n e
i n t h e c h a i n a s its c d r , except t h e l a s t o n e , which h a s t h e
s y m b o l l f n i l f 1 a s i t s c d r . A l i s t b u i l t i n t h i s way o f n c o n s e s i s
c a l l e d a list of n elements, t h e elements being t h e n o b j e c t s
t h a t a r e t h e c a r s o f t h e c o n s e s . The c o n s a t t h e head o f t h e
list is i d e n t i f i e d a s being Ifthe listff: its c a r is t h e f i r s t
e l e m e n t i n t h e l i s t , i t s c d r i s t h e c o n s whose c a r i s t h e s e c o n d
e l e m e n t o f t h e l i s t , a n d s o f o r t h . To c o n s t r u c t a l i s t o f t h e
numbers 2 , 4 , 5 , and 7 , i n t h a t o r d e r , and set t h e v a r i a b l e b t o
i t , you would,need:

         (setq b (cons 2 (cons 4 (cons 5 (cons 7 n i l ) ) ) ) )                                                  *       1
                                                                                                                          I
(Note t h a t t h e v a r i a b l e lfniltf is p e c u l i a r i n s o f a r a s its value is
a l w a y s t h e symbol t f n i l l f , t h u s you n e e d n o t s a y ' n i l . )



                                                                                                                          1
          A function t h a t *simplifies t h e writing of such forms, f o r
c o n s t r u c t i n g l i s t s , b u i l d s l i s t s d i r e c t l y and a c c e p t s a n y number
of arguments.                   I t produ,ces t h e same r e s u l t a s t h e t y p e o f
c o n s t r u c t i o n shown a b o v e . I t i s c a l l e d " l i s t f f :
                (setq b (list 2 4 5 7 ) )
(   I   To g e t t h e t h i r d e l e m e n t o f t h e l i s t ,                   once      this      form i s
        e v a l u a t e d , you c o u l d e v a l u a t e t h e f o r m : .
                (car (cdr (cdr b ) ) )
        ( i . e . , t h e c a r of t h e cons t h a t is t h e c d r of t h e c o n s t h a t is
        t h e c d r o f t h e cons t h a t is t h e value of b ) . Again, t h e r e a r e
        L i s p f u n c t i o n s t o s i m p l i f y s u c h c o n s t r u c t i o n s . The a b o v e f o r m i s
        equivalent to:
                (caddr b)
        I n g e n e r a l , f o r up t o 4 c a r s a n d c d r s d e e p , t o t a l , f u n c t i o n s l i k e
        c a d r , c d a r , c a d d r , c a d a r , and s o f o r t h , a r e p r o v i d e d ( u p t h r o u g h
        c a a a a r and c d d d d r ) . The f i r s t f o u r e l e m e n t s o f a l i s t a r e g o t t e n
        by c a r , c a d r , c a d d r , a n d c a d d d r ( i t i s a good e x e r c i s e t o work
        t h a t t h r o u g h a n d v e r i f y why t h i s i s t h e c a s e ) .

                  When l i s t s a r e p r i n t e d o u t by L i s p , t h e y a r e r e p r e s e n t e d a s
        a p a i r of parentheses around t h e p r i n t e d r e p r e s e n t a t i o n s o f a l l
        o f t h e e l e m e n t s , i n s e q u e n c e , s e p a r a t e d by s p a c e s . T h u s , i f L i s p
        p r i n t e d o u t t h e l i s t t h a t was b f s v a l u e a b o v e , i t would a p p e a r :

                (2 4 5 7)
        A c o n s whose c d r i s t h e s y m b o l n i l c a n a l w a y s b e v i e w e d a s a l i s t
        o f o n e i t e m , a n d i s s o p r i n t e d o u t by L i s p , u n l e s s . i t i s i n t h e
        p r o c e s s of p r i n t i n g a l a r g e r l i s t o f which t h e c o n s a t i s s u e i s a
        chain-link.           A c o n s whose c d r i s n e i t h e r n i l n o r a n o t h e r c o n s i s
        p r i n t e d w i t h a d o t p r e c e d i n g t h e c d r . Thus:
                (cons     'a   ' b ) => ( a        .  b)
                (cons     'a   n i l ) => ( a )                     ; a l i s t of one element
                (cons     'a   ( c o n s Ib ' c ) ) => ( a b     c) .
                (cons     'a   ( c o n s ' b n i l ) ) => ( a b)    ; l i s t o f two e l e m e n t s
                (cons     'a   (cons (cons ' b ' c ) ( c o n s 'd n i l ) ) )
                               => ( a ( b . c ) d )                 ;list of t h r e e elements

               Lists c a n b e p u t i n t o           p r o g r a m s , by q u o t i n g t h e m , a s s y m b o l s
        a r e quoted:
                 (setq bl       ' ( t h i s is ( a l i s t ) ( o f l i s t s ) ) )
              Two f u n c t i o n s a r e p r o v i d e d t o r e d e f i n e t h e c a r o r c d r o f a n
    e x i s t i n g c o n s . They c a n b e v e r y d a n g e r o u s i f m i s u s e d , e s p e c i a l l y   ;1)
    i f t h e y a l t e r a l i s t a s i n t h e form above, which is w r i t t e n i n t o
.   a p r o g r a m a s a c o n s t a n t . The r p l a c a f u n c t i o n ( r e p l a c e c a r ) a n d
    t h e r p l a c d f u n c t i o n ( r e p l a c e c d r ) e a c h t a k e two a r g u m e n t s . The
    f i r s t i s t h e c o n 3 t h a t i s t o be a l t e r e d , and t h e s e c o n d i s t h e
    new c a r o r new c d r , r e s p e c t i v e l y . The r e t u r n e d v a l u e i s t h e c o n s
    itself.
                                    SECTION 3

                            WRITING EMACS EXTENSIONS



             The starting point for writing extensions is building
        functions out of those.provided in the Emacs Lisp environment,
        and   hooking   them up   to keys.     The Emacs   set-key and
        set-permanent-key extended requests can connect keys to Lisp
        functions that you provide, as well as to the standard requests
        and keyboard macros.

             Many simple and useful extensions are just groups o f Emacs
        requests strung together. For instance, to go to the beginning
        o f a line, delete all whitespace there, go to the end of the
        line, do the same, and then return to the beginning of the line,
( ...   you could type:
             "A ESC \ "E ESC \ "A
        Alternatively, you could    write a     function,   called shave-line
        here, to do the same:
        (defun shave-line 0            ;keystroke functions take no args.
               (go-to-beginning-of-line)
               (delete-white-sides)
               (go-to-end-of-line)
               (delete-white-sides)
               (go-to-beginning-of-line))
        Write this function into a file.    When in Emacs, type ESC X
        loadfile PATHNAME CR, to load it in as code. Then hook it up,
        perhaps by typing:
             ESC X set-key "XA shave-line CR
        Thereafter, hitting "XA causes the     chosen sequence o f actions to
        happen.

             T o use conditionals and variables, you might, for example,
(+.     want a function that goes to the beginning of a line and deletes
        all words that start with nfoow from the beginning of the line.
        ( % i n c l u d e e-macros)

        (defun foodeleter (1
               (go-'to-beginning-of-line)
               (do-forever
                  ( i f ( l o o k i n g - a t "fool1)
                        (delete-word)
                        (delete-white-sides)
                      else ( s t o p - d o i n g ) ) ) )
The ( % i n c l u d e e-macros) must b e a t t h e b e g i n n i n g of any f i l e t h a t
u s e s t h e Ernacs e n v i r o n m e n t L i s p m a c r o s . T h e e - m a c r o s . i n c l . l i s p
f i l e should be i n your lltranslatorll search path i n .order t o do
a n y Emacs e x t e n s i o n d e v e l o p m e n t work.

          What t h i s f u n c t i o n d o e s i n e s s e n c e i s t y p e " A , a n d a s l o n g
a s t h e f i r s t t h r e e c h a r a c t e r s o n t h e l i n e a r e ! ' f ~ o ~ o e, s a n ESC
                                                                                         d~
D,      f o l l o w e d b y ESC \ t o r e m o v e t h e w h i t e s p a c e a f t e r t h e w o r d .
When t h e f i r s t t h r e e c h a r a c t e r s a r e n o l o n g e r l l f o o l l , i t r e t u r n s .
The " l o o k i n g - a t " i s a n Emacs p r e d i c a t e ( t o b e d e s c r i b e d i n d e t a i l
below) t h a t tests whether a given s t r i n g is t o t h e r i g h t o f t h e
c u r r e n t llcursorll.          For t h i s f u n c t i o n and any o t h e r s t h a t you
write, you c o u l d set a                       key a s d e s c r i b e d a b o v e ("XA              for
shave-line).

         The c o d e f o r t h e f o o d e l e t e r makes no mention o f p r i n t i n g ,
o u t p u t , o r d i s p l a y s b e c a u s e it d o e s n o t need t o . The s c r e e n o r
printing          terminal is              managed a u t o m a t i c a l l y b y t h e Emacs
redisplay.            The d i s p l a y need n e v e r be t h o u g h t a b o u t i n c o d i n g
Emacs e x t e n s i o n s .

U S I N G EMACS REQUESTS - EXTENSION C O D I N G
                      .
                         IN
        Many o f t h e E m a c s r e q u e s t s c a n a n d s h o u l d b e u s e d i n c o d i n g
extensions,              for        example,           go-to-end-of-line,          forward-char,
go-to-beginning-of-buffer,                      delete-word and skip-over-indentation.
Some r e q u e s t s , h o w e v e r , s h o u l d n o t b e u s e d i n e x t e n s i o n c o d e .
F o r e x a m p l e , i f you want t o s e a r c h f o r some s t r i n g , you d o n o t
want t o invoke string-search ( ^ S ) , s i n c e t h a t prompts t h e u s e r i n
t h e m i n i b u f f e r f o r a s e a r c h s t r i n g . The f o l l o w i n g t a b l e l i s t s
s o m e i m p o r t a n t k e y s t r o k e r e q u e s t s w h o s e command n a m e s y o u s h o u l d
n o t u s e and g i v e s a l t e r n a t i v e f u n c t i o n s t o use.

        KEY              DO NOT USE                              USE INSTEAD
        ^N           next-line-command                         next-line
                 The         next-line-c.ommand              function            is       unnecessarily
                 e x p e n s i v e i n c o n s i d e r i n g s c r e e n p o s i t i o n , and h a n d l e s
                 n u m e r i c a r g u m e n t s . The n e x t - l i n e f u n c t i o n a l w a y s g o e s
                 t o t h e beginning of the next l i n e .
    "P        prev-line-command        prev-line
            Same reasons as above. The prev-line function always
            goes to the previous line.
    ^K        kill-lines               kill-to-end-of-line
                                       delete-char (at eol)
            The kill-lines function is complex, has many cases, and
            handles numeric arguments.
    AS        string-search           forward-search
            The forward-search function takes a string as a Lisp
            argument, does not prompt, moves the cursor if the
            search succeeds, and returns truth or falsity t o
            indicate result.
    A   R     reverse-string-search          reverse-search
            Same as ^S.
    ^XAR      read-file                read-in-file
            The read-in-file function takes a Lisp               argument for
            pathname, does not prompt.
    "X*W      write-file                     write-out-file
            Same as "XAR.
    A   W     wipe-region               wipe-point-mark
            Use local marks, see below.
    ESC /     regexp-search-command    regexp-search
            Same issues as "S. Takes a Lisp argument, no slashes.
            Returns falsity if not found or moves cursor t o after,
            and returns mark to before, matched string. Be careful
            to release this mark (see below).
     ^XB      select-buffer                       go-to-or-create-buffer
            Takes an a r g u m e n t , d o e s not prompt.
     ^XAF     find-file                find-file-subr
            Takes an argument, does not prompt.

     .Requests that accept a positive numeric argument as meaning
repeat that number o f times, e.g., "B, "D, "F, ESC B, ESC D , ESC
F , !I, ESC # , etc., are acceptable in extensions; they do not
inspect their arguments. They are invoked multiple times by the
Emacs listener if appropriate.    Requests whose names include the
word "commandn (other than " G , command-quit) are usually not
intended to be used in code.
           T h e v a l u e o f a n u m e r i c a r g u m e n t , e . g . , 5 i n ESC 5 ^ B , i s
a v a i l a b l e a s t h e b i n d i n g o f t h e g l o b a l v a r i a b l e llnumargfl; i f no
numeric argument is g i v e n , t h i s v a r i a b l e is set t o t h e symbol
11 n i 1II     ( n o t t o b e confused w i t h t h e g l o b a l v a r i a b l e n i l , whose
b i n d i n g is t h e symbol n i l ) , which i s t h e r e p r e s e n t a t i o n o f
falsity.            The defcom f a c i l i t y , d i s c u s s e d l a t e r , can b e used t o
a d v a n t a g e a s well.


          The n o r m a l p r i n t i n g c h a r a c t e r s a r e bound t o t h e s e l f - i n s e r t
f u n c t i o n , which i n s e r t s t h e l a s t p h y s i c a l c h a r a c t e r typed a t t h e
current point in the buffer.                       T h i s is c l e a r l y unusable from code,
if     your d e s i r e is t o i n s e r t text i n t o t h e b u f f e r .               For t h i s
purpose, t h e            Emacs e n v i r o n m e n t p r o v i d e s        the insert-string
f u n c t i o n , whose argument i s a s t r i n g t o b e i n s e r t e d i n t o t h e
buffer a t t h e cursor. A s i n typing i n t e x t manually, t h e cursor
is l e f t a f t e r t h e i n s e r t e d t e x t :
        ( d e f u n make-a-point 0
                    (go-to-beginning-of-line)
                    ( i n s e r t - s t r i n g IICASE I N POINT:          ">>
          T h i s make-a-point            f u n c t i o n , when i n v o k e d , g o e s t o t h e
b e g i n n i n g o f t h e l i n e , a n d i n s e r t s t h e s t r i n g "CASE I POINT:
                                                                                     N
in the buffer.             The c u r s o r is l e f t a f t e r t h e i n s e r t e d s t r i n g .

          A s used here, phrases l i k e ,             " t h e c u r s o r i s moved a r o u n d w o r
"a s t r i n g is i , n s e r t e d u i n a f u n c t i o n , d o n o t imply t h a t t h e u s e r
w a t c h i n g t h e s c r e e n c a n see a l l t h e s e t h i n g s h a p p e n .         No a c t i o n
on t h e s c r e e n o c c u r s u n t i l t h e e n t i r e f u n c t i o n h a s f i n i s h e d
r u n n i n g , a t w h i c h time t h e s c r e e n i s u p d a t e d a l l a t o n c e , s h o w i n g
t h e c u m u l a t i v e e f f e c t o f w h a t h a s h a p p e n e d , r e g a r d l e s s o f how i t
happened.

M A R K S - THEIR MANAGEMENT
          AND

          L i k e t h e c u r s o r , a mark i s a c o n c e p t u a l p o i n t e r t o t h e
p o s i t i o n b e t w e e n t.wo c h a r a c t e r s i n t h e c u r r e n t b u f f e r .         Marks
remain           between. t h e s e           two c h a r a c t e r s       regardless of other
i n s e r t i o n s o r d e l e t i o n s i n t h e same b u f f e r , e v e n o n t h e same l i n e
as t h e mark.             Marks a r e v a l u a b l e beca.use r e g i o n s o f . t e x t i n t h e
b u f f e r a r e s p e c i f i e d a s t h e e x t e n t between t h e c u r r e n t c o n c e p t u a l
c u r s o r , ( t h e p o i n t ) , and a g i v e n mark. Marks a r e a t y p e o f d a t a
o b j e c t i n t h e Emacs L i s p e n v i r o n m e n t , l i k e s t r i n g s , n u m b e r s , a n d
s y m b o l s . T h e v a l u e o f a n y v a r i a b l e c a n b e made t o b e a m a r k .
T h e v a l u e o f s e v e r a l v a r i a b l e s m i g h t e v e n b e t h e same m a r k .           The
w o r d s " t h e - m a r k n u s e d i n Emacs d e s c r i p t i o n s d e s i g n a t e o n e mark
t h a t i s t h e v a l u e o f a g l o b a l v a r i a b l e t h a t many s u p p l i e d
f u n c t i o n s know a b o u t .       E m a c s f u n c t i o n s u s e many t e m p o r a r y m a r k s .
          - set-mark,
          The           release-mark and wipe-point-mark Functions
               The set-mark function creates a new mark, which points to
          the current point in the current buffer. It stays around, and is
          updated by the editor, any time text is inserted or deleted in
          this buffer.    This is expensive, so you must take care, to
          discard, or release marks when you are done using them. This is
          done by giving them to the release-mark function. A



◦ Jabse Service Manual Search 2020 ◦ Jabse Pravopis ◦ Other service manual resources online : FixyaeServiceinfo