Fork me on GitHub
#clojure
<
2016-09-05
>
didibus00:09:39

@gws Exactly what I wanted, thanks

aengelberg04:09:20

I have a few questions about transit. (There doesn't seem to be a better channel to discuss this) - What is the difference between rep and stringRep methods of a write handler? i.e. when would I expect one to get called vs the other? (that doesn't seem well documented on transit-format) - Is it typical / advised to implement a write handler with different rep and stringRep methods (where rep does not return a string)? - If so, do I need to implement my read handler for a given tag so that it can take either the rep or stringRep formats?

rui.yang07:09:05

a question about write macro, can someone point me how to do the following?

rui.yang07:09:25

(defmacro def-handler [name f]
    `(def ~name
       {:enter ~(fn [a] (f 10))}))

rui.yang07:09:25

basically what I want to do is to: define a var pointing to a map. the value of the key is a function with wrap another function passed as second parameter to the macro

rui.yang07:09:50

I don’t know how to quote or unquote (f 10) in above example

rui.yang07:09:10

how to recognize f is a function passed to macro.

hiredman07:09:50

@rui.yang: you are unquoting the whole fn form, when you should just unquote the f

hiredman07:09:26

(fn [a] (~f 10))

hiredman07:09:54

you'll also need to gensym the paramter

rui.yang07:09:00

that doesn’t work

hiredman07:09:16

(fn [a#] (~f 10))

rui.yang07:09:27

(defn add [a] (+ a 10))
(defmacro def-handler [name f]
    `(def ~name
       {:enter ~(fn [a] (f 10))}))
(def-handler h add)
((:enter h) 20) ;; => 30

rui.yang07:09:38

the above codes are used to test this

hiredman07:09:06

the fn form you have sort of works, because you have fallen in to an edge case in the compiler

rui.yang07:09:13

it did work

rui.yang07:09:21

I need to use a# to gensym

hiredman07:09:38

but you are emitting a fn object instead of a form that when evaluated returns a fn object

hiredman07:09:08

syntax quote namespace qualifies symbols

hiredman07:09:46

unless you use the auto gensym feature, which is when you syntax quote a symbol with the suffix #

rui.yang07:09:20

@hiredman thanks, I will have another try to see it can do what I want 🙂

hiredman07:09:26

