home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
new
/
util
/
edit
/
jade
/
man
/
jade.info-5
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1994-10-16
|
50KB
|
980 lines
This is Info file jade.info, produced by Makeinfo-1.55 from the input
file jade.texi.
START-INFO-DIR-ENTRY
* Jade: (jade). An editor for X11 and AmigaDOS
END-INFO-DIR-ENTRY
This is Edition 1.3, last updated 7 October 1994, of `The Jade
Manual', for Jade, Version 3.2.
Jade is a text editor for X11 (on Unix) and the Amiga.
Copyright 1993, 1994 John Harper.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided that
the entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
File: jade.info, Node: Control Structures, Next: Variables, Prev: Evaluation, Up: Programming Jade
Control Structures
==================
Control structures are special forms or macros which control which
forms get evaluated, when they get evaluated and the number of times to
evaluate them. This includes conditional structures, loops, etc...
The simplest control structures are the sequencing structures; they
are used to evaluate a list of forms in left to right order.
* Menu:
* Sequencing Structures:: Evaluating several forms in sequence
* Conditional Structures:: Making decisions based on truth values
* Looping Structures:: `while' loops
* Non-Local Exits:: Exiting from several levels of evaluation
File: jade.info, Node: Sequencing Structures, Next: Conditional Structures, Up: Control Structures
Sequencing Structures
---------------------
Each of the special forms in this section simply evaluates its
argument forms in left-to-right order. The only difference is the
result they return.
The most widely used sequencing special form is `progn': it
evaluates all its argument forms and returns the computed value of the
last one. Many other control structures are said to perform an
"implicit progn", this means that they call `progn' with a list of
forms.
`progn' in Lisp is nearly analogous to a `begin...end' block in
Pascal; it is used in much the same places -- to allow you to evaluate
a sequence of form where only one form was allowed (for example the
true clause of an `if' structure).
- Special Form: progn FORMS...
All of the FORMS are evaluated sequentially (from left-to-right),
the result of the last evaluated FORM is the return value of this
structure. If no arguments are given to `progn' it returns `nil'.
(progn 'one (+ 1 1) "three")
=> "three"
(progn)
=> nil
- Special Form: prog1 FIRST FORMS...
This special form evaluates its FIRST form then performs an
implicit progn on the rest of its arguments. The result of this
structure is the computed value of the first form.
(prog1 'one (+ 1 1) "three")
=> one
- Special Form: prog2 FIRST SECOND FORMS...
This is similar to `prog1' except that the evaluated value of its
SECOND form is returned.
The FIRST form is evaluated, then its SECOND, then it performs an
implicit progn on the remaining arguments.
(prog2 'one (+ 1 1) "three")
=> 2
File: jade.info, Node: Conditional Structures, Next: Looping Structures, Prev: Sequencing Structures, Up: Control Structures
Conditional Structures
----------------------
Lisp provides a number of conditional constructs, the most complex of
which (`cond') will take a list of conditions, the first of which is
`t' then has its associated list of forms evaluated. Theoretically this
is the only conditional special form necessary -- the rest could be
implemented as macros.
- Special Form: if CONDITION TRUE-FORM ELSE-FORMS...
The `if' construct is the nearest thing in Lisp to the
"if-then-else" construct found in most programming languages.
First the CONDITION form is evaluated, if it returns `t' (not
`nil') the TRUE-FORM is evaluated and its result returned.
Otherwise the result of an implicit progn on the ELSE-FORMS is
returned. If there are no ELSE-FORMS `nil' is returned.
Note that one of the TRUE-FORM or the ELSE-FORMS is completely
ignored -- it is not evaluated.
(if (special-form-p 'if)
"`if' is a special form"
"`if' is not a special form")
=> "`if' is a special form"
- Special Form: when CONDITION TRUE-FORMS...
CONDITION is evaluated, if it is `t' the result of an implicit
progn on the TRUE-FORMS is returned, otherwise `nil' is returned.
(when t
(message "Pointless")
'foo)
=> foo
- Special Form: unless CONDITION ELSE-FORMS...
This special forms first evaluates CONDITION, if its computed
value is not `nil' its value is returned. Otherwise the ELSE-FORMS
are evaluated sequentially, the value of the last is returned.
- Special Form: cond CLAUSE...
The `cond' special form is used to choose between an arbitrary
number of conditions. Each CLAUSE is a list; its car is the
CONDITION the list which is the cdr of the CLAUSE is the
BODY-FORMS. This means that each CLAUSE looks something like:
(CONDITION BODY-FORMS...)
and a whole `cond' form looks like:
(cond
(CONDITION-1 BODY-FORMS-1...)
(CONDITION-2 BODY-FORMS-2...)
...)
The CONDITION in each CLAUSE is evaluated in sequence
(CONDITION-1, then CONDITION-2, ...), the first one which
evaluates to a non-`nil' has an implicit progn performed on its
BODY-FORMS, the value of which is the value returned by the `cond'
form.
If the true CONDITION has no BODY-FORMS the value returned by
`cond' is the value of the CONDITION. If none of the clauses has a
non-`nil' CONDITION the value of the `cond' is `nil'.
Often you want a "default" clause; one which has its BODY-FORMS to
be evaluated if none of the other clauses are true. The way to do
this is to add a clause with a CONDITION of `t' and BODY-FORMS of
whatever you want the default action to be.
(cond
((stringp buffer-list)) ;Clause with no BODY-FORMS
((consp buffer-list)
(setq x buffer-list) ;Two BODY-FORMS
t)
(t ;Default clause
(error "`buffer-list' is corrupted!")))
=> t
All of the other conditionals can be written in terms of `cond',
(if C T E...) == (cond (C T) (t E...))
(when C T...) == (cond (C T...))
(unless C E...) == (cond (E) (t E...))
There are also a number of special forms which combine conditions
together by the normal logical rules.
- Special Form: or FORMS...
The first of the FORMS is evaluated, if it is non-`nil' its value
becomes the value of the `or' form and no more of `forms' are
evaluated. Otherwise this step is repeated for the next member of
FORMS.
If all of the FORMS have been evaluated and none have a non-`nil'
value `nil' becomes the value of the `or' form.
If there are no FORMS `nil' is returned.
(or nil 1 nil (beep)) ;`(beep)' won't be evaluated
=> 1
- Special Form: and FORMS...
The first of the FORMS is evaluated. If it is `nil' no more of the
FORMS are evaluated and `nil' becomes the value of the `and'
structure. Otherwise the next member of FORMS is evaluated and its
value tested. If none of the FORMS are `nil' the computed value of
the last member of FORMS becomes the value of the `and' form.
(and 1 2 nil (beep)) ;`(beep)' won't be evaluated
=> nil
(and 1 2 3) ;All forms are evaluated
=> 3
- Function: not OBJECT
This function inverts the boolean value of its argument. If OBJECT
is non-`nil', `nil' is returned, otherwise `t' is returned.
(not nil)
=> t