Fork me on GitHub
#clojure
<
2016-12-10
>
oli04:12:30

@camdez yeah it was easy once i stopped screwing around with map - just another recursion over the list of lists

oli04:12:21

@camdez the two arity thing moves up to the function that calls process-instructions

oli04:12:44

@camdez it's pure aesthetic anyway - just want to avoid (solve position instructions nil) or similar at the top level

olslash06:12:00

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.

shaun-mahood06:12:20

@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

olslash06:12:54

oh interesting

olslash06:12:58

i'll read up, thanks

olslash06:12:48

yeah this is good, i think it'll work for my usecase with some mods

ag11:12:35

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 matter

ag11:12:58

Actually I just realized that it actually may matter, since this particular piece is of CLJS (?)

rauh11:12:23

@ag What do you mean with "improve". A simple case statement is usually best, also goog.ui.KeyboardShortcutHandler is fantastic

ag11:12:04

@rauh yeah, maybe “improve” not the right word here, I just wanted to understand how to use pattern matching for cases such above

ag11:12:15

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”),,,)]

camdez15:12:51

@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))

camdez15:12:13

@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! 🍻

spacepluk15:12:10

is there any way to acces a property of a java class by name? (. obj (symbol "myProperty"))

gfredericks16:12:46

@spacepluk the clojure Reflector class probably has something for that

gfredericks16:12:10

@spacepluk you don't know the property name until runtime? otherwise a macro could do it too

spacepluk17:12:27

yeah, that's the problem

spacepluk17:12:44

I'll try with Reflector

spacepluk17:12:28

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

Alex Miller (Clojure team)19:12:32

@hiredman that may not work in Java 9 anymore :)

hiredman19:12:33

yeah, a shame

arohner19:12:59

Why is that?

hiredman20:12:12

java 9 brings some stricter visibility controls with its module system

jmb21:12:53

Should I use the compojure or luminus template when I first do web development in Clojure ?

seancorfield21:12:27

If you want to start simple and learn how the “plumbing” works in Clojure, use Ring + Compojure and maybe Selmer for web page templates.

seancorfield21:12:48

I would avoid a framework until you understand how the basic principles work.

olslash21:12:38

anyone have tips for unwrapping errors thrown from a deref'd future?

(try
  @(future
    (throw (ex-info "test" {})))
  (catch Exception e
    (println (ex-data e)))) ;; this doesn't work

olslash21:12:16

i think maybe slingshot will do it but i wanted to avoid the dep

olslash21:12:07

oh is it .getCause?

olslash21:12:12

seems to work