Skip to content

Commit d3ab1d3

Browse files
committed
Update concept documents to match style guide.
1 parent 7b066db commit d3ab1d3

File tree

19 files changed

+133
-89
lines changed

19 files changed

+133
-89
lines changed

concepts/conditionals/about.md

+14-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
Common Lisp provides the programmer with several different conditionals that can be categorised by the number of "branches" they support.
44

5-
Also, unlike many other programming languages, all conditionals in Common Lisp are _expressions_ not statements. This means that all Lisp conditionals evaluate to some value and can be substituted for concrete parameters.
5+
Also, unlike many other programming languages, all conditionals in Common Lisp are _expressions_ not statements.
6+
This means that all Lisp conditionals evaluate to some value and can be substituted for concrete parameters.
67

78
As an example:
89

@@ -30,7 +31,9 @@ The `if` conditional evaluates the first expression of the body when the test is
3031

3132
## Many-Branch Conditionals
3233

33-
The Lisp "super-conditional" is `cond`, which can have an infinite number of branches. Each branch has a test condition and body expression that are surrounded by an extra pair of parentheses. If all of the tests evaluate to false, then `nil` is returned.
34+
The Lisp "super-conditional" is `cond`, which can have an infinite number of branches.
35+
Each branch has a test condition and body expression that are surrounded by an extra pair of parentheses.
36+
If all of the tests evaluate to false, then `nil` is returned.
3437

3538
```lisp
3639
(cond ((= 0 2) 'nope)
@@ -41,7 +44,9 @@ The Lisp "super-conditional" is `cond`, which can have an infinite number of bra
4144
; => QUITE-TRUE
4245
```
4346

44-
If you just want to test one value against a number of branches, you can use the cleaner `case` expression. If none of the cases match, `nil` is returned. Both `t` and `otherwise` can be used as catch-all cases
47+
If you just want to test one value against a number of branches, you can use the cleaner `case` expression.
48+
If none of the cases match, `nil` is returned.
49+
Both `t` and `otherwise` can be used as catch-all cases:
4550

4651
```lisp
4752
(case 'elder-beast
@@ -54,20 +59,16 @@ If you just want to test one value against a number of branches, you can use the
5459

5560
## The Stealth Conditionals
5661

57-
The boolean `and` and `or` operations in Common Lisp are short-circuiting macros
58-
that can be used to reduce the duplication of certain conditional
59-
expressions.
62+
The boolean `and` and `or` operations in Common Lisp are short-circuiting macros that can be used to reduce the duplication of certain conditional expressions.
6063

61-
The `and` macro will immediately return `nil` if a single false value is
62-
encountered, but the last true value of the `and` otherwise:
64+
The `and` macro will immediately return `nil` if a single false value is encountered, but the last true value of the `and` otherwise:
6365

6466
```lisp
6567
(and 42 "Magic" :cool) ; => :COOL
6668
(and () "Magic" :cool) ; => NIL
6769
```
6870

69-
The `or` macro returns the first true value it encounters or `nil` if there were
70-
no true values:
71+
The `or` macro returns the first true value it encounters or `nil` if there were no true values:
7172

7273
```lisp
7374
(or () 42 nil) ; => 42
@@ -76,13 +77,10 @@ no true values:
7677

7778
## I'm Exhausted...
7879

79-
As mentioned previously, when none of the branches in a `case` statement match,
80-
and there is no `otherwise` clause, `nil` is returned. Occasionally, however, a
81-
failure to match any branch should be treated as an error – this is where
82-
`ecase` (for **exhaustive** matching) comes in.
80+
As mentioned previously, when none of the branches in a `case` statement match, and there is no `otherwise` clause, `nil` is returned.
81+
Occasionally, however, a failure to match any branch should be treated as an error – this is where `ecase` (for **exhaustive** matching) comes in.
8382

84-
It's used in exactly the same way as `case`, but signals an error instead of
85-
returning `nil` when there is no match.
83+
It's used in exactly the same way as `case`, but signals an error instead of returning `nil` when there is no match.
8684

