This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-10
Channels
- # adventofcode (9)
- # bangalore-clj (1)
- # beginners (130)
- # boot (6)
- # cljs-dev (8)
- # cljsjs (12)
- # cljsrn (3)
- # clojure (33)
- # clojure-brasil (3)
- # clojure-korea (4)
- # clojure-russia (150)
- # clojure-sanfrancisco (4)
- # clojure-spec (159)
- # clojure-uk (3)
- # clojurescript (100)
- # code-reviews (9)
- # core-async (1)
- # datascript (3)
- # dirac (58)
- # hoplon (8)
- # jobs-discuss (10)
- # luminus (18)
- # om (2)
- # onyx (14)
- # protorepl (19)
- # re-frame (34)
- # reagent (28)
@camdez yeah it was easy once i stopped screwing around with map - just another recursion over the list of lists
@camdez it's pure aesthetic anyway - just want to avoid (solve position instructions nil) or similar at the top level
anyone have a recommendation for making a really simple state machine? All the libraries seem pretty complicated. I'm using a basic loop/recur structure right now that works but i can't figure out a way inspect its state from outside.
@olslash: Not sure if it’s as simple as you want, but there’s a pretty good example of one in re-frame for CLJS - https://github.com/Day8/re-frame/blob/master/src/re_frame/router.cljc
if I have a piece something like this:
(fn [e]
(let [kc (or (aget e “which”)
(aget e "keyCode"))]
,,,
how can I improve it with core.match?
what the code does in this context doesn’t really matterActually I just realized that it actually may matter, since this particular piece is of CLJS (?)
@ag What do you mean with "improve". A simple case
statement is usually best, also goog.ui.KeyboardShortcutHandler
is fantastic
@rauh yeah, maybe “improve” not the right word here, I just wanted to understand how to use pattern matching for cases such above
as I said the code doesn’t really matter much. what if I have:
(let [v (or (foo e “x”) (foo e “y”) (foo e “z”),,,)]
@oli: Congrats on solving it! BTW, here’s what a reduce
-based rewrite of process-instructions
might look like:
(defn process-instructions' [start-pos instructions]
(reduce (fn [pos inst]
(let [next-pos (mapv + pos (next-move inst))]
(if (keypad-lookup next-pos)
next-pos
pos)))
start-pos instructions))
@oli: I’d probably break out the process of advancing one position on the board and then it becomes quite clean:
(defn advance
"Given a starting position and an instruction, compute the next position."
[pos inst]
(let [next-pos (mapv + pos (next-move inst))]
(if (keypad-lookup next-pos)
next-pos
pos)))
(defn process-instructions'' [start-pos instructions]
(reduce advance start-pos instructions))
Anyway, cheers! 🍻is there any way to acces a property of a java class by name? (. obj (symbol "myProperty"))
@spacepluk the clojure Reflector class probably has something for that
@spacepluk you don't know the property name until runtime? otherwise a macro could do it too
I was just playing with clojure.reflect/reflect
but I don't know what to do with the names after I get them, they don't seem to work with the dot interop form
@hiredman that may not work in Java 9 anymore :)
Should I use the compojure or luminus template when I first do web development in Clojure ?
If you want to start simple and learn how the “plumbing” works in Clojure, use Ring + Compojure and maybe Selmer for web page templates.
I would avoid a framework until you understand how the basic principles work.