What does the Bob say? (clojure version)
CBP Reminds Travelers to Allow 72 Hours for ESTA. Why?
Why does the author believe that the central mass that gas cloud HCN-0.009-0.044 orbits is smaller than our solar system?
You'll find me clean when something is full
Does music exist in Panem? And if so, what kinds of music?
The change directory (cd) command is not working with a USB drive
Reason Why Dimensional Travelling Would be Restricted
Make me a metasequence
Book where the good guy lives backwards through time and the bad guy lives forward
How can I find an Adventure or Adventure Path I need that meets certain criteria?
What is this waxed root vegetable?
Are small insurances worth it
Is divide-by-zero a security vulnerability?
"Murder!" The knight said
Find the next monthly expiration date
Why proton concentration is divided by 10⁻⁷?
How can I handle a player who pre-plans arguments about my rulings on RAW?
How to add multiple differently colored borders around a node?
Non-Italian European mafias in USA?
Exponential growth/decay formula: what happened to the other constant of integration?
As a new poet, where can I find help from a professional to judge my work?
How would we write a misogynistic character without offending people?
What am I? I am in theaters and computer programs
How to count words in a line
I am on the US no-fly list. What can I do in order to be allowed on flights which go through US airspace?
What does the Bob say? (clojure version)
$begingroup$
I'm doing the exercices from clojureacademy.
Here are the instructions for this one.
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
- Returns "Whatever." if given phrase is one of the following inputs:
- "Tom-ay-to, tom-aaaah-to."
- "Let's go make out behind the gym!"
- "It's OK if you don't want to go to the DMV."
- "Ending with ? means a question."
- "1, 2, 3"
Returns "Woah, chill out!" if given phrase is one of the following inputs:
- "WATCH OUT!"
- "WHAT THE HELL WERE YOU THINKING?"
- "ZOMG THE %^@#$(^ ZOMBIES ARE COMING!!11!!1!"
- "1, 2, 3 GO!"
- "I HATE YOU"
Returns "Sure." if given phrase is one of the following inputs:
- "Does this cryogenic chamber make me look fat?"
- "4?"
- Returns "Fine. Be that way!" if given phrase is one of the following inputs:
- ""
- " "
Here is my code in src/ex1_bob/core.clj:
(ns ex1-bob.core
(:gen-class))
; responses
; =======================
(def whatever "Whatever.")
(def chill-out "Woah, chill out!")
(def sure "Sure.")
(def fine "Fine. Be that way!")
; triggers
; =======================
(def sure-triggers
["Does this cryogenic chamber make me look fat?" "4?"])
(def whatever-triggers
["Tom-ay-to, tom-aaaah-to."
"Let's go make out behind the gym!"
"It's OK if you don't want to go to the DMV."
"Ending with ? means a question."
"1, 2, 3"])
(def chill-out-triggers
["WATCH OUT!"
"WHAT THE HELL WERE YOU THINKING?"
"ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
"1, 2, 3 GO!"
"I HATE YOU"])
(defn has-phrase
"return `true` if the given phrase is found in the collection, `false` otherwise"
[phrase coll]
(if (some #(= phrase %) coll)
true
false))
(defn response-for
"return `true` if the given phrase is found in the collection, `false` otherwise"
[phrase]
(cond
(has-phrase phrase whatever-triggers) whatever
(has-phrase phrase chill-out-triggers) chill-out
(has-phrase phrase sure-triggers) sure
(= (clojure.string/trim phrase) "") fine))
I also wrote some tests in test/ex1_bob/core_test.clj:
(ns ex1-bob.core-test
(:require [clojure.test :refer :all]
[ex1-bob.core :refer :all]))
; This does not work because `is` is a macro, and it seems it does not like to
; be used in a `map` or with `comp`.
;
; (deftest non-working-response-for-chill-out-triggers
; (doall (map (comp is #(= % chill-out) response-for) chill-out-triggers)))
(deftest response-for-chill-out-triggers
(is (every? #(= % chill-out) (map response-for chill-out-triggers))))
(deftest response-for-whatever-triggers
(is (every? #(= % whatever) (map response-for whatever-triggers))))
(deftest response-for-sure-triggers
(is (every? #(= % sure) (map response-for sure-triggers))))
(deftest response-for-empty-string
(is (every? #(= % fine) (map response-for [""]))))
Two things make me a bit unhappy about this code:
- the
has-phrasefunction seems a bit silly. Do I really have to write a function to returntrue/falseif an element is found in a collection? I feel that there must be a function that does this already
I first wrote my unit test with:
(deftest non-working-response-for-chill-out-triggers
(doall (map (comp is #(= % chill-out) response-for) chill-out-triggers)))
The idea is to have one assertion for each item, which I assumed would give me a better error message in case of a failure (because I know which item failed). But it seems that
isis a macro and somehow, the interpreter doesn't like this.
beginner clojure
$endgroup$
add a comment |
$begingroup$
I'm doing the exercices from clojureacademy.
Here are the instructions for this one.
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
- Returns "Whatever." if given phrase is one of the following inputs:
- "Tom-ay-to, tom-aaaah-to."
- "Let's go make out behind the gym!"
- "It's OK if you don't want to go to the DMV."
- "Ending with ? means a question."
- "1, 2, 3"
Returns "Woah, chill out!" if given phrase is one of the following inputs:
- "WATCH OUT!"
- "WHAT THE HELL WERE YOU THINKING?"
- "ZOMG THE %^@#$(^ ZOMBIES ARE COMING!!11!!1!"
- "1, 2, 3 GO!"
- "I HATE YOU"
Returns "Sure." if given phrase is one of the following inputs:
- "Does this cryogenic chamber make me look fat?"
- "4?"
- Returns "Fine. Be that way!" if given phrase is one of the following inputs:
- ""
- " "
Here is my code in src/ex1_bob/core.clj:
(ns ex1-bob.core
(:gen-class))
; responses
; =======================
(def whatever "Whatever.")
(def chill-out "Woah, chill out!")
(def sure "Sure.")
(def fine "Fine. Be that way!")
; triggers
; =======================
(def sure-triggers
["Does this cryogenic chamber make me look fat?" "4?"])
(def whatever-triggers
["Tom-ay-to, tom-aaaah-to."
"Let's go make out behind the gym!"
"It's OK if you don't want to go to the DMV."
"Ending with ? means a question."
"1, 2, 3"])
(def chill-out-triggers
["WATCH OUT!"
"WHAT THE HELL WERE YOU THINKING?"
"ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
"1, 2, 3 GO!"
"I HATE YOU"])
(defn has-phrase
"return `true` if the given phrase is found in the collection, `false` otherwise"
[phrase coll]
(if (some #(= phrase %) coll)
true
false))
(defn response-for
"return `true` if the given phrase is found in the collection, `false` otherwise"
[phrase]
(cond
(has-phrase phrase whatever-triggers) whatever
(has-phrase phrase chill-out-triggers) chill-out
(has-phrase phrase sure-triggers) sure
(= (clojure.string/trim phrase) "") fine))
I also wrote some tests in test/ex1_bob/core_test.clj:
(ns ex1-bob.core-test
(:require [clojure.test :refer :all]
[ex1-bob.core :refer :all]))
; This does not work because `is` is a macro, and it seems it does not like to
; be used in a `map` or with `comp`.
;
; (deftest non-working-response-for-chill-out-triggers
; (doall (map (comp is #(= % chill-out) response-for) chill-out-triggers)))
(deftest response-for-chill-out-triggers
(is (every? #(= % chill-out) (map response-for chill-out-triggers))))
(deftest response-for-whatever-triggers
(is (every? #(= % whatever) (map response-for whatever-triggers))))
(deftest response-for-sure-triggers
(is (every? #(= % sure) (map response-for sure-triggers))))
(deftest response-for-empty-string
(is (every? #(= % fine) (map response-for [""]))))
Two things make me a bit unhappy about this code:
- the
has-phrasefunction seems a bit silly. Do I really have to write a function to returntrue/falseif an element is found in a collection? I feel that there must be a function that does this already
I first wrote my unit test with:
(deftest non-working-response-for-chill-out-triggers
(doall (map (comp is #(= % chill-out) response-for) chill-out-triggers)))
The idea is to have one assertion for each item, which I assumed would give me a better error message in case of a failure (because I know which item failed). But it seems that
isis a macro and somehow, the interpreter doesn't like this.
beginner clojure
$endgroup$
add a comment |
$begingroup$
I'm doing the exercices from clojureacademy.
Here are the instructions for this one.
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
- Returns "Whatever." if given phrase is one of the following inputs:
- "Tom-ay-to, tom-aaaah-to."
- "Let's go make out behind the gym!"
- "It's OK if you don't want to go to the DMV."
- "Ending with ? means a question."
- "1, 2, 3"
Returns "Woah, chill out!" if given phrase is one of the following inputs:
- "WATCH OUT!"
- "WHAT THE HELL WERE YOU THINKING?"
- "ZOMG THE %^@#$(^ ZOMBIES ARE COMING!!11!!1!"
- "1, 2, 3 GO!"
- "I HATE YOU"
Returns "Sure." if given phrase is one of the following inputs:
- "Does this cryogenic chamber make me look fat?"
- "4?"
- Returns "Fine. Be that way!" if given phrase is one of the following inputs:
- ""
- " "
Here is my code in src/ex1_bob/core.clj:
(ns ex1-bob.core
(:gen-class))
; responses
; =======================
(def whatever "Whatever.")
(def chill-out "Woah, chill out!")
(def sure "Sure.")
(def fine "Fine. Be that way!")
; triggers
; =======================
(def sure-triggers
["Does this cryogenic chamber make me look fat?" "4?"])
(def whatever-triggers
["Tom-ay-to, tom-aaaah-to."
"Let's go make out behind the gym!"
"It's OK if you don't want to go to the DMV."
"Ending with ? means a question."
"1, 2, 3"])
(def chill-out-triggers
["WATCH OUT!"
"WHAT THE HELL WERE YOU THINKING?"
"ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
"1, 2, 3 GO!"
"I HATE YOU"])
(defn has-phrase
"return `true` if the given phrase is found in the collection, `false` otherwise"
[phrase coll]
(if (some #(= phrase %) coll)
true
false))
(defn response-for
"return `true` if the given phrase is found in the collection, `false` otherwise"
[phrase]
(cond
(has-phrase phrase whatever-triggers) whatever
(has-phrase phrase chill-out-triggers) chill-out
(has-phrase phrase sure-triggers) sure
(= (clojure.string/trim phrase) "") fine))
I also wrote some tests in test/ex1_bob/core_test.clj:
(ns ex1-bob.core-test
(:require [clojure.test :refer :all]
[ex1-bob.core :refer :all]))
; This does not work because `is` is a macro, and it seems it does not like to
; be used in a `map` or with `comp`.
;
; (deftest non-working-response-for-chill-out-triggers
; (doall (map (comp is #(= % chill-out) response-for) chill-out-triggers)))
(deftest response-for-chill-out-triggers
(is (every? #(= % chill-out) (map response-for chill-out-triggers))))
(deftest response-for-whatever-triggers
(is (every? #(= % whatever) (map response-for whatever-triggers))))
(deftest response-for-sure-triggers
(is (every? #(= % sure) (map response-for sure-triggers))))
(deftest response-for-empty-string
(is (every? #(= % fine) (map response-for [""]))))
Two things make me a bit unhappy about this code:
- the
has-phrasefunction seems a bit silly. Do I really have to write a function to returntrue/falseif an element is found in a collection? I feel that there must be a function that does this already
I first wrote my unit test with:
(deftest non-working-response-for-chill-out-triggers
(doall (map (comp is #(= % chill-out) response-for) chill-out-triggers)))
The idea is to have one assertion for each item, which I assumed would give me a better error message in case of a failure (because I know which item failed). But it seems that
isis a macro and somehow, the interpreter doesn't like this.
beginner clojure
$endgroup$
I'm doing the exercices from clojureacademy.
Here are the instructions for this one.
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
- Returns "Whatever." if given phrase is one of the following inputs:
- "Tom-ay-to, tom-aaaah-to."
- "Let's go make out behind the gym!"
- "It's OK if you don't want to go to the DMV."
- "Ending with ? means a question."
- "1, 2, 3"
Returns "Woah, chill out!" if given phrase is one of the following inputs:
- "WATCH OUT!"
- "WHAT THE HELL WERE YOU THINKING?"
- "ZOMG THE %^@#$(^ ZOMBIES ARE COMING!!11!!1!"
- "1, 2, 3 GO!"
- "I HATE YOU"
Returns "Sure." if given phrase is one of the following inputs:
- "Does this cryogenic chamber make me look fat?"
- "4?"
- Returns "Fine. Be that way!" if given phrase is one of the following inputs:
- ""
- " "
Here is my code in src/ex1_bob/core.clj:
(ns ex1-bob.core
(:gen-class))
; responses
; =======================
(def whatever "Whatever.")
(def chill-out "Woah, chill out!")
(def sure "Sure.")
(def fine "Fine. Be that way!")
; triggers
; =======================
(def sure-triggers
["Does this cryogenic chamber make me look fat?" "4?"])
(def whatever-triggers
["Tom-ay-to, tom-aaaah-to."
"Let's go make out behind the gym!"
"It's OK if you don't want to go to the DMV."
"Ending with ? means a question."
"1, 2, 3"])
(def chill-out-triggers
["WATCH OUT!"
"WHAT THE HELL WERE YOU THINKING?"
"ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
"1, 2, 3 GO!"
"I HATE YOU"])
(defn has-phrase
"return `true` if the given phrase is found in the collection, `false` otherwise"
[phrase coll]
(if (some #(= phrase %) coll)
true
false))
(defn response-for
"return `true` if the given phrase is found in the collection, `false` otherwise"
[phrase]
(cond
(has-phrase phrase whatever-triggers) whatever
(has-phrase phrase chill-out-triggers) chill-out
(has-phrase phrase sure-triggers) sure
(= (clojure.string/trim phrase) "") fine))
I also wrote some tests in test/ex1_bob/core_test.clj:
(ns ex1-bob.core-test
(:require [clojure.test :refer :all]
[ex1-bob.core :refer :all]))
; This does not work because `is` is a macro, and it seems it does not like to
; be used in a `map` or with `comp`.
;
; (deftest non-working-response-for-chill-out-triggers
; (doall (map (comp is #(= % chill-out) response-for) chill-out-triggers)))
(deftest response-for-chill-out-triggers
(is (every? #(= % chill-out) (map response-for chill-out-triggers))))
(deftest response-for-whatever-triggers
(is (every? #(= % whatever) (map response-for whatever-triggers))))
(deftest response-for-sure-triggers
(is (every? #(= % sure) (map response-for sure-triggers))))
(deftest response-for-empty-string
(is (every? #(= % fine) (map response-for [""]))))
Two things make me a bit unhappy about this code:
- the
has-phrasefunction seems a bit silly. Do I really have to write a function to returntrue/falseif an element is found in a collection? I feel that there must be a function that does this already
I first wrote my unit test with:
(deftest non-working-response-for-chill-out-triggers
(doall (map (comp is #(= % chill-out) response-for) chill-out-triggers)))
The idea is to have one assertion for each item, which I assumed would give me a better error message in case of a failure (because I know which item failed). But it seems that
isis a macro and somehow, the interpreter doesn't like this.
beginner clojure
beginner clojure
asked 2 mins ago
little-dudelittle-dude
20815
20815
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214734%2fwhat-does-the-bob-say-clojure-version%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214734%2fwhat-does-the-bob-say-clojure-version%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown