Skip to content

Commit 06a487d

Browse files
committed
(minor) reader feedback: typos and precisions+
from @E3D3 for #509 time spent: 3 hours.
1 parent b1494c3 commit 06a487d

File tree

6 files changed

+102
-73
lines changed

6 files changed

+102
-73
lines changed

data-structures.md

Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ Destructuring a plist, giving defaults:
340340
~~~lisp
341341
(destructuring-bind (&key a (b :not-found) c
342342
&allow-other-keys)
343-
(:c 23 :d "D" :a #\A :foo :whatever)
343+
'(:c 23 :d "D" :a #\A :foo :whatever)
344344
(list a b c))
345345
;; => (#\A :NOT-FOUND 23)
346346
~~~
@@ -462,7 +462,7 @@ Accepts `:test`, `:test-not`, `:key` (functions or symbols).
462462
### Replacing objects in a tree: subst, sublis
463463

464464
[subst](http://www.lispworks.com/documentation/HyperSpec/Body/f_substc.htm) and
465-
`subst-if` search and replace occurences of an element
465+
`subst-if` search and replace occurrences of an element
466466
or subexpression in a tree (when it satisfies the optional `test`):
467467

468468
~~~lisp
@@ -504,52 +504,37 @@ _Note_: see also the [strings](strings.html) page.
504504
Many of the sequence functions take keyword arguments. All keyword
505505
arguments are optional and, if specified, may appear in any order.
506506

507-
Pay attention to the `:test` argument. It defaults to `eql` (for
508-
strings, use `:equal`).
507+
Pay attention to the `:test` argument. It defaults to `eql`. For
508+
strings, use `:equal`.
509509

510-
The `:key` argument should be passed either nil, or a function of one
510+
The `:key` argument can be passed a function of one
511511
argument. This key function is used as a filter through which the
512512
elements of the sequence are seen. For instance, this:
513513

514514
~~~lisp
515-
(find x y :key 'car)
516-
~~~
517-
518-
is similar to `(assoc* x y)`: It searches for an element of the list
519-
whose car equals x, rather than for an element which equals x
520-
itself. If `:key` is omitted or nil, the filter is effectively the
521-
identity function.
522-
523-
Example with an alist (see definition below):
515+
(defparameter *list-of-pairs* '((1 2) (41 42)))
524516
525-
~~~lisp
526-
(defparameter my-alist (list (cons 'foo "foo")
527-
(cons 'bar "bar")))
528-
;; => ((FOO . "foo") (BAR . "bar"))
529-
(find 'bar my-alist)
530-
;; => NIL
531-
(find 'bar my-alist :key 'car)
532-
;; => (BAR . "bar")
517+
(find 42 *list-of-pairs* :key #'second)
518+
;; => (41 42)
533519
~~~
534520

535-
For more, use a `lambda` that takes one parameter.
521+
searches for an element in the sequence
522+
whose `second` element equals 42, rather than for an element which equals 42
523+
itself. If `:key` is omitted or nil, the filter is effectively the
524+
`identity` function.
536525

537-
~~~lisp
538-
(find 'bar my-alist :key (lambda (it) (car it)))
539-
~~~
540-
541-
~~~lisp
542-
(find 'bar my-alist :key ^(car %))
543-
(find 'bar my-alist :key (lm (it) (car it)))
544-
~~~
526+
You can use a `lambda` function or any function that accepts one
527+
argument.
545528

546529

547530
### Predicates: every, some, notany
548531

549-
`every, notevery (test, sequence)`: return nil or t, respectively, as
532+
`every, notevery (test, sequence)`: they return nil or t, respectively, as
550533
soon as one test on any set of the corresponding elements of sequences
551534
returns nil.
552535

536+
`some`, `notany` *(test, sequence)*: they return either the value of the test, or nil.
537+
553538
~~~lisp
554539
(defparameter foo '(1 2 3))
555540
(every #'evenp foo)
@@ -558,18 +543,19 @@ returns nil.
558543
;; => T
559544
~~~
560545

561-
with a list of strings:
546+
Example with a list of strings:
562547

563548
~~~lisp
564-
(defparameter str '("foo" "bar" "team"))
565-
(every #'stringp str)
549+
(defparameter *list-of-strings* '("foo" "bar" "team"))
550+
(every #'stringp *list-of-strings*)
566551
;; => T
567-
(some (lambda (it) (= 3 (length it))) str)
552+
553+
(some (lambda (it)
554+
(= 3 (length it)))
555+
*list-of-strings*)
568556
;; => T
569557
~~~
570558

571-
`some`, `notany` *(test, sequence)*: return either the value of the test, or nil.
572-
573559

574560
### Functions
575561

@@ -619,7 +605,7 @@ To this end, use `alexandria-2:subseq*`:
619605
length of the one to replace.
620606

621607

622-
#### sort, stable-sort (sequence, test [, key function])
608+
#### sort, stable-sort (sequence, test [, key function]) (destructive)
623609

624610
These sort functions are destructive, so one may prefer to copy the sequence with `copy-seq` before sorting:
625611

@@ -637,7 +623,7 @@ In theory, the result of this:
637623
could be either `((1 :A) (1 :B))`, either `((1 :B) (1 :A))`. On my tests, the order is preserved, but the standard does not guarantee it.
638624

639625

640-
#### fill (sequence item &keys start end)
626+
#### fill (sequence item &keys start end) (destructive)
641627

642628
`fill` is a **destructive** operation.
643629

@@ -710,11 +696,29 @@ except that all elements equal to `old` are replaced with `new`.
710696
`nsubstitute` is the non-destructive version.
711697

712698

713-
#### sort, stable-sort, merge
699+
#### merge (result-type, sequence1, sequence2, predicate) (destructive)
714700

715-
(see above)
701+
The `merge` function is destructive.
716702

717-
#### replace (sequence-a, sequence-b, &key start1, end1)
703+
> destructively merge `sequence1` with `sequence2` according to an order determined by the predicate.
704+
705+
~~~lisp
706+
(setq test1 (list 1 3 5 7))
707+
(setq test2 (list 2 4 6 8))
708+
(merge 'list test1 test2 #'<)
709+
;; => (1 2 3 4 5 6 7 8)
710+
~~~
711+
712+
Now look at `test1`:
713+
714+
~~~lisp
715+
test1
716+
;; => (1 2 3 4 5 6 7 8)
717+
;; at least on SBCL, your result may vary.
718+
~~~
719+
720+
721+
#### replace (sequence-a, sequence-b, &key start1, end1) (destructive)
718722

719723
Destructively replace elements of sequence-a with elements of
720724
sequence-b.
@@ -727,7 +731,7 @@ The full signature is:
727731
&key (start1 0) (end1 nil) (start2 0) (end2 nil))
728732
~~~
729733

730-
Elements are copied to the subseqeuence bounded by START1 and END1,
734+
Elements are copied to the subsequence bounded by START1 and END1,
731735
from the subsequence bounded by START2 and END2. If these subsequences
732736
are not of the same length, then the shorter length determines how
733737
many elements are copied.
@@ -764,7 +768,7 @@ see also `remove-if[-not]` below.
764768
#### remove-duplicates, delete-duplicates (sequence)
765769

766770
[remove-duplicates](http://clhs.lisp.se/Body/f_rm_dup.htm) returns a
767-
new sequence with uniq elements. `delete-duplicates` may modify the
771+
new sequence with unique elements. `delete-duplicates` may modify the
768772
original sequence.
769773

770774
`remove-duplicates` accepts the following, usual arguments: `from-end
@@ -861,9 +865,15 @@ We can use sets functions.
861865

862866
We show below how to use set operations on lists.
863867

864-
A set doesn't contain twice the same element and is unordered.
868+
A set doesn't contain the same element twice and is unordered.
869+
870+
Most of these functions have recycling (modifying) counterparts,
871+
starting with "n", e.g.`nintersection` and `nreverse`. The "n" is for
872+
"non-consing", a lisp parlance for "don't create objects in memory".
865873

866-
Most of these functions have recycling (modifying) counterparts, starting with "n": `nintersection`,… They all accept the usual `:key` and `:test` arguments, so use the test `#'string=` or `#'equal` if you are working with strings.
874+
They all accept the usual `:key`
875+
and `:test` arguments, so use the test `#'string=` or `#'equal` if you
876+
are working with strings.
867877

868878
For more, see functions in
869879
[Alexandria](https://common-lisp.net/project/alexandria/draft/alexandria.html#Conses):
@@ -889,13 +899,15 @@ What elements are both in list-a and list-b ?
889899
;; => (4)
890900
~~~
891901

892-
### Join two lists with uniq elements (`union`)
902+
### Join two lists with unique elements (`union`, `nunion`)
893903

894904
~~~lisp
895905
(union list-a list-b)
896906
;; => (3 1 0 2 4) ;; order can be different in your lisp
897907
~~~
898908

909+
`nunion` is the recycling, destructive version.
910+
899911
### Remove elements that are in both lists (`set-exclusive-or`)
900912

901913
~~~lisp
@@ -1071,7 +1083,8 @@ Alists can be used sometimes differently though:
10711083
- they can be easily (de)serialized
10721084
- because of RASSOC, keys and values in alists are essentially
10731085
interchangeable; whereas in hash tables, keys and values play very
1074-
different roles (as usual, see CL Recipes for more).
1086+
different roles (as usual, see "Common Lisp Recipes" by Edmund Weitz
1087+
for more).
10751088

10761089

10771090
<a name="create"></a>

emacs-ide.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,15 @@ Otherwise, install SLIME by adding this code to your `~/.emacs.d/init.el` file:
8585

8686
~~~lisp
8787
(require 'package)
88+
8889
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
89-
(dolist (package '(slime))
90+
91+
(defvar my-packages '(slime))
92+
93+
(dolist (package my-packages)
9094
(unless (package-installed-p package)
9195
(package-install package)))
96+
9297
(require 'slime)
9398
~~~
9499

@@ -102,6 +107,12 @@ even the SLIME REPL), you might want to enable more features with
102107
(slime-setup '(slime-fancy slime-quicklisp slime-asdf slime-mrepl))
103108
~~~
104109

110+
Finally, tell Slime to use SBCL:
111+
112+
~~~lisp
113+
(setq inferior-lisp-program "sbcl")
114+
~~~
115+
105116
After this you can press Alt-X on your keyboard and type `slime` and try Common Lisp!
106117

107118
(Alt-X is often written `M-x` in Emacs-world.)
@@ -173,7 +184,8 @@ If you can't see it, call `M-x menu-bar-mode RET`.
173184

174185
In the terminal version of Emacs (`emacs -nw`), you can open the menu
175186
with `M-x menu-bar-open`, which is bound by default to `f10`, or use
176-
the mouse when it is enabled (`(xterm-mouse-mode +1)`).
187+
the mouse when it is enabled (evaluate `(xterm-mouse-mode +1)` with
188+
`M-:` or in the `*scratch*` buffer).
177189

178190
![](assets/slime-menu.png "Emacs' SLIME menu lists all available commands and keybindings.")
179191

@@ -313,7 +325,7 @@ The main shortcut to know is:
313325
Other bindings which may be useful:
314326

315327
- **C-c C-d f** describes a function
316-
- **C-c C-d h** looks up the symbol documentation in CLHS by opening the web browser. But it works only on symbols, so there are two more bindings:
328+
- **C-c C-d h** looks up the symbol documentation in Common Lisp Hyper Spec (CLHS) by opening the web browser. But it works only on symbols, so there are two more bindings:
317329
- **C-c C-d #** for reader macros
318330
- **C-c C-d ~** for format directives
319331

@@ -342,7 +354,7 @@ Use `C-c M-m` to macroexpand a macro call
342354
When you compile and load a file with `C-c C-k` (or a single function
343355
with `C-c C-c`), and when you have compilation warnings, you don't get
344356
the interactive debugger. You get the list of warnings inside a
345-
dedicated "`*slime-compilation*`" buffer that opens up next to your
357+
dedicated "`*slime-compilation*`" Emacs buffer that opens up next to your
346358
source file.
347359

348360
Each line of your source impacted by a warning will be underlined in red.
@@ -404,7 +416,7 @@ In Slime, you can use the usual `C-c C-k` in an .asd file to compile and load it
404416
- `M-x slime-rgrep-system`: run `rgrep` on the base directory of a system.
405417
- `M-x slime-isearch-system`: run `isearch` on the files of a system.
406418
- `M-x slime-query-replace-system`: run `query-replace` on an ASDF system.
407-
- `M-x slime-save-system`: save all files belongign to a system.
419+
- `M-x slime-save-system`: save all files belonging to a system.
408420
- `M-x slime-delete-system-fasls`: this deletes the cached .fasl files for this system.
409421

410422
Sly users have a more featureful `sly-load-system` command that will search the .asd file on the current directory and in parent directories.
@@ -879,13 +891,13 @@ Press `C-u M-(` to enclose it with parens:
879891

880892
With a numbered prefix argument (`C-u 2 M-(`), wrap around this number of s-expressions.
881893

882-
Additionnaly, use `M-x check-parens` to spot malformed s-exps.
894+
Additionally, use `M-x check-parens` to spot malformed s-exps.
883895

884896
There are additional packages that can make your use of parens easier:
885897

886898
- `M-x show-paren-mode`, a built-in Emacs mode: it toggles the visualization of matching parenthesis. When enabled, place the cursor on a paren and you'll see the other paren it matches with. You can initialize it in your Emacs init file with `(show-paren-mode t)`. It is a global minor mode (it will work for all buffers, all languages).
887899
- **we highly suggest you enable it**.
888-
- when evil-mode (the vim layer) is enabled, you can use the `%` key to go to the matchin paren.
900+
- when evil-mode (the vim layer) is enabled, you can use the `%` key to go to the matching paren.
889901
- `M-x electric-pair-mode`, a built-in Emacs mode: when enabled, typing an open parenthesis automatically inserts the corresponding closing parenthesis, and vice versa. (Likewise for brackets, etc.). If the region is active, the parentheses (brackets, etc.) are inserted around the region instead.
890902
- you could use [Paredit (animated guide)](http://danmidwood.com/content/2014/11/21/animated-paredit.html) to automatically insert parentheses in pairs,
891903
- or [lispy-mode](https://github.com/abo-abo/lispy), like Paredit, but a key triggers an action when the cursor is placed right before or right after a parentheses.
@@ -1054,7 +1066,6 @@ C-c C-o slime-repl-clear-output
10541066
C-c C-p slime-repl-previous-prompt
10551067
C-c C-s slime-complete-form
10561068
C-c C-u slime-repl-kill-input
1057-
C-c C-z other-window
10581069
C-c ESC Prefix Command
10591070
C-c I slime-repl-inspect
10601071

functions.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Call it:
3434
~~~
3535

3636
The `print` function prints its one argument to standard output *and
37-
returns it*. "hello world" is thus the returned value of our function.
37+
returns it*. "hello world!" is thus the returned value of our function.
3838

3939

4040
## Arguments
@@ -193,7 +193,7 @@ We saw that a default key parameter is `nil` by default (`(defun hello
193193
(name &key happy) …)`). But how can be distinguish between "the value
194194
is NIL by default" and "the user wants it to be NIL"?
195195

196-
We saw how to use a tuple to set its default value:
196+
We saw how to use a list of two elements to set its default value:
197197

198198
`&key (happy t)`
199199

@@ -283,8 +283,7 @@ Common Lisp has also the concept of multiple return values.
283283

284284
### Multiple return values
285285

286-
Returning multiple values is **not** like returning a tuple or a list of
287-
results.
286+
Returning multiple values is **not** like returning a list of results.
288287

289288
#### Quick example
290289

@@ -714,7 +713,7 @@ NIL
714713
;; We create a variable:
715714
CL-USER> (defparameter foo 42)
716715
FOO
717-
* foo
716+
CL-USER> foo
718717
42
719718
;; Now foo is "bound":
720719
CL-USER> (boundp 'foo)
@@ -732,7 +731,7 @@ T
732731
CL-USER> (function foo)
733732
#<FUNCTION FOO>
734733
;; and the shorthand notation:
735-
* #'foo
734+
CL-USER> #'foo
736735
#<FUNCTION FOO>
737736
;; We call it:
738737
(funcall (function adder) 5)
@@ -751,7 +750,7 @@ The other cell - sometimes referred to as its _function cell_ - can hold the def
751750
Now, if a _symbol_ is evaluated, it is treated as a _variable_ in that its value cell is returned (just `foo`). If a _compound form_, i.e. a _cons_, is evaluated and its _car_ is a symbol, then the function cell of this symbol is used (as in `(foo 3)`).
752751

753752

754-
In Common Lisp, as opposed to Scheme, it is _not_ possible that the car of the compound form to be evaluated is an arbitrary form. If it is not a symbol, it _must_ be a _lambda expression_, which looks like `(lambda `_lambda-list_ _form*_`)`.
753+
In Common Lisp, as opposed to Scheme, it is _not_ possible that the car of the compound form to be evaluated is an arbitrary form. If it is not a symbol, it _must_ be a _lambda expression_, which looks like `(lambda lambda-list form*)`.
755754

756755
This explains the error message we got above - `(adder 3)` is neither a symbol nor a lambda expression.
757756

0 commit comments

Comments
 (0)