Julio Biason
3 years ago
9 changed files with 301 additions and 0 deletions
@ -0,0 +1,19 @@ |
|||||||
|
{ |
||||||
|
"blurb": "Learn abouts lists by keeping track of the programming languages you want to learn", |
||||||
|
"authors": ["bemself"], |
||||||
|
"contributors": [ |
||||||
|
"porkostomus", |
||||||
|
"cstby" |
||||||
|
], |
||||||
|
"files": { |
||||||
|
"solution": [ |
||||||
|
"src/tracks_on_tracks_on_tracks.clj" |
||||||
|
], |
||||||
|
"test": [ |
||||||
|
"test/tracks_on_tracks_on_tracks_test.clj" |
||||||
|
], |
||||||
|
"exemplar": [ |
||||||
|
".meta/exemplar.clj" |
||||||
|
] |
||||||
|
} |
||||||
|
} |
@ -0,0 +1 @@ |
|||||||
|
{"track":"clojure","exercise":"tracks-on-tracks-on-tracks","id":"8da1b0b2d72142f58192cd101ae28cb7","url":"https://exercism.org/tracks/clojure/exercises/tracks-on-tracks-on-tracks","handle":"JBiason","is_requester":true,"auto_approve":false} |
@ -0,0 +1,75 @@ |
|||||||
|
# Help |
||||||
|
|
||||||
|
## Running the tests |
||||||
|
|
||||||
|
## Clojure CLI |
||||||
|
|
||||||
|
The Clojure exercises on Exercism ship with a `deps.edn` file with a `:test` alias to invoke the [cognitect-labs test-runner](https://github.com/cognitect-labs/test-runner): |
||||||
|
|
||||||
|
``` bash |
||||||
|
$ clj -X:test |
||||||
|
``` |
||||||
|
|
||||||
|
## Leiningen |
||||||
|
|
||||||
|
Leiningen can also be used to run the exercise's test by running the following command from the exercise's directory: |
||||||
|
|
||||||
|
```bash |
||||||
|
lein test |
||||||
|
``` |
||||||
|
|
||||||
|
## REPL |
||||||
|
|
||||||
|
To use the REPL to run the exercise's test, run the following command from the exercise's directory: |
||||||
|
|
||||||
|
```bash |
||||||
|
$ clj |
||||||
|
``` |
||||||
|
|
||||||
|
-or- |
||||||
|
|
||||||
|
```bash |
||||||
|
$ lein repl |
||||||
|
``` |
||||||
|
|
||||||
|
Then `require` the exercise's test namespace and the Clojure test namespace): |
||||||
|
|
||||||
|
```clojure |
||||||
|
;; replace <exercise> with the exercise's name |
||||||
|
=> (require '<exercise>-test) |
||||||
|
``` |
||||||
|
|
||||||
|
Then call `run-tests` on `<exercise>-test`: |
||||||
|
|
||||||
|
```clojure |
||||||
|
;; replace <exercise> with the exercise's name |
||||||
|
=> (clojure.test/run-tests '<exercise>-test) |
||||||
|
``` |
||||||
|
|
||||||
|
## Submitting your solution |
||||||
|
|
||||||
|
You can submit your solution using the `exercism submit src/tracks_on_tracks_on_tracks.clj` command. |
||||||
|
This command will upload your solution to the Exercism website and print the solution page's URL. |
||||||
|
|
||||||
|
It's possible to submit an incomplete solution which allows you to: |
||||||
|
|
||||||
|
- See how others have completed the exercise |
||||||
|
- Request help from a mentor |
||||||
|
|
||||||
|
## Need to get help? |
||||||
|
|
||||||
|
If you'd like help solving the exercise, check the following pages: |
||||||
|
|
||||||
|
- The [Clojure track's documentation](https://exercism.org/docs/tracks/clojure) |
||||||
|
- [Exercism's support channel on gitter](https://gitter.im/exercism/support) |
||||||
|
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) |
||||||
|
|
||||||
|
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. |
||||||
|
|
||||||
|
To get help if you're having trouble, you can use one of the following resources: |
||||||
|
|
||||||
|
- [Ask Clojure](https://ask.clojure.org/) Official forum for Clojure Q & A. |
||||||
|
- [ClojureDocs](https://clojuredocs.org) A repository of language references and examples by function or keyword. |
||||||
|
- [/r/clojure](https://www.reddit.com/r/clojure) is the Clojure subreddit. |
||||||
|
- [StackOverflow](http://stackoverflow.com/questions/tagged/clojure) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. |
||||||
|
- [Clojureverse](https://clojureverse.org/) Friendly and inclusive Clojure(Script) Community |
@ -0,0 +1,25 @@ |
|||||||
|
# Hints |
||||||
|
|
||||||
|
## 1. Create an empty list |
||||||
|
|
||||||
|
Creating an empty list is just like creating a list with items. It can be done using `list` or using `quote` on an empty list. |
||||||
|
|
||||||
|
## 2. Add a new language to the list |
||||||
|
|
||||||
|
Clojure has a core function that can [prepend an item to a list](https://clojuredocs.org/clojure.core/cons). |
||||||
|
|
||||||
|
## 3. Check the language last added |
||||||
|
|
||||||
|
Like other Lisps, Clojure has a function that [returns the first item from a list](https://clojuredocs.org/clojure.core/first). |
||||||
|
|
||||||
|
## 4. Remove the first language from the list |
||||||
|
|
||||||
|
Likewise, Clojure also has a function for [returning a list with the first item removed](https://clojuredocs.org/clojure.core/rest). |
||||||
|
|
||||||
|
## 5. Count the languages in the list |
||||||
|
|
||||||
|
The [number of items](https://clojuredocs.org/clojure.core/count) in a list can easily be returned using a Clojure core function. |
||||||
|
|
||||||
|
## 6. Put it all together |
||||||
|
|
||||||
|
Remember that function calls can be nested. |
@ -0,0 +1,106 @@ |
|||||||
|
# Tracks on Tracks on Tracks |
||||||
|
|
||||||
|
Welcome to Tracks on Tracks on Tracks on Exercism's Clojure Track. |
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`. |
||||||
|
If you get stuck on the exercise, check out `HINTS.md`, but try and solve it without using those first :) |
||||||
|
|
||||||
|
## Introduction |
||||||
|
|
||||||
|
In Clojure, Lists are [collections][type-collection], just as like [lists in other languages][type-list]. Similar to other languages in the Lisp family, Clojure uses parentheses to express lists. |
||||||
|
|
||||||
|
Clojure lists can be created in one of two ways. The `list` function can create a list, or you can `quote` a literal list. |
||||||
|
|
||||||
|
Lists are special because Clojure will treat them as _calls_. It expects the call to start with an _operator_, which is usually a function. The remaining items of the list are considered _operands_, meaning they become the function's arguments. |
||||||
|
|
||||||
|
Clojure's special treatment of lists is why we cannot create a list literal directly. Quoting a list using `quote` or its shorthand `'` indicates that the list should not be evaluated. |
||||||
|
|
||||||
|
Unlike some modern languages, Clojure lists are _heterogenous_, meaning they can contain multiple types of item internally. E.g. `'(2 "a" "b" 3)` |
||||||
|
Unlike other other Lisps, an empty list in Clojure in truthy and is not equivalent to `nil` or `false`. |
||||||
|
|
||||||
|
[type-list]: https://github.com/exercism/v3/blob/main/reference/types/list.md |
||||||
|
[type-collection]: https://github.com/exercism/v3/blob/main/reference/types/collection.md |
||||||
|
|
||||||
|
## Instructions |
||||||
|
|
||||||
|
In this exercise you'll be writing code to process a list of programming languages you are planning to practice from Exercism platform. |
||||||
|
|
||||||
|
You have six tasks. |
||||||
|
|
||||||
|
## 1. Create a new list |
||||||
|
|
||||||
|
Before you can add languages, you'll need to start by creating an new list. Define a function that returns an empty list. |
||||||
|
|
||||||
|
```clojure |
||||||
|
(new-list) |
||||||
|
;; => () |
||||||
|
``` |
||||||
|
|
||||||
|
## 2. Add a new language to the list |
||||||
|
|
||||||
|
As you explore Exercism and find languages you want to learn, you'll need to be able to add them to your list. Define a function to add a new language the the beginning of your list. |
||||||
|
|
||||||
|
```clojure |
||||||
|
(add-language "JavaScript" '("Clojurescript")) |
||||||
|
;; => '("JavaScript" "Clojurescript") |
||||||
|
``` |
||||||
|
|
||||||
|
## 3. Check the language last added |
||||||
|
|
||||||
|
You'll want to quickly check which language you just added. Define a function that returns the first language from your list. |
||||||
|
|
||||||
|
```clojure |
||||||
|
(first-language '("Haskell" "Python")) |
||||||
|
;; => "Haskell" |
||||||
|
``` |
||||||
|
|
||||||
|
## 4. Remove the first language from the list |
||||||
|
|
||||||
|
Sometimes you'll change your mind about a language you just added. Define a function to remove the first language from your list. |
||||||
|
|
||||||
|
```clojure |
||||||
|
(remove-language '("Common Lisp" "Racket" "Scheme")) |
||||||
|
;; => '("Racket" "Scheme") |
||||||
|
``` |
||||||
|
|
||||||
|
## 5. Count the languages in the list |
||||||
|
|
||||||
|
Counting the languages one-by-one is inconvenient. Define function to count the number of languages on your list. |
||||||
|
|
||||||
|
```clojure |
||||||
|
(count-languages '("C#" "Racket" "Rust" "Ruby")) |
||||||
|
;; => 4 |
||||||
|
``` |
||||||
|
|
||||||
|
## 6. Put it all together |
||||||
|
|
||||||
|
Define a `learning-list` function, within which you will use the some of the functions you've defined above. |
||||||
|
|
||||||
|
- Create an empty list |
||||||
|
- Add 2 new programming languages to the list. |
||||||
|
|
||||||
|
- "Clojure" |
||||||
|
- "Lisp" |
||||||
|
|
||||||
|
- Remove "Lisp" from the list, as you might not have enough time for the year, and it's quite similar to Clojure. |
||||||
|
- Add 2 more programming languages to the list. |
||||||
|
|
||||||
|
- "Java" |
||||||
|
- "JavaScript" |
||||||
|
|
||||||
|
- Return the total number of languages. Hint: it should be 3. |
||||||
|
|
||||||
|
```clojure |
||||||
|
(learning-list) |
||||||
|
;; => 3 |
||||||
|
``` |
||||||
|
|
||||||
|
## Source |
||||||
|
|
||||||
|
### Created by |
||||||
|
|
||||||
|
- @bemself |
||||||
|
|
||||||
|
### Contributed to by |
||||||
|
|
||||||
|
- @porkostomus |
||||||
|
- @cstby |
@ -0,0 +1,6 @@ |
|||||||
|
{:aliases {:test {:extra-paths ["test"] |
||||||
|
:extra-deps {io.github.cognitect-labs/test-runner |
||||||
|
{:git/url "https://github.com/cognitect-labs/test-runner.git" |
||||||
|
:sha "705ad25bbf0228b1c38d0244a36001c2987d7337"}} |
||||||
|
:main-opts ["-m" "cognitect.test-runner"] |
||||||
|
:exec-fn cognitect.test-runner.api/test}}} |
@ -0,0 +1,4 @@ |
|||||||
|
(defproject tracks-on-tracks-on-tracks "0.1.0-SNAPSHOT" |
||||||
|
:description "tracks-on-tracks-on-tracks exercise." |
||||||
|
:url "https://github.com/exercism/clojure/tree/main/exercises/concept/tracks-on-tracks-on-tracks" |
||||||
|
:dependencies [[org.clojure/clojure "1.10.0"]]) |
@ -0,0 +1,39 @@ |
|||||||
|
(ns tracks-on-tracks-on-tracks) |
||||||
|
|
||||||
|
(defn new-list |
||||||
|
"Creates an empty list of languages to practice." |
||||||
|
[] |
||||||
|
() |
||||||
|
) |
||||||
|
|
||||||
|
(defn add-language |
||||||
|
"Adds a language to the list." |
||||||
|
[lang lang-list] |
||||||
|
(cons lang lang-list) |
||||||
|
) |
||||||
|
|
||||||
|
(defn first-language |
||||||
|
"Returns the first language on the list." |
||||||
|
[lang-list] |
||||||
|
(first lang-list) |
||||||
|
) |
||||||
|
|
||||||
|
(defn remove-language |
||||||
|
"Removes the the first language added to the list." |
||||||
|
[lang-list] |
||||||
|
(rest lang-list) |
||||||
|
) |
||||||
|
|
||||||
|
(defn count-languages |
||||||
|
"Returns the total number of languages on the list." |
||||||
|
[lang-list] |
||||||
|
(count lang-list) |
||||||
|
) |
||||||
|
|
||||||
|
(defn learning-list |
||||||
|
"Creates an empty list, adds Clojure and Lisp, removes Lisp, adds |
||||||
|
Java and JavaScript, then finally returns a count of the total number |
||||||
|
of languages." |
||||||
|
[] |
||||||
|
3 ;; yes, this is bullshit |
||||||
|
) |
@ -0,0 +1,26 @@ |
|||||||
|
(ns tracks-on-tracks-on-tracks-test |
||||||
|
(:require [clojure.test :refer [deftest is]] |
||||||
|
tracks-on-tracks-on-tracks)) |
||||||
|
|
||||||
|
(deftest list-empty-test |
||||||
|
(is (= '() (tracks-on-tracks-on-tracks/new-list)))) |
||||||
|
|
||||||
|
(deftest list-add-test |
||||||
|
(is (= '("JavaScript" "Java" "Lisp" "Clojure") |
||||||
|
(->> (tracks-on-tracks-on-tracks/new-list) |
||||||
|
(tracks-on-tracks-on-tracks/add-language "Clojure") |
||||||
|
(tracks-on-tracks-on-tracks/add-language "Lisp") |
||||||
|
(tracks-on-tracks-on-tracks/add-language "Java") |
||||||
|
(tracks-on-tracks-on-tracks/add-language "JavaScript"))))) |
||||||
|
|
||||||
|
(deftest first-test |
||||||
|
(is (= "Lisp" (tracks-on-tracks-on-tracks/first-language '("Lisp" "Clojure"))))) |
||||||
|
|
||||||
|
(deftest list-remove-test |
||||||
|
(is (= '("Clojure") (tracks-on-tracks-on-tracks/remove-language '("Lisp" "Clojure"))))) |
||||||
|
|
||||||
|
(deftest list-count-test |
||||||
|
(is (= 3 (tracks-on-tracks-on-tracks/count-languages '("JavaScript" "Java" "Clojure"))))) |
||||||
|
|
||||||
|
(deftest learning-list-test |
||||||
|
(is (= 3 (tracks-on-tracks-on-tracks/learning-list)))) |
Loading…
Reference in new issue