This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # admin-announcements (1)
- # aleph (3)
- # beginners (72)
- # boot (67)
- # braveandtrue (1)
- # cider (17)
- # cljs-dev (8)
- # cljsfiddle (2)
- # cljsjs (1)
- # cljsrn (2)
- # clojure (19)
- # clojure-greece (1)
- # clojure-russia (42)
- # clojurescript (15)
- # core-logic (10)
- # cursive (6)
- # datomic (2)
- # hoplon (349)
- # kosmos (3)
- # lein-figwheel (3)
- # om (52)
- # onyx (3)
- # overtone (1)
- # parinfer (11)
- # proton (11)
- # protorepl (3)
- # reagent (29)
- # ring-swagger (2)
- # spacemacs (1)
- # testing (3)
- # uncomplicate (1)
I’d like to time an arbitrary function, send the time taken off via side-effect (to the SGG stack incidentally) and then return the result of the called function: Thusly:
So far in my ignorance I’ve tried:
(time-a-function '(db/get-record )); => returns record
however, simply using
(defn time-a-function [metric-name expression] (def start (System/currentTimeMillis)) (def result (eval expression)) (send-to-sgg metric-name start) result)
evalruns into namespace issues and I am guessing is the wrong tool for the job. Would anyone have any recommendations?
def creates a global / top-level Var so you don't want to use it inside a
defn. Since you just want local bindings, you want
Second, since you want to pass in code that you want evaluated in place, you'd probably want a macro for this...
(defmacro time-a-function [metric-name expression] `(let [start# (System/currentTimeMillis) result# ~expression] (send-to-sgg ~metric-name start#) result#))
Of course…. thank you. I believe you’ve already answered my next question about getting the start time too.
Hope that at least gets you going in the right direction, even if it doesn't actually work.
Absolutely. I’ll start fiddling with it and go from there. I think I understand backticks in macros, but I’m going to have to do a bit more reading to fully understand the rest of the symbols and their applicability.
Sometimes things that seem like a no-brainer can be hard in FP, and things that seem really difficult are easy.
For Haskell that’s really true. I’m finding Clojure to be not all that much of a jump from JS
One other question if I may. I’ve noticed that my use of
macroexpand works on things like
->, but fails to expand the macros I write. Is this expected behaviour?
Ah hell… My apologies, I’m going to have to run. It is a problem which can wait. Thank you for your help.
Hey, I'm working through Clojure for the Brave and true. Does this look right for implementing map using reduce? I first didn't use vectors and just reversed the list, but I'm not sure if this is better...
(defn map-reduce [function data] "An implementation of map using reduce" (seq (reduce (fn [x y] (conj x (function y)))  data)))
I think the basic idea is that map and reduce are similar. reduce acting as a map builds a collection with f applied to each element of that initial collection
Took me a minute (too much food in me at the moment, moving slow), but I think an implementation like this is the idea:
(defn map-in-reduce [f coll] (reduce (fn [coll elem] (into coll [(f elem)]))  coll))
so you're basically removing reduce's generality by deciding in advance what the reduction will be.
(reduce + 0 (range 5)) is supplying a reduction of
(fn [total elem] (+ total elem)) for example.
There’s a general principle here that you can create a more general function that can be used to implement both
It’s been a while but I think I was looking first at a function like this
(defn chn [c h n l] (if (seq l) (c (h l) (chn c h n (rest l))) n))
And then a function
r that generalized the end-of-sequence test and the rest-of-sequence test… that took two more functions.
(defn map [f l] (chn cons (comp f first) nil l)) I think and
(defn reduce [f i l] (chn f first i l)) or something...
r was something like this
(defn r [p c h t n l] (if (p l) n (c (h l) (r p c h t n (t l)))))
I assume to some degree, so I guess a better phrasing is, is there a place to learn the convention being used?
I don’t know about conventional but those were acceptable names back in the 80’s when I was doing my postgrad work on FP… I don’t know whether I made them up or whether I got them from a book...
This was what I learned a lot of this stuff from http://www.amazon.com/Recursive-Programming-Techniques-Systems-programming/dp/0201144506
And this one http://www.amazon.com/Functional-Programming-Application-Implementation-Henderson/dp/0133315797/ref=pd_sim_14_5?ie=UTF8&dpID=41FBKJR4OvL&dpSrc=sims&preST=_AC_UL160_SR107%2C160_&refRID=16J17V5A2VKFQHTRJW8V
ok, I just dropped that into light table and with syntax highlighting and tabbing it reads easier
I think it's technically github flavored markdown? I've had triple-backticks fail on me to make block code before.
Yeah, I know about blocks of code — but want I really want is paren matching 😄 — I’m so spoiled by paredit mode in Emacs!
since it is now possible to make an interactive repl in clojurescript, somebody should make a clojure specific developer chat website that can also evaluate your code, and provide syntax highlighting and parinfer functionality. that would also make it really easy to discuss ideas with other people in a dynamic way as you can actually run some code and have them see what that does
when I was learning haskell the irc channel had something called lambda bot which could eval arbitrary expressions
See also #C0J20813K I think which was one of the projects that spun out of the community discussions (and, I believe, is on the schedule for Clojure/West).
sometimes just browsing the history and seeing the ridiculously smart solutions people came up with to solve problems others had helped me learn a ton
The freenode IRC channel for Clojure has at least one bot that evaluates Clojure expressions and reports them back… I thought there was such a bot here as well…
yeah thats true, but I feel like it can be really useful especially on a beginners channel where people might have a conceptual misunderstanding of how something works, and being able to demonstrate the way things evaluate can be exactly what somebody needs
You can go into a DM with @slackbot and use the
/clj command there if you want to experiment.
hey how do you use a npm library in clojurescript, as in on the front end not on the server
I used to use webpack for that, but now I am not sure how to go about this, I tried using lein-npm but it I am not sure how to make the modules available on the browser