(fn [~'a] (~f 10)) would also work, but is not as nice

dominicm10:09:07

@grzm I just ran into http://seespotcode.net/2016/08/16/figwheel-reloaded/ We came up with a different solution though. For just refresh, simply setting your refresh dirs with: (clojure.tools.namespace.repl/set-refresh-dirs "test" "src") should work, as an inclusive set of directories you want to bring in. Looks like the #boot guys ran into this sometime last year. And came up with this solution to the problem: https://github.com/boot-clj/boot/wiki/Repl-reloading#problems-with-setting-refresh-dirs Something similar in Leiningen should work, based on your directory listing functions.

dominicm10:09:44

It's particularly potent with https://github.com/juxt/bidi as it includes protocols and such, which with the wrong reload order breaks your entire site on refresh.

dominicm10:09:46

On further digging, I'm not sure about the method involving user.dir, I don't think it solves this particular problem completely. As cljs output files are in user.dir, so I stand by my original solution ("test" "src")

donyorm11:09:01

so I'm implementing a web app in clojure/script and I was wondering if I should use om (in clojurescript) or enlive (in clojure) for creating the pages. The website is similiar to a forum, so mostly static but some buttons and stuff to press.

donyorm11:09:17

Does anyone have any thoughts on what would be best?

slipset11:09:05

@donyorm it depends… If you’re doing this to learn “How to write a web-app in clojure”, I’d start out with enlive, and keep clojurscript on hold for a while. If this is a production system which might want to have several clients (mobile, web, what have you), a restish kind of api would be usefull, and implementing the frontend in Om would make sense.

slipset11:09:58

IMNSHO, I find that people way to often reach for spa’s when plain old html generated on the server with a wee bit of jquery would do the job perfectly.

donyorm11:09:55

It's kind of a mix of both. I'm definitely learning clojure, but I wouldn't mind this being actually useful. I'll probably go with enlive, since I don't think I'll be doing javacript intensive work

donyorm11:09:23

I've heard that jquery doesn't work with clojurescript, is that true? Should I even bother using clojurescript for relatively simple tasks?

donyorm11:09:50

(I've done a small web app using luminus, but I used normal JS, so I haven't looked into clojurescript as much)

donyorm11:09:50

That works. Thank you!

donyorm12:09:59

Enlive hasn't been worked on for a couple of years, and is still using clojure 1.5. Is that something to be concerned about?

slipset12:09:49

I’ve been happy with hiccup

donyorm12:09:44

Hiccup seemed like a ton of typing for creating a whole html page, though it seemed like it would be useful for shorter snippets

akiva12:09:33

I use hiccup almost exclusively. I like how Clojure-esque it is. I’ve always disliked Selmer/handlebar-style solutions that bury code snippets inside of markup. Hiccup requires a bit more upfront work but you can compose snippets together to form full pages to keep things DRY.

donyorm12:09:20

yeah @akiva that's part of what I liked about om and/or enlive. But maybe I look into hiccup more then. Om was very slick, but felt like it was possibly more than I needed

akiva12:09:56

I’m a fan of Om but it is heavy, especially syntax-wise, but worth the work for a massive/complex SPA. Keep an eye on Om-Next, however; it’s going to be severely bad ass. Currently, I’m using re-frame/reagent for smaller projects.

amacdougall14:09:13

I know I'm tapping into a classic source of Java pain here, but I'm generating some SVG, and I naively started feeding literals like 10 into calculations which included division. Then my tests start failing because even when everything adds up perfectly, (not (= 10 10.0)). Is the correct move to just use float literals in every context that is not guaranteed to be ints only? I've spent a bit too long working with languages that were a bit more cheerful about converting between types...

mpenet14:09:02

you can use ==

amacdougall14:09:18

Interesting, I never knew about ==. And it doesn't surprise me that it's not perfect either... but I guess I'll use == and see what happens in real life. I doubt I'll ever be seeing numbers larger than a few thousand, since I'm just rendering SVGs of relatively small graphs. Thanks for the tips!

amacdougall15:09:26

Bah, I'll have to extend that to collections!

(= [1 2 3] '(1 2 3)) ; true
(= [1 2 3] '(1.0 2.0 3.0)) ; false
(== [1 2 3] '(1.0 2.0 3.0)) ; ClassCastException

amacdougall15:09:35

(defn equal-numbers? [c1 c2]
  (every? #(apply == %) (partition 2 (interleave c1 c2))))
This does the job, anyway. Perhaps there's something easier.

madstap16:09:23

Any common lisp wizards here? I'm trying to use cl-format to format money. I want (f 12345) ;=> "12,345.00". I get the decimals with "~$" and I get the comma separators with "~:D". How do I combine them?

madstap18:09:21

Yeah, i just went and used java ¯\(ツ)/¯. #(.format (java.text.DecimalFormat. "#,###,###,###.00") %)

noprompt18:09:20

when 1.9.0 is no longer alpha will specs defined by clojure.core e.g. :clojure.core.specs/bindings be reliable for use? ie. i'm writing a macro and i want to support the bindings form as defined by :clojure.core.specs/bindings; can i rely on it for parsing, etc.?

noprompt18:09:12

(my presumption is no.)

andrepnh18:09:50

@noprompt IIRC, I think alexmiller mentioned that yes, you could

andrepnh18:09:07

you might want to check #clojure-spec thou

noprompt18:09:52

that's good to know.

Alex Miller (Clojure team)18:09:54

The idea is that they are public specs for core and you can build on them

Alex Miller (Clojure team)18:09:30

I don't expect them to change dramatically

jannikko19:09:58

This has probably been asked before but, is there an easy way to generate urls from compojure routes? I am building a rest api and want to have links to other resources.

andrepnh20:09:30

@jannikko do you want those links for api documentation purposes, or something else?

jannikko20:09:14

@andrepnh No I want to include them in my response, to link to a related resource.

jannikko20:09:37

And I don’t really want to hardcode them or define another function to create them

jannikko20:09:30

I know that bidi was created for these kind of things but I really want to stick to compojure

andrepnh20:09:59

mm, I'm afraid I don't know how to do that 😕

andrepnh20:09:10

have you tried #ring ?

jannikko20:09:21

I mean I am using compojure with ring

jannikko20:09:33

I use compojure to define my routes

andrepnh20:09:53

I meant looking for help at the #ring channel

jannikko20:09:53

Oh right 😅 thanks

andrepnh20:09:07

nice, looks promising

dpsutton21:09:44

is there a good way for documentation?

andrepnh21:09:04

@dpsutton api documentation?

andrepnh21:09:17

you could try something with swagger

dpsutton21:09:23

wow impressive. thanks