This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-04-14
Channels
- # admin-announcements (5)
- # aws (3)
- # beginners (35)
- # boot (96)
- # cider (1)
- # clara (6)
- # cljs-dev (12)
- # cljsrn (34)
- # clojure (151)
- # clojure-boston (3)
- # clojure-brasil (4)
- # clojure-canada (1)
- # clojure-czech (8)
- # clojure-dusseldorf (11)
- # clojure-japan (5)
- # clojure-russia (120)
- # clojure-taiwan (1)
- # clojure-uk (3)
- # clojurescript (7)
- # component (27)
- # cursive (13)
- # data-science (45)
- # datomic (1)
- # devcards (5)
- # emacs (3)
- # funcool (65)
- # hoplon (103)
- # instaparse (3)
- # jobs (14)
- # jobs-discuss (1)
- # juxt (2)
- # lein-figwheel (2)
- # off-topic (16)
- # om (20)
- # onyx (49)
- # parinfer (17)
- # perun (1)
- # planck (5)
- # proton (4)
- # re-frame (14)
- # ring-swagger (4)
- # spacemacs (4)
- # untangled (110)
- # yada (14)
Hello!
Is it correct way return map with f and sql?
(defn- do-with-try-catch [f & sql]
(try
( {:f (f) :sql sql} ) ; <<<<<——— this is correct?
(catch java.sql.SQLException e
(jdbc/print-sql-exception-chain e)
(let [^String message (or (->> (.getMessage e)
(re-find #"(?s)(^.*)\s+\[[\d-]+\]$")
second)
(.getMessage e))]
(throw (Exception. message))))))
(defn process-structured
"Convert QUERY into a korma select
form, execute it, and annotate the results."
[driver {{:keys [source-table]} :query, database :database, settings :settings, :as outer-query}]
(let [timezone (:report-timezone settings)
entity ((resolve 'metabase.driver.generic-sql/korma-entity) database source-table)
korma-form (build-korma-form driver outer-query entity)
f (partial k/exec korma-form)
f (fn []
(kdb/with-db (:db entity)
(if (seq timezone)
(do-with-timezone driver timezone f)
(f))))]
(log/debug (u/format-color 'blue "\nSQL: 😈\n%s\n" (get-sql korma-form)))
;(log-korma-form korma-form)
(do-with-try-catch f, (get-sql korma-form))))
When I try to destructuring , I got null
(let [{driver-process-query :f sql :sql} (partial (if (structured-query? query) ; <<- driver-process-query, sql are null
driver/process-structured
driver/process-native) driver)]
@mrwhite: Hi, "rest" arguments of a function have to be passed in to a vec like this: do-with-try-catch [f & [sql]]
Depending on what sql is you will have to call it too in your map: {:f (f) :sql (sql)}
. But, tbh, I dont know what the purpose of that map is: {:f (f) :sql sql}
. It is not really making sense to me being wrapped into a SQLException, but maybe it is because I am lacking context.
Other than that you can add snippets here by pressing the + plutton on the left of the input field, it adds syntax highlighting to your code
@mrwhite: Or you can use a single backtick for inline code
and triple backticks for
multiple
lines of
code.
Also, I wouldn’t force rest
arguments to be passed as a vector unless you have good reason for it. I’d rather have a slightly more complex function that handles all comers rather than forcing callers to adhere to an expectation.
Hi everyone, I’m blowing my mind trying to understand macros. Could someone explain what is happening here?
(defmacro my-macro
([] '())
([x & next] (cons x (apply my-macro next))))
(macroexpand '(my-macro a b c))
;; expected => (c b a)
;; actual => (a)
Oh, I see you already have, @bojan.matic!
all i can contribute at this point is that you want your macro to look like this
(defmacro my-macro
([& args] (reverse args)))
that was my first thought as well, but then why doesn’t that blow up?
from within the macro definition, the macro itself is not yet a macro and still a function
Why would you want a macro that applies itself rather than just returning a transform of itself.
This answers my real question, but now I’m curious why you can’t call apply
on a macro if the macro is a function from the point of view of the macro.
hi guys, just starting with clojurescript and really need to clarify something.
If I'm making a multiple pages, does that mean I will have also a multiple .cljs? e.g. index.cljs, about.cljs, profile.cljs?
@cory: well you technically can, if you provide the two implicit args that macros have (&env and &form), so you could technically write
(defmacro my-macro
([] '())
([x & next] (cons x (apply my-macro nil nil next))))
usually if you feel the need to recur through a macro, just delegate that to a function
Implementing macros by delegating to rewrite functions is considered better practice by some anyway.
Thanks a ton for humoring me. So in my example, what is actually happening to produce (a)
? It is cons
ing a
to (apply my-macro ‘(b c))
, which is ending up as effectively (my-macro b c) and those are being treated as those implicit arguments?
this is an interesting gotcha
is it mentioned anywhere in some docs? how discoverable is this?
Hi there, I'm stuck trying to use multimethods default
s:
(defmulti to-home (fn [page] [(:app page) (:module page)]))
(defmethod to-home [:a :b] [page]
:first)
(defmethod to-home [:a :default] [page]
:second)
(defmethod to-home :default [page]
:default)
(println (to-home {:app :a :module :x})) ; => :default
Any idea what to write to dispatch on [:some-value *]
?