This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-21
Channels
- # beginners (165)
- # boot (9)
- # cider (9)
- # cljs-dev (5)
- # cljsjs (5)
- # clojars (4)
- # clojure (207)
- # clojure-brasil (1)
- # clojure-greece (3)
- # clojure-poland (2)
- # clojure-russia (6)
- # clojure-spec (85)
- # clojure-taiwan (1)
- # clojure-uk (53)
- # clojurescript (96)
- # community-development (2)
- # cursive (4)
- # datomic (14)
- # emacs (41)
- # events (2)
- # hoplon (184)
- # leiningen (1)
- # nginx (1)
- # off-topic (16)
- # om (7)
- # onyx (63)
- # pedestal (27)
- # planck (17)
- # protorepl (3)
- # rdf (9)
- # re-frame (62)
- # reagent (7)
- # ring-swagger (5)
- # schema (2)
- # spacemacs (5)
- # test-check (25)
- # untangled (93)
- # yada (3)
whats the best way to walk a hashmap given a vector of keys?
{:a {:b 1}}
[:a :b]
=> 1
@jswart I use your code this way :
(map (fn [input]
(let [reverser
(if (string? input)
(comp (partial apply str) reverse)
reverse)]
(= input (reverser input))))
@roelofw Are you using an editor + REPL or are you typing the solutions directly into 4clojure? Working in the REPL makes it a lot easier to see what your functions do
For example, what do you get when you call your function with '(1 2 3 4 5) as input?
@roelofw I am guessing that's a potential soln to an anagram detector? In the snippet you've shared you don't seem to have passed a collection to map
to map over?
Even if you fix that - I'm not sure what problem you are try to solve but that is expecting a sequence of either sequences or strings?
thanks, this solution is too difficult for me. I think im going for : ' (fn [x] (string? x (= x (str(reverse x)) (reverse x))))
I would try out some of these in a REPL - I think 4Clojure has a link to tryclj repl?
I changed the code to :
(fn [x](string? x)
(= x (str(reverse x)))
(= x reverse x) "racecar" )
at the moment you're executing each of these in sequence but none of them are doing anything with the result of the string?
predicate...
oke, what I want is if x is a string then this part must be evaluted (= x (str(reverse x)))
else the other part
I have now this :
(fn [x](if (string? x)
(= x (str(reverse x)))
(= x reverse x)) "racecar" )
oke, this works :
(defn roelof [x](if (string? x)
(= x (str(reverse x)))
(= x reverse x)))
I don't think you need to make a sequence a string as all you want as a result is true or false
if x
is a sequence and (reverse x)
is a reversed sequence then you can just compare them
oke, this one works for the first two :
(fn [x](if (string? x)
(= x (clojure.string/join(reverse x)))
(= x reverse x)))
i.e. =
is taking 3 arguments, two values (of x
) and the unevaluated function reverse
@roelofw I highly recommend following some people to see how they solve the challenges! I follow some of the top users: maximental, hypirion, jafingerhut, chouser, _caterpillar
@roelofw the trick to the palindrome stuff was that reverse converts it's input to a sequential, so you should do the same.
@roelofw a popular Fibonacci sequence solution uses recursion. It's worth trying to use recursion to solve it as it's educational
someone who can help me why I see this error message : ' ArityException Wrong number of args (1) passed to: runner/fibtill/fn--1885 clojure.lang.AFn.throwArity (AFn.java:429) on this code :
`` (defn fibtill [n]
(take n (map first (iterate ( fn[ a b ] ( + b (+ a b))) [0 1])))) `
Hello all, is there any way to use something like this? (re-seq #(str "some " thing) "some thing")
a function already takes a vector as its argument declaration, if you want to destructure in there you need to nest another vector
oke, I did .
(defn fibtill [n]
(take n (map first (iterate ( fn[ [a b] ] ( + b (+ a b))) [0 1]))))
but now this error message : IllegalArgumentException Don't know how to create ISeq from: java.lang.Long clojure.lang.RT.seqFrom (RT.java:542)
Hey, what am I missing, as can I do (require ā¦)
in user
ns in repl, but I get Unable to resolve symbol require ā¦
if I switch to namespace using (in-ns āmy-example.core)
?
When you run (in-ns āfoo)
the repl creates a new namespace for you. This namespace does not have clojure.core
in it. To see what you have you can type (clojure.core/ns-map clojure.core/*ns*)
this will show you a mapping of symbols to their values. You can type the symbol to run it in the repl.
@roelofw important part of clojure is learning to read these error messages. You should watch the Stuart Halloway talk on Debugging with the Scientific Method (or something similar to this in name)
@jswart wow, thanks! I didnāt know it doesnāt include clojure.core
. Do you know reasoning behind that? Why wouldnāt I want clojure.core
to be loaded each namespace?
Yes, this assumption from the "source codeā led me to this issue. But I still wonder why it is like that⦠reading in-ns
documentation again...
There it its (in the example), I missed that...
;; The "in-ns" function works almost the same as "ns", but does not load
;; clojure.core
Depends on what you are doing, if you are trying to test out some code then I usually put it into a file and run (load-file āthefile.cljā)
this is assuming Iām not just running a REPL with a little bit of code for fleshing out some idea
in ~5 years i donāt think Iāve ever run (nsā¦)
at the REPL, but maybe Iām doing it wrong.
I usually whole load buffer in cider, but sometimes I just want to run just a function without writing it in a file, now 90% of those get saved in a test anyways...
if you accidentally in-ns
to a new namespace and donāt have core, the easiest way to correct is to (clojure.core/refer-clojure)
(which is all ns
does)
Those are good, Iāve honestly never thought to (ns 'ā¦) at the REPL. I usually play in the REPL until the idea is done, grab the .nrepl-history with VIM and make a file.
technically both take symbols, but ns
is a macro so the symbol will not be evaluated and thus doesnāt need to be quoted
@roelofw I finished with Clojure-Nginx server setup here is the final ssh code https://github.com/damesek/clojure-nginx-setup-ssh
@dpsutton thanks , now I have to find out how to use it on this part :
(re-seq #"[A_Z]" s)
but the code ' (re-seq #"[A_Z]" s) ` needs to be evaluated. The outcome needs to be quoted I think
The code I work on is this one :
(defn filter-capitals
[s]
(re-seq #"[A_Z]" s)
)
(filter-capitals "Roelof Wobben")
why does (first {:a 1 :b 2})
always return [:a 1]
i would expect it to be random as there is no first in hash-maps as i understand?
> Returns the first item in the collection. Calls seq on its > argument. If coll is nil, returns nil.
gotcha. I have this database that the clj-httpās :as :json
functionality interoperates as a hashmap {:1 0.0 :2 10 :3 20}
. I think the database wants to serve me a sorted collection of [timestamp/long value] sorted by timestamp, but clj-http doesn't know its a sorted-map
Iāll probably have to tell it that otherwise ill run into trouble.