forked from exercism/emacs-lisp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add accumulate exercise (exercism#407)
- Loading branch information
1 parent
b21ffaa
commit ef5dce3
Showing
7 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Instructions | ||
|
||
Implement the `accumulate` operation, which, given a collection and an operation to perform on each element of the collection, returns a new collection containing the result of applying that operation to each element of the input collection. | ||
|
||
Given the collection of numbers: | ||
|
||
- 1, 2, 3, 4, 5 | ||
|
||
And the operation: | ||
|
||
- square a number (`x => x * x`) | ||
|
||
Your code should be able to produce the collection of squares: | ||
|
||
- 1, 4, 9, 16, 25 | ||
|
||
Check out the test suite to see the expected function signature. | ||
|
||
## Restrictions | ||
|
||
Keep your hands off that collect/map/fmap/whatchamacallit functionality provided by your standard library! | ||
Solve this one yourself using other basic tools instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"authors": [ | ||
"kmarker1101" | ||
], | ||
"files": { | ||
"solution": [ | ||
"accumulate.el" | ||
], | ||
"test": [ | ||
"accumulate-test.el" | ||
], | ||
"example": [ | ||
".meta/example.el" | ||
] | ||
}, | ||
"blurb": "Implement the `accumulate` operation, which, given a collection and an operation to perform on each element of the collection, returns a new collection containing the result of applying that operation to each element of the input collection.", | ||
"source": "Conversation with James Edward Gray II", | ||
"source_url": "http://graysoftinc.com/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
;;; accumulate.el --- Accumulate (exercism) -*- lexical-binding: t; -*- | ||
|
||
;;; Commentary: | ||
|
||
;;; Code: | ||
|
||
|
||
(defun accumulate (lst op) | ||
(cond | ||
((null lst) lst) | ||
(t (cons (funcall op (car lst)) (accumulate (cdr lst) op))))) | ||
|
||
|
||
(provide 'accumulate) | ||
;;; accumulate.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This is an auto-generated file. | ||
# | ||
# Regenerating this file via `configlet sync` will: | ||
# - Recreate every `description` key/value pair | ||
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
# - Preserve any other key/value pair | ||
# | ||
# As user-added comments (using the # character) will be removed when this file | ||
# is regenerated, comments can be added via a `comment` key. | ||
|
||
[64d97c14-36dd-44a8-9621-2cecebd6ed23] | ||
description = "accumulate empty" | ||
|
||
[00008ed2-4651-4929-8c08-8b4dbd70872e] | ||
description = "accumulate squares" | ||
|
||
[551016da-4396-4cae-b0ec-4c3a1a264125] | ||
description = "accumulate upcases" | ||
|
||
[cdf95597-b6ec-4eac-a838-3480d13d0d05] | ||
description = "accumulate reversed strings" | ||
|
||
[bee8e9b6-b16f-4cd2-be3b-ccf7457e50bb] | ||
description = "accumulate recursively" | ||
include = false | ||
|
||
[0b357334-4cad-49e1-a741-425202edfc7c] | ||
description = "accumulate recursively" | ||
reimplements = "bee8e9b6-b16f-4cd2-be3b-ccf7457e50bb" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
;;; accumulate-test.el --- Accumulate (exercism) -*- lexical-binding: t; -*- | ||
|
||
;;; Commentary: | ||
|
||
;;; Code: | ||
|
||
|
||
(load-file "accumulate.el") | ||
(declare-function accumulate "accumulate.el" (lst op)) | ||
|
||
|
||
(ert-deftest accumulate-empty () | ||
(let ((result (accumulate '() (lambda (x) (* x x))))) | ||
(should (equal result '())))) | ||
|
||
|
||
(ert-deftest accumulate-square () | ||
(let ((result (accumulate '(1 2 3 4) (lambda (x) (* x x))))) | ||
(should (equal result '(1 4 9 16))))) | ||
|
||
|
||
(ert-deftest accumulate-upcases () | ||
(let ((result (accumulate '("Hello" "world") 'upcase))) | ||
(should (equal result '("HELLO" "WORLD"))))) | ||
|
||
|
||
(ert-deftest accumulate-reversed-strings () | ||
(let ((result (accumulate '("the" "quick" "brown" "fox" "etc") (lambda (x) (apply #'string (reverse (string-to-list x))))))) | ||
(should (equal result '("eht" "kciuq" "nworb" "xof" "cte"))))) | ||
|
||
|
||
(ert-deftest accumulate-recursively () | ||
(let* ((inner-list '("1" "2" "3")) | ||
(result (accumulate '("a" "b" "c") | ||
(lambda (x) | ||
(mapcar (lambda (y) (concat x y)) inner-list))))) | ||
(should (equal result '(("a1" "a2" "a3") | ||
("b1" "b2" "b3") | ||
("c1" "c2" "c3")))))) | ||
|
||
|
||
(provide 'accumulate-test) | ||
;;; accumulate-test.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
;;; accumulate.el --- Accumulate (exercism) -*- lexical-binding: t; -*- | ||
|
||
;;; Commentary: | ||
|
||
;;; Code: | ||
|
||
|
||
(defun accumulate (lst op) | ||
(error "Delete this S-Expression and write your own implementation")) | ||
|
||
|
||
(provide 'accumulate) | ||
;;; accumulate.el ends here |