home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / util / edit / jade / man / jade.info-5 (.txt) < prev    next >
GNU Info File  |  1994-10-16  |  50KB  |  980 lines

  1. This is Info file jade.info, produced by Makeinfo-1.55 from the input
  2. file jade.texi.
  3. START-INFO-DIR-ENTRY
  4. * Jade: (jade).            An editor for X11 and AmigaDOS
  5. END-INFO-DIR-ENTRY
  6.    This is Edition 1.3, last updated 7 October 1994, of `The Jade
  7. Manual', for Jade, Version 3.2.
  8.    Jade is a text editor for X11 (on Unix) and the Amiga.
  9.    Copyright 1993, 1994 John Harper.
  10.    Permission is granted to make and distribute verbatim copies of this
  11. manual provided the copyright notice and this permission notice are
  12. preserved on all copies.
  13.    Permission is granted to copy and distribute modified versions of
  14. this manual under the conditions for verbatim copying, provided that
  15. the entire resulting derived work is distributed under the terms of a
  16. permission notice identical to this one.
  17. File: jade.info,  Node: Control Structures,  Next: Variables,  Prev: Evaluation,  Up: Programming Jade
  18. Control Structures
  19. ==================
  20.    Control structures are special forms or macros which control which
  21. forms get evaluated, when they get evaluated and the number of times to
  22. evaluate them. This includes conditional structures, loops, etc...
  23.    The simplest control structures are the sequencing structures; they
  24. are used to evaluate a list of forms in left to right order.
  25. * Menu:
  26. * Sequencing Structures::       Evaluating several forms in sequence
  27. * Conditional Structures::      Making decisions based on truth values
  28. * Looping Structures::          `while' loops
  29. * Non-Local Exits::             Exiting from several levels of evaluation
  30. File: jade.info,  Node: Sequencing Structures,  Next: Conditional Structures,  Up: Control Structures
  31. Sequencing Structures
  32. ---------------------
  33.    Each of the special forms in this section simply evaluates its
  34. argument forms in left-to-right order. The only difference is the
  35. result they return.
  36.    The most widely used sequencing special form is `progn': it
  37. evaluates all its argument forms and returns the computed value of the
  38. last one. Many other control structures are said to perform an
  39. "implicit progn", this means that they call `progn' with a list of
  40. forms.
  41.    `progn' in Lisp is nearly analogous to a `begin...end' block in
  42. Pascal; it is used in much the same places -- to allow you to evaluate
  43. a sequence of form where only one form was allowed (for example the
  44. true clause of an `if' structure).
  45.  - Special Form: progn FORMS...
  46.      All of the FORMS are evaluated sequentially (from left-to-right),
  47.      the result of the last evaluated FORM is the return value of this
  48.      structure. If no arguments are given to `progn' it returns `nil'.
  49.           (progn 'one (+ 1 1) "three")
  50.               => "three"
  51.           
  52.           (progn)
  53.               => nil
  54.  - Special Form: prog1 FIRST FORMS...
  55.      This special form evaluates its FIRST form then performs an
  56.      implicit progn on the rest of its arguments. The result of this
  57.      structure is the computed value of the first form.
  58.           (prog1 'one (+ 1 1) "three")
  59.               => one
  60.  - Special Form: prog2 FIRST SECOND FORMS...
  61.      This is similar to `prog1' except that the evaluated value of its
  62.      SECOND form is returned.
  63.      The FIRST form is evaluated, then its SECOND, then it performs an
  64.      implicit progn on the remaining arguments.
  65.           (prog2 'one (+ 1 1) "three")
  66.               => 2
  67. File: jade.info,  Node: Conditional Structures,  Next: Looping Structures,  Prev: Sequencing Structures,  Up: Control Structures
  68. Conditional Structures
  69. ----------------------
  70.    Lisp provides a number of conditional constructs, the most complex of
  71. which (`cond') will take a list of conditions, the first of which is
  72. `t' then has its associated list of forms evaluated. Theoretically this
  73. is the only conditional special form necessary -- the rest could be
  74. implemented as macros.
  75.  - Special Form: if CONDITION TRUE-FORM ELSE-FORMS...
  76.      The `if' construct is the nearest thing in Lisp to the
  77.      "if-then-else" construct found in most programming languages.
  78.      First the CONDITION form is evaluated, if it returns `t' (not
  79.      `nil') the TRUE-FORM is evaluated and its result returned.
  80.      Otherwise the result of an implicit progn on the ELSE-FORMS is
  81.      returned. If there are no ELSE-FORMS `nil' is returned.
  82.      Note that one of the TRUE-FORM or the ELSE-FORMS is completely
  83.      ignored -- it is not evaluated.
  84.           (if (special-form-p 'if)
  85.               "`if' is a special form"
  86.             "`if' is not a special form")
  87.               => "`if' is a special form"
  88.  - Special Form: when CONDITION TRUE-FORMS...
  89.      CONDITION is evaluated, if it is `t' the result of an implicit
  90.      progn on the TRUE-FORMS is returned, otherwise `nil' is returned.
  91.           (when t
  92.             (message "Pointless")
  93.             'foo)
  94.               => foo
  95.  - Special Form: unless CONDITION ELSE-FORMS...
  96.      This special forms first evaluates CONDITION, if its computed
  97.      value is not `nil' its value is returned. Otherwise the ELSE-FORMS
  98.      are evaluated sequentially, the value of the last is returned.
  99.  - Special Form: cond CLAUSE...
  100.      The `cond' special form is used to choose between an arbitrary
  101.      number of conditions. Each CLAUSE is a list; its car is the
  102.      CONDITION the list which is the cdr of the CLAUSE is the
  103.      BODY-FORMS. This means that each CLAUSE looks something like:
  104.           (CONDITION BODY-FORMS...)
  105.      and a whole `cond' form looks like:
  106.           (cond
  107.            (CONDITION-1 BODY-FORMS-1...)
  108.            (CONDITION-2 BODY-FORMS-2...)
  109.            ...)
  110.      The CONDITION in each CLAUSE is evaluated in sequence
  111.      (CONDITION-1, then CONDITION-2, ...), the first one which
  112.      evaluates to a non-`nil' has an implicit progn performed on its
  113.      BODY-FORMS, the value of which is the value returned by the `cond'
  114.      form.
  115.      If the true CONDITION has no BODY-FORMS the value returned by
  116.      `cond' is the value of the CONDITION. If none of the clauses has a
  117.      non-`nil' CONDITION the value of the `cond' is `nil'.
  118.      Often you want a "default" clause; one which has its BODY-FORMS to
  119.      be evaluated if none of the other clauses are true. The way to do
  120.      this is to add a clause with a CONDITION of `t' and BODY-FORMS of
  121.      whatever you want the default action to be.
  122.           (cond
  123.            ((stringp buffer-list))        ;Clause with no BODY-FORMS
  124.            ((consp buffer-list)
  125.             (setq x buffer-list)          ;Two BODY-FORMS
  126.             t)
  127.            (t                             ;Default clause
  128.             (error "`buffer-list' is corrupted!")))
  129.               => t
  130.      All of the other conditionals can be written in terms of `cond',
  131.           (if C T E...) == (cond (C T) (t E...))
  132.           
  133.           (when C T...) == (cond (C T...))
  134.           
  135.           (unless C E...) == (cond (E) (t E...))
  136.    There are also a number of special forms which combine conditions
  137. together by the normal logical rules.
  138.  - Special Form: or FORMS...
  139.      The first of the FORMS is evaluated, if it is non-`nil' its value
  140.      becomes the value of the `or' form and no more of `forms' are
  141.      evaluated. Otherwise this step is repeated for the next member of
  142.      FORMS.
  143.      If all of the FORMS have been evaluated and none have a non-`nil'
  144.      value `nil' becomes the value of the `or' form.
  145.      If there are no FORMS `nil' is returned.
  146.           (or nil 1 nil (beep))           ;`(beep)' won't be evaluated
  147.               => 1
  148.  - Special Form: and FORMS...
  149.      The first of the FORMS is evaluated. If it is `nil' no more of the
  150.      FORMS are evaluated and `nil' becomes the value of the `and'
  151.      structure. Otherwise the next member of FORMS is evaluated and its
  152.      value tested. If none of the FORMS are `nil' the computed value of
  153.      the last member of FORMS becomes the value of the `and' form.
  154.           (and 1 2 nil (beep))            ;`(beep)' won't be evaluated
  155.               => nil
  156.           
  157.           (and 1 2 3)                     ;All forms are evaluated
  158.               => 3
  159.  - Function: not OBJECT
  160.      This function inverts the boolean value of its argument. If OBJECT
  161.      is non-`nil', `nil' is returned, otherwise `t' is returned.
  162.           (not nil)
  163.               => t
  164.