This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-18
Channels
- # adventofcode (1)
- # bangalore-clj (1)
- # beginners (118)
- # boot (39)
- # cljs-dev (6)
- # cljsrn (1)
- # clojure (62)
- # clojure-mke (1)
- # clojure-nl (6)
- # clojure-russia (51)
- # clojure-spec (8)
- # clojure-uk (9)
- # clojurescript (101)
- # code-reviews (1)
- # cursive (2)
- # datascript (9)
- # datomic (80)
- # emacs (4)
- # hoplon (27)
- # jobs-discuss (1)
- # off-topic (1)
- # om (1)
- # onyx (18)
- # protorepl (2)
- # re-frame (13)
- # reagent (13)
- # rum (9)
- # test-check (23)
I just wrote a beginner-focused blog post on how destructuring works (one of many, I know). feedback welcome! https://paultopia.github.io/posts-output/destructuring/
@seancorfield solved
(defn let-it-be
"Can you bind x, y, and z so that these are all true?"
[]
(let [x 7
y 3
z 1]
(and (= 10 (let x y (+ x y)))
(= 4 (let y z (+ y z)))
(= 1 (let z z)))))
I could do
(defn let-it-be "Can you bind x, y, and z so that these are all true?" [] (let [x 7 y 3 z 1]
is there a clojure fn that would convert
{:x {:y {:z 1}
:z 2} :z 3}
into {[:x :y :z] 1
[:x :z] 2
[:z] 3}
@kokos perhaps you can create a walker that traverses the map from top to bottom? That way you could put the keys in a vector i believe
(defn prepred [pk r [k v]]
(if-not (map? v)
(assoc r (conj pk k) v)
(reduce (partial prepred (conj pk k)) r v)))
(defn transf [x]
(reduce (partial prepred []) {} x))
(transf {:x {:y {:z 1} :z 2} :z 3})
probably will blow up stack for deep nested maps but works , thank you all but I see on the code that the functions have another color indicating that there is a error.
are sets not part of core ? When I test a function I see this error message :
java.lang.ClassNotFoundException: clojure.set
it is in a test file which only ns line is this :
(ns forclojure.elementary2-test
(:require [clojure.test :refer :all]
[forclojure.elementary2 :refer :all]))
it complaing about this line :
(is (= (intro-to-sets) (clojure.set/union #{:a :b :c} #{:b :c :d}))))
@seancorfield I’m still a little confused and looking for a definite answer on where I should create my database environment. Should I create all of my db environment through my application or is this something that you typically create beforehand and your application sits on top/references?
is this a good way to require set :
(ns forclojure.elementary2-test
(:require [clojure.test :refer :all]
[forclojure.elementary2 :refer :all]
[clojure.set :refer :all]))
I know the answer is [c e] . But when I make a function like this (identity [c e] )
I see a message that [ c e] cannot be resolved
and how to I make a function that takes two arguments [ v m]
and [ v, m ]
does not work
I try to make my private repo of 4 clojure challenges and I try to make one file with the solutions and one with tests
oh, so you're putting in a different file to return [c e] where c and e are not defined
it's about this code :
(defn map-defaults
"When retrieving values from a map, you can specify default values in case the key is not found:
\n\n(= 2 (:foo {:bar 0, :baz 1} 2))\n\nHowever, what if you want the map itself to contain the default values?
Write a function which takes a default value and a sequence of keys and constructs a map."
[]
[v m]
(zipmap m (repeat v)))
Could someone help me understand what I'm doing wrong with Java interop? I'm trying to translate this:
java
PDFont font = PDTrueTypeFont.loadTTF(document, "Arial.ttf");
Into clojure...
clojure
(.loadTTF PDTrueTypeFont document "Arial.ttf")
But I'm getting the following error
java.lang.IllegalArgumentException: No matching method found: loadTTF for class java.lang.Class
Do I need to cast the result to a PDFont?Why do I see this error in this test file :
(testing "rearrenging code"
(is ( (rearranging_code) (sort (rest (reverse [2 5 4 1 3 6]))))
(-> [2 5 4 1 3 6] (reverse) (rest) (sort) ((rearranging_code)))))
I try to test this function :
(defn rearranging_code
"The -> macro threads an expression x through a variable number of forms. First, x is inserted as the second item
in the first form, making a list of it if it is not a list already. Then the first form is inserted as the second
item in the second form, making a list of that form if necessary. This process continues for all the forms.
Using -> can sometimes make your code more readable."
[]
(identity 5))
and the error message is this :
actual: java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IFn
also, note that (identity x)
is x. so the function doesn't do anything, so you can just return x instead of (identity x)
and you call rearranging code twice, once so that it is the head of the list so therefore a function in the first form after the is, and second at the end of a threading macro but you are invoking it and threading the result, which is 5
I tried
(testing "rearrenging code"
(is ( = (rearranging_code) (sort (rest (reverse [2 5 4 1 3 6]))))
(-> [2 5 4 1 3 6] (reverse) (rest) (sort) ((rearranging_code)))))
and
(testing "rearrenging code"
(is ( (rearranging_code) ( = (sort (rest (reverse [2 5 4 1 3 6]))))
(-> [2 5 4 1 3 6] (reverse) (rest) (sort) ((rearranging_code))))))
then this schould be working I think
(testing "rearrenging code"
(is ( = (rearranging_code) (sort (rest (reverse [2 5 4 1 3 6])))
(-> [2 5 4 1 3 6] (reverse) (rest) (sort) ((rearranging_code))))))
but still the same error message : actual: java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IFn
also, based on indentation, your equal doesn't include the second form with the threading macro
when I do only rearranging_code
then it will also not be 5 because the function is not applied to my knowlegde
(= (__ (sort (rest (reverse [2 5 4 1 3 6]))))
(-> [2 5 4 1 3 6] (reverse) (rest) (sort) (__))
5)
defn returns-last [] last) #'cljc-bug.core/returns-last cljc-bug.core> ((returns-last) [1 2 3 4 5]) 5