This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-11
Channels
- # babashka (3)
- # beginners (70)
- # calva (15)
- # cider (34)
- # clara (10)
- # cljsrn (2)
- # clojure (28)
- # clojure-europe (21)
- # clojure-france (1)
- # clojure-uk (17)
- # clojuredesign-podcast (4)
- # clojurescript (51)
- # cursive (21)
- # data-science (1)
- # datalog (2)
- # datascript (2)
- # datomic (10)
- # emacs (5)
- # esprit (24)
- # expound (9)
- # figwheel-main (15)
- # fulcro (31)
- # graphql (3)
- # jobs-discuss (27)
- # keechma (2)
- # luminus (2)
- # malli (2)
- # minimallist (14)
- # nrepl (1)
- # off-topic (4)
- # pathom (1)
- # pedestal (8)
- # re-frame (10)
- # reagent (5)
- # reitit (2)
- # rewrite-clj (54)
- # sci (1)
- # shadow-cljs (34)
- # spacemacs (12)
- # sql (17)
- # vim (16)
- # web-security (1)
(defn home
[request]
(response
(layout[[:div.container
[:h1.display3 "Hello there!"]]
])))
The above produces this error "[:div.container [:h1.display3 "Hello there!"]] is not a valid element name."
(defn home
[request]
(response
(layout[:div.container
[:h1.display3 "Hello there!"]]
)))
Hi all, I've been learning from the book Getting Clojure the past few weeks and I am just running a code example but not getting the results as expected from the text. Here is the code: (defn chatty-vector []
(println "Here we go!")
[1 2 3])
Followed by: (def s (lazy-seq (chatty-vector)))
and (first s)
That last is meant to trigger the println expression to be executed according to the book but it doesn't for me - I tried both in Atom+Chlorine as well as on the PowerShell commandline REPL with clj tool
Is this some behaviour that is changed in Clojure since the book came out or perhaps an error in the book?
how do i import or require a protocol from a different namespace?
ope, okay. got myself confused with records and importing. thanks
The Alfred North Whitehead book? https://en.wikipedia.org/wiki/Process_and_Reality
(here's the transcript of Rich's talk https://github.com/matthiasn/talk-transcripts/blob/master/Hickey_Rich/AreWeThereYet-mostly-text.md -- that site has transcripts of several other talks by him and others)
Is there a way to select a shape? Maybe with EQL or clojure.spec
;; if shape is described with clojure.spec
(s/def ::meaningful ...)
(defn save-meaningful! [org]
(-> org
(clojure.spec/select ::meaningful) ;; desired feature, ensures only speced shape is getting through {:meaningful-key "meaningful value"}
(transact-org!)
))
(save-org! {:meaningful-key "meaningful value"
:trash-key "trash value"})
(select-keys ...) works for this simple case, but let's imagine it is a deep maphow can I express the following (Java) method annotation @Plan(trigger=@Trigger(factchanged="time"))
in Clojure? So how do I express the 'nested-ness' of these annotations?
annotations are expressed in Java on code - are you using gen-class or deftype or something? there is (limited) support for annotations in interop
see https://clojure.org/reference/datatypes#_java_annotation_support
do protocol interfaces support variable argument lists yet? or is this (https://clojuredocs.org/clojure.core/defprotocol#example-542692d2c026201cdc326f80) still the best work around?
reasoning: i have a macro that creates an if
branch, where it either adds or doesn't add a specific call in the parameter list. this works in "normal" function calls because parameter length isn't checked unless execute. but in a protocol method, the parameter length is checked at compile. I can add an extra method signature that has a plz-dont-use
parameter, but that feels like it's opening me up to bugs in the future.
code example, from after macro expansion:
(if use-eid#
(handler (first costs) state side new-eid# card actions)
(handler (first costs) state side new-eid# (make-eid state eid) card actions))
handler
here is the protocol method
no, they do not support varargs
Hi folks - I’m working on a game. I have a sequence of 16 vectors - 4 of one set of keys, 4 of another set of keys:
([:a :w] [:a :x] [:a :y] [:a :z] [:b :w] ... [:d :z])
(Note: The data won’t be neatly ordered like this.)
I’d like to think of this data as 4 rows x 4 columns. I’ve figured out how to evaluate the rows for a test condition, but I’m having problems evaluating the columns. Maybe it would be easier to turn the grid 90° and then just use the same tests for the rows. Any thoughts on how to tackle this problem?a row is (partition 4 coll)
, right?
so a column within a row would be (nth row index)
where index is a number between 0 and 3
oh, you're asking about the entire column i bet
yes, the whole column
row * number-of-columns + column
is the formula for each cell in the column
forgot to mention, lol, number-of-columns
is 1-indexed and column
is 0-indexed
(1-indexed isn't quite correct, it's just the natural means of counting)
Maybe a couple of nested for
statements?
that could work!
if you don't have substructure, you want a single for comprehension with multiple clauses
in C / Java "for" is a statement that makes a loop, in Clojure it's a comprehension that generates a lazy sequence
we don't have statements
and if you're selecting a single column, you only need a single clause: (for [r (range 4)] (nth coll (+ 3 (* r 4))))
@scotto if you store the data in a more structured way, the form you present here is easy to derive - is there a reason it needs to be spread out like this?
No, @noisesmith I could structure it differently if that would help things.
when it's only 16 items long, seems like not much to be gained by keeping it as a 1-d array
forgot to mention, lol, number-of-columns
is 1-indexed and column
is 0-indexed
consider for example {:a {:w {} :x {} :y {} :z {}} :b {:w {} :x ... ...} ... ... :d {... ... :z {}}
depending on what you are using the data for - this structure is friendly for get-in
for finding data at a specific nested index (and update via update-in
or assoc-in
)
Here’s the thing - I want to make a test to see if there are 3 in a row of one of the keys, vertical or horizontal. I am wanting to filter/remove those from the possible permutations. There are a metric-butt-load of permutations, effectively a lazy sequence.
(combo/count-permutations tiles)
; => 20922789888000
oh, OK
clearly I didn't understand what you were doing here
sorry! My fault.
you can use (partition 3 1 ...)
and map a function that detects repeats of column or row
that might not be straightforward to apply at the filtering step though
Yeah, I already have the function working that detects if 3 of a sequence of 4 is a match of either key.
But only for rows.
Hell, it might be easier to make a rotate 90 degrees function that takes the sequence [%1 %2 %3 %4 %5…. %16]
and converts it to [%1 %5 %9 %13 %2 … %16]
. I can hand-code that but it seems icky.
OK, I managed to rotate it using the for
statements mentioned above. Onward!
(defn rot90 [s]
"Takes a sequence of 16 vector pairs and rotates it 90 degrees."
(into [] (for [x (range 4)] (into [] (for [y (range 4)] (nth s (+ x (* y 4))))))))
@scotto does the same thing, more idiomatic:
(defn rot-90 [s] (apply mapv vector (partition 4 s)))
Sweet!!!
also it's immediately obvious how to parameterize it if your size ever changes from 4
(not familiar with the mapv
function… Looking that bad-boy up.)
map, apply, reduce, lifeblood of the sequentialist