Exercism  Check-in [5d1be6d30f]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add CL word-count
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 5d1be6d30f968501af931beff170171bed2ccd4cff9271f4f74887045ccb56c3
User & Date: jaccarmac 2019-02-22 06:03:25.887
Context
2019-02-22
06:03
Fix tests for Guix. check-in: 244b64e1df user: jaccarmac tags: trunk
06:03
Add CL word-count check-in: 5d1be6d30f user: jaccarmac tags: trunk
06:00
Gigasecond in CL. check-in: 1ef4b2e868 user: jaccarmac tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Added common-lisp/word-count/.exercism/metadata.json.


>
1
{"track":"common-lisp","exercise":"word-count","id":"d0fdfae95a9c4816ba91b3d8cfc36056","url":"https://exercism.io/my/solutions/d0fdfae95a9c4816ba91b3d8cfc36056","handle":"jaccarmac","is_requester":true,"auto_approve":false}
Added common-lisp/word-count/README.md.


































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Word Count

Given a phrase, count the occurrences of each word in that phrase.

For example for the input `"olly olly in come free"`

```text
olly: 2
in: 1
come: 1
free: 1
```

## Setup

Check out [Exercism Help](http://exercism.io/tracks/common-lisp) for instructions to
get started writing Common Lisp. That page will explain how to install and setup
a Lisp implementation and how to run the tests.

## Formatting

While Common Lisp doesn't care about indentation and layout of code,
nor whether you use spaces or tabs, this is an important consideration
for submissions to exercism.io. Excercism.io's code widget cannot
handle mixing of tab and space characters well so using only spaces is recommended to make
the code more readable to the human reviewers. Please review your
editors settings on how to accomplish this. Below are instructions for
popular editors for Common Lisp.

### VIM

Use the following commands to ensure VIM uses only spaces for
indentation:

```vimscript
:set tabstop=2
:set shiftwidth=2
:set expandtab
```

(or as a oneliner `:set tabstop=2 shiftwidth=2 expandtab`). This can
be added to your `~/.vimrc` file to use it all the time.

### Emacs

Emacs is very well suited for editing Common Lisp and has many
powerful add-on packages available. The only thing that one needs to
do with a stock emacs to make it work well with exercism.io is to
evaluate the following code:

`(setq-default indent-tab-mode nil)`

This can be placed in your `~/.emacs` (or `~/.emacs.d/init.el`) in
order to have it set whenever Emacs is launched.

One suggested add-on for Emacs and Common Lisp is
[SLIME](https://github.com/slime/slime) which offers tight integration
with the REPL; making iterative coding and testing very easy.

## Source

This is a classic toy problem, but we were reminded of it by seeing it in the Go Tour.

## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
Added common-lisp/word-count/word-count-test.lisp.




























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(ql:quickload "lisp-unit")
#-xlisp-test (load "word-count")

(defpackage #:word-count-test
  (:use #:common-lisp #:lisp-unit))

(in-package #:word-count-test)

(defun assert-assoc-equal (expected actual)
  "The association lists must have the same length and the keys and
  values of the items must match. But the order is not
  important. Equality is tested with equal"
  (assert-equal
      (sort (copy-seq expected) #'string< :key #'car)
      (sort (copy-seq actual) #'string< :key #'car)))

(define-test count-one-word
  (assert-assoc-equal '(("word" . 1))
      (phrase:word-count "word")))

(define-test count-one-of-each
  (assert-assoc-equal '(("one" . 1) ("of" . 1) ("each" . 1))
      (phrase:word-count "one of each")))

(define-test count-multiple-occurrences
  (assert-assoc-equal
   '(("one" . 1) ("fish" . 4) ("two". 1) ("red" . 1) ("blue" . 1))
   (phrase:word-count "one fish two fish red fish blue fish")))

(define-test ignore-punctuation
  (assert-assoc-equal
   '(("car" . 1) ("carpet" . 1) ("as" . 1) ("java" . 1) ("javascript" . 1))
   (phrase:word-count "car : carpet as java : javascript!!&@$%^&")))

(define-test include-numbers
  (assert-assoc-equal '(("testing" . 2) ("1" . 1) ("2" . 1))
      (phrase:word-count "testing, 1, 2 testing")))

(define-test normalize-case
  (assert-assoc-equal '(("go" . 3) ("on" . 3))
	  (phrase:word-count "go ON Go On GO on")))

#-xlisp-test
(let ((*print-errors* t)
      (*print-failures* t))
  (run-tests :all :word-count-test))
Added common-lisp/word-count/word-count.lisp.










>
>
>
>
>
1
2
3
4
5
(in-package #:cl-user)
(defpackage #:phrase
  (:use #:cl)
  (:export #:word-count))
(in-package #:phrase)