8785
```lisp
8886
(case 'elder-beast

concepts/default-parameters/about.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
# About
22

3-
An optional parameter is designated by the `&optional` lambda list keyword in a lambda list. Optional parameters are not required, can have a default and also can specify a "supplied-p parameter" which will be "true" or "false" depending on whether an argument was provided for the parameter.
3+
An optional parameter is designated by the `&optional` lambda list keyword in a lambda list.
4+
Optional parameters are not required, can have a default and also can specify a "supplied-p parameter" which will be "true" or "false" depending on whether an argument was provided for the parameter.
45

56
```lisp
67
(defun optional-parameter (&optional (arg -1)) arg)
78
(optional-parameter) ;; => -1
89
(optional-parameter 13) ;; => 13
910
```
1011

11-
Optional parameters must be put after required parameters but before named or rest parameters. Arguments are first bound to required parameters, then optional parameters and finally to rest and named parameters.
12+
Optional parameters must be put after required parameters but before named or rest parameters.
13+
Arguments are first bound to required parameters, then optional parameters and finally to rest and named parameters.
1214

1315
```lisp
1416
(defun req-and-opt (req &optional (opt -1)) (list req opt)
1517
(req-and-opt 1) ;; => (1 -1)
1618
(req-and-opt 1 13) ;; => (1 13)
1719
```
1820

19-
While multiple types of parameters can be combined with other types of parameters (optional and keyword arguments) this can be be problematic and should be done carefully. See the section on ("Mixing Different Parameter Types")(pcl-function) in Practical Common Lisp.
21+
While multiple types of parameters can be combined with other types of parameters (optional and keyword arguments) this can be be problematic and should be done carefully.
22+
See the section on ("Mixing Different Parameter Types")(pcl-function) in Practical Common Lisp.
2023

2124
--
2225

concepts/default-parameters/introduction.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Introduction
22

3-
In Common Lisp a function can have some arguments are are optional. These are designated in the lambda list by `&optional` lambda list keyword. A parameter will be bound to the value `nil` if it is not specified. If there are several optional parameters they are bound in order. Default values can be specified for optional parameters. Finally a symbol an be specified for each optional parameter which will be bound to true or false depending on whether that parameter was supplied by the caller of the function (this is referred to as the "supplied-p parameter").
3+
In Common Lisp a function can have some arguments are are optional.
4+
These are designated in the lambda list by `&optional` lambda list keyword.
5+
A parameter will be bound to the value `nil` if it is not specified.
6+
If there are several optional parameters they are bound in order.
7+
Default values can be specified for optional parameters.
8+
Finally a symbol an be specified for each optional parameter which will be bound to true or false depending on whether that parameter was supplied by the caller of the function (this is referred to as the "supplied-p parameter").
49

510
```lisp
611
(defun default-parameters (&optional x (y 'default) (z nil z-supplied-p))

concepts/functions/about.md

+7-16
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,22 @@
22

33
In Common Lisp, global, named functions are defined with `defun`.
44

5-
This form takes as its first argument a list of parameters for the
6-
function being defined (the list of parameters is also called a
7-
'lambda list'). After that it can, optionally, take a string for use
8-
as documentation to that function. Finally there are zero or more
9-
expressions which make up the body of the function.
5+
This form takes as its first argument a list of parameters for the function being defined (the list of parameters is also called a 'lambda list').
6+
After that it can, optionally, take a string for use as documentation to that function.
7+
Finally there are zero or more expressions which make up the body of the function.
108

11-
Calling a function is done by using the name of the function as the
12-
first element of an expression, followed by any parameters to that
13-
function.
9+
Calling a function is done by using the name of the function as the first element of an expression, followed by any parameters to that function.
1410

1511
```lisp
1612
(defun add-one (x) (1+ x))
1713
1814
(add-one 3) ;; => 4
1915
```
2016

21-
Functions can also take [optional
22-
parameters](../default-parameters/about.md), [keyword
23-
parameters](../named-parameters/about.md), [rest
24-
parameters](../rest-parameters/about.md). These will be discussed in
25-
later concepts.
17+
Functions can also take [optional parameters](../default-parameters/about.md), [keyword parameters](../named-parameters/about.md), [rest parameters](../rest-parameters/about.md).
18+
These will be discussed in later concepts.
2619

27-
The name of the function is in [scope](../scope/about.md) in the body of
28-
the function so that [recursion](../recursion/about.md) can be
29-
performed.
20+
The name of the function is in [scope](../scope/about.md) in the body of the function so that [recursion](../recursion/about.md) can be performed.
3021

3122
```lisp
3223
(defun countdown (x)

concepts/functions/introduction.md

+8-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# Introduction
22

3-
To define a global function in Common Lisp one uses the `defun`
4-
expression. This expression takes as its first argument a list of
5-
parameters (and empty list means the function has no parameters). This
6-
is followed by an optional documentation string (see below), then zero
7-
or more expressions which make up the "body" of the function.
3+
To define a global function in Common Lisp one uses the `defun` expression.
4+
This expression takes as its first argument a list of parameters (and empty list means the function has no parameters).
5+
This is followed by an optional documentation string (see below), then zero or more expressions which make up the "body" of the function.
86

97
Functions may have zero or more parameters.
108

@@ -16,23 +14,17 @@ Functions may have zero or more parameters.
1614
(defun add-nums (x y) (+ x y))
1715
```
1816

19-
Calling a function is done by evaluating an expression with the symbol
20-
designating the function as the first element of the expression with
21-
the arguments to the function (if any) as the remaining items in the
22-
expression.
17+
Calling a function is done by evaluating an expression with the symbol designating the function as the first element of the expression with the arguments to the function (if any) as the remaining items in the expression.
2318

24-
The value that a function evaluates to is the value of the last
25-
expression in the function body that was evaluated. All functions
26-
evaluate to a value.
19+
The value that a function evaluates to is the value of the last expression in the function body that was evaluated. All functions evaluate to a value.
2720

2821
```lisp
2922
(add-nums 2 2) ;; => 4
3023
```
3124

32-
Functions can also have, optionally, a documentation string (also
33-
called a 'docstring'). If provided it comes after the argument list
34-
but before the body of the function. The documentation string can be
35-
accessed via `documentation`.
25+
Functions can also have, optionally, a documentation string (also called a 'docstring').
26+
If provided it comes after the argument list but before the body of the function.
27+
The documentation string can be via `documentation`.
3628

3729
```lisp
3830
(defun add-nums (x y) "Add X and Y together" (+ x y))

concepts/lambda-list/about.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# About
22

3-
In Common Lisp a parameter list (such as for defining a function) is also known as a (lambda list)[lambda-list]. Lambda lists are also used for defining macros and destructuring.
3+
In Common Lisp a parameter list (such as for defining a function) is also known as a (lambda list)[lambda-list].
4+
Lambda lists are also used for defining macros and destructuring.
45

56
Lambda lists can contain (lambda list keywords)[lambda-list-keyword] such as `&rest`, `&optional`, `&key` and others.
67

7-
While multiple types of parameters can be combined with other types of parameters (optional and keyword arguments) this can be be problematic and should be done carefully. See the section on ("Mixing Different Parameter Types")(pcl-function) in Practical Common Lisp.
8+
While multiple types of parameters can be combined with other types of parameters (optional and keyword arguments) this can be be problematic and should be done carefully.
9+
See the section on ("Mixing Different Parameter Types")(pcl-function) in Practical Common Lisp.
810

911
--
1012

concepts/lambda-list/introduction.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Introduction
22

3-
In Common Lisp a function's argument list is known as a ('lambda list')[lambda-list]. A lambda list can can have arguments of different types. These different types are designated with the use of ('lambda list keywords')[lambda-list-keyword] which all begin with `&`. The most commonly used types are optional, keyword and rest arguments types. Every parameter in the lambda list after a particular lambda list keyword is will be of that type. A lambda list keyword can only be used once in a lambda list.
3+
In Common Lisp a function's argument list is known as a ('lambda list')[lambda-list].
4+
A lambda list can can have arguments of different types.
5+
These different types are designated with the use of ('lambda list keywords')[lambda-list-keyword] which all begin with `&`.
6+
The most commonly used types are optional, keyword and rest arguments types.
7+
Every parameter in the lambda list after a particular lambda list keyword is will be of that type.
8+
A lambda list keyword can only be used once in a lambda list.
49

510
Lambda lists are also used in other constructs which will be discussed later such as destructuring and macros.
611

concepts/lists/about.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# About
22

3-
[Lists][hyper-cons-as-list] are a very common data type in Common Lisp. They are made up of a sequence of [cons][../cons/about.md] cells. Each `car` is an element of the list and every `cdr` is a either the next cons cell or a terminating atom.
3+
[Lists][hyper-cons-as-list] are a very common data type in Common Lisp.
4+
They are made up of a sequence of [cons][../cons/about.md] cells.
5+
Each `car` is an element of the list and every `cdr` is a either the next cons cell or a terminating atom.
46

57
A list which terminates with the empty list is called a "proper list".
68

79
A list which terminates with an atom that is not th empty list is called a "dotted list" (based upon how it is printed: `(cons 'a 'b) ;=> (a . b)`).
810

9-
A list can also be circular if some cons cell in the list `cdr` of a later cons cell. For example: `(let ((x (list 1))) (setf (cdr x) x) (write x :stream t :circle t) :done)`. Take care when working with circular lists as allowing them to be printed out without binding [`*print-circle*`][hyper-print-circle] to `t` will cause an infinite loop and will lock up the REPL (in this example by specifying `:circle t` to `write`, `*print-circle` will be bound to `t`).
11+
A list can also be circular if some cons cell in the list `cdr` of a later cons cell.
12+
For example: `(let ((x (list 1))) (setf (cdr x) x) (write x :stream t :circle t) :done)`.
13+
Take care when working with circular lists as allowing them to be printed out without binding [`*print-circle*`][hyper-print-circle] to `t` will cause an infinite loop and will lock up the REPL (in this example by specifying `:circle t` to `write`, `*print-circle` will be bound to `t`).
1014

1115
[hyper-cons-as-list]: http://l1sp.org/cl/14.1.2
1216
[hyper-print-circle]: http://l1sp.org/cl/*print-circle*

concepts/lists/introduction.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ Given that the name of the language is Lisp which stands of _LISt Processing_ on
44

55
While Common Lisp has other data structures as well as lists, lists are still heavily used.
66

7-
A list in Common Lisp is a sequence of items. The items themselves do not have to be the same type. For example you can have a list of `1`, `two`, `"III"`.
7+
A list in Common Lisp is a sequence of items.
8+
The items themselves do not have to be the same type.
9+
For example you can have a list of `1`, `two`, `"III"`.
810

911
## Creating Lists
1012

@@ -32,11 +34,13 @@ There are also two main functions used to create lists: `list` and `cons`.
3234

3335
## Length & Random Access
3436

35-
The length of a list can be determined by the use of `length`. An empty list has length zero.
37+
The length of a list can be determined by the use of `length`.
38+
An empty list has length zero.
3639

3740
An arbitrary item can be accessed with `nth` (note that lists are zero-indexed).
3841

39-
It is _not_ an error to request an index that is more than the length. Instead it evaluates to `nil`:
42+
It is _not_ an error to request an index that is more than the length.
43+
Instead it evaluates to `nil`:
4044

4145
```lisp
4246
(nth 23 '(short list))` ; => nil

concepts/named-parameters/about.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@
22

33
In Common Lisp named parameters are called keyword parameters.
44

5-
Keyword parameters are designated by the `&key` lambda list keyword in a lambda list. Keyword parameters are not required, can have a default and also can specify a "supplied-p parameter" which will be "true" or "false" depending on whether an argument was provided for the parameter.
5+
Keyword parameters are designated by the `&key` lambda list keyword in a lambda list.
6+
Keyword parameters are not required, can have a default and also can specify a "supplied-p parameter" which will be "true" or "false" depending on whether an argument was provided for the parameter.
67

78
```lisp
89
(defun keyword-parameter (&key (arg -1) arg)
910
(keyword-parameter) ;; => -1
1011
(keyword-parameter :arg 13) ;; => 13
1112
```
1213

13-
In the arguments to a function the keyword parameters are specified by their "keyword name" which is, by default, a keyword symbol version of the parameter name (_i.e._ keyword parameter `name` has a keyword name of `:name`). It is possible to specify another name for the keyword parameter by using a list of keyword name and parameter name instead of just the parameter name:
14+
In the arguments to a function the keyword parameters are specified by their "keyword name" which is, by default, a keyword symbol version of the parameter name (_i.e._ keyword parameter `name` has a keyword name of `:name`).
15+
It is possible to specify another name for the keyword parameter by using a list of keyword name and parameter name instead of just the parameter name:
1416

1517
```lisp
1618
(defun other-keyword-name (&key ((other-name arg))) (list arg))
1719
(other-keyword-name 'other-name 5) ;; => (5)
1820
```
1921

20-
While multiple types of parameters can be combined with other types of parameters (optional and keyword arguments) this can be be problematic and should be done carefully. See the section on ("Mixing Different Parameter Types")(pcl-function) in Practical Common Lisp.
22+
While multiple types of parameters can be combined with other types of parameters (optional and keyword arguments) this can be be problematic and should be done carefully.
23+
See the section on ("Mixing Different Parameter Types")(pcl-function) in Practical Common Lisp.
2124

2225
--
2326

concepts/named-parameters/introduction.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Introduction
22

3-
In Common Lisp a function can have named parameters (referred to as "keyword parameters" or "keyword arguments"). These are designated in the lambda list by the `&key` lambda list keyword. Keyword parameters are not required parameters. Like optional parameters they can be given default values and symbols to bind to their 'supplied-or-not' state.
3+
In Common Lisp a function can have named parameters (referred to as "keyword parameters" or "keyword arguments").
4+
These are designated in the lambda list by the `&key` lambda list keyword.
5+
Keyword parameters are not required parameters.
6+
Like optional parameters they can be given default values and symbols to bind to their 'supplied-or-not' state.
47

5-
When calling a function with keyword parameters the name of the parameter as a keyword is used in front of the parameter value. Keyword parameters can be specified by the caller of the function in any order.
8+
When calling a function with keyword parameters the name of the parameter as a keyword is used in front of the parameter value.
9+
Keyword parameters can be specified by the caller of the function in any order.
610

711
```lisp
812
(defun keyword-parameters (&key x (y 'default) (z nil z-supplied-p))

0 commit comments

Comments
 (0)