This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-08-11
Channels
- # architecture (11)
- # bangalore-clj (1)
- # beginners (42)
- # boot (28)
- # chestnut (1)
- # cider (1)
- # cljs-dev (28)
- # cljsrn (7)
- # clojure (124)
- # clojure-austin (1)
- # clojure-italy (10)
- # clojure-russia (3)
- # clojure-spec (29)
- # clojure-uk (32)
- # clojurescript (62)
- # core-async (22)
- # data-science (7)
- # datascript (5)
- # datomic (8)
- # events (1)
- # fulcro (15)
- # funcool (1)
- # jobs (1)
- # keechma (10)
- # lein-figwheel (4)
- # lumo (4)
- # mental-health (1)
- # off-topic (21)
- # om (10)
- # onyx (8)
- # parinfer (29)
- # pedestal (1)
- # planck (4)
- # portkey (2)
- # protorepl (1)
- # random (1)
- # re-frame (12)
- # ring (3)
- # spacemacs (6)
- # uncomplicate (63)
hmm, is the clojure solution to hygeinic macros as follows: 1. if all vars had full path, we wouldn't have hygiene problems 2. thus `(... ) automatically adds the namesapce to any symbol
(defmacro not-working [x y z] (list 'list x y z)) (let [list "hello world"] (not-working-fun 2 3 4)) ==> compile time error /// $&*@($#& (defmacro working [x y z] (list 'clojure.core/list x y z)) ==> okay, it no longer calls the local env list
the point is this: if we want `(list x y ~z) to do the right thing, we need list to be bound when macro is DEFINED, not when macro is USED
@qqq that sounds pretty close to it, yeah - I wouldn't call it hygiene, but it's a lot safer than the approach in CL or elisp macros
I'm using pipeline-async and curious what the best way to handle errors is. Right now, if the function throws then it gets swallowed and goes no where. Separately, is there a better way of processing a queue than using pipeline-async?
@skaplan have you tried providing the error-handler arg to the chan you pass in?
oddly, I tried to test that but with my core.async version the exception shows up at the top level where I started the pipeline-async and doesn't reach the channel error handlers
of course, you can just try/catch in your af
I want the error to stop the pipeline. What's the best way to do that if i try catch in the af?
I wonder - one way would to be have a delay or promise which is realized in a catch block, and bail if it is realized in the af
that feels hackish though
hmm does anyone know whether it’s possible to forward-declare a namespace for sole purpose of using namespaced keywords under an alias ?
e.g. being able to use ::foo/my-key
without having to (:require [my.very.long.ns.foo :as foo])
i was thinking about using declare
and alias
, but i’m not sure whether that’s the best approach
@lmergen You could use foo
as namespace instead of alias: :foo/key
@juhoteperi but then i would have to use :my.very.long.ns.foo/key
, right ?
why do you need long ns if the ns doesn't really exist?
Ah no, I somehow misread the question
I somehow jumped to conclusion that the ns doesn't exists as you don't want to use require
i figured that if i’m able to just literally type the long-ns keyword and have things work, then i wouldn’t have to require the module either
aha, just doing (alias 'foo 'my.very.long.ns.foo)
does the trick, no forward declarations necessary
@lmergen this will not require file to exist:
(create-ns 'my.very.long.ns.foo)
(alias 'foo 'my.very.long.ns.foo)
so I was thinking that instead of trying to serve static files with Ring/Pedestal/whatever directly I could just push them to S3
which seems like a standard thing to do
the only non deprecated/maintained thing I found about this is amazonica
though
I don't really need the library for the whole S3 to just push some files to S3
what do you guys use for that?
This doesn't seem too bad:
(-> (AmazonS3ClientBuilder/defaultClient)
(.getObject bucket key)
(.getObjectContent))
am I doing multiarity macro right?
(defmacro or-based-coerce
([spec-name triples] `(or-based-coerse ~spec-name (constantly nil) ~triples)) ;;<= this bit specifically
([spec-name default-coerce-fn triples] ...)
Trying register or
spec, and create coerce function at the same time by providing [dispatch-key predicate coerse-fn] triples
@yonatanel here's an example of the actual thing I am trying to address https://clojurians.slack.com/archives/C1B1BB2Q3/p1502377408579283
Will something like this help? https://github.com/yonatane/spec-grind/blob/master/src/spec_grind/grind.clj#L33
does it do something like "s/nonconforming"? Then no. I want or
branches, I just don't want to keep spec and coerce function in sync manually
in case above – I need to have executable-id
and executable
as a separate specs, so the coercion needs to be separate from executable-id
.
I might be framing macro's purpose wrong, actually, since coerce fn in my example uses 2 different specs for validation, and coerces in-between. Macro as I write it now would stop after coercion, and I'd need to validate against the second spec "manually" afterwards. Which renders whole effort sort of useless :)
Are there any zprint gurus who know how I can make this:
(atlaskit/label #js
{:label "Search" :htmlFor "hipchat-search" :isLabelHidden true})
format like this
(atlaskit/label #js {:label "Search" :htmlFor "hipchat-search" :isLabelHidden true})
I basically want to force the thing after #js
to always be on the same line
Anyone have an implementation of ?->
and ?->>
lying around that I could borrow? (thread but stop threading when any intermediate value is nil)
I'm sure some of the utility libs must have these but seems http://crossclj.info is down and these are a bit tricky to google 🙂
I think some->
does that
how to use clojure bot 🙃
lol we can do this
maybe no
works on my machine 😛
yet another bug in the bot (it also treats strings as if they were symbols)
(this is clojure runtime, not source code) suppose I have ;; foo/bar.clj (ns foo.bar) (def xyz 20) ;; some other file (def my-var-name 'foo.bar/xyz) (???? my-var-name) ==> 20 what do I put in ???? to "resolve" the var ?
@qqq I think that's going to be a 2 step process. you need something to load the file and something to resolve the var
hmm, I tried (ns-resolve ns-sym hiccup-var) // got the var instead (var-get (ns-resolve ns-sym hiccup-var)) // worked [ there was a require executed earlier ]
so you had the var-get .. and it turns out I also need it, is the problem resolve returns a "VARIABLE CONTAINER" but not the actual value ?
yeah a var is not the value, the var is the container, you can get the value from the container 🙂
a subtlety about ns-resolve
- people assume it means "get this symbol which is defined in this ns" it actually means "look up this symbol as if we were currently in this ns" - subtle but sometimes significant
intern throws errors for this kind of thing - which is why we need refer-clojure clauses if we want to reuse those names
ns-resolve only looks up in the target ns
you have to give ns-resolve the symbol to look up - and the semantics of intern and namespace definition ensure that this symbol can only be resolved to one var
mind you this can be a namespaced symbol (and must be if they didn't use refer or use)
but if you know the precise ns and symbol, you can just use resolve
@noisesmith : I don't get the subtlety. What is a scenario where it differs from what I would expect ?
it means that the namespace of the var returned from ns-resolve doesn't have to be the ns used in ns-resolve
@qqq (ns-resolve 'my.ns '+)
returns #'clojure.core/+
(unless you didn't refer clojure.core in my.ns of course)
usually this doesn't matter, but the difference is worth noting
user=> (ns foo.bar)
nil
foo.bar=> (def x 20)
#'foo.bar/x
foo.bar=> (ns foo.baz)
nil
foo.baz=> (alias 'bar 'foo.bar)
nil
foo.baz=> (ns foo.bash)
nil
foo.bash=> (ns-resolve 'foo.baz 'bar/x)
#'foo.bar/x
(ns-resolve NS SYM) if SYM is defined in NS, return NS/SYM if SYM is NOT defined in NS, look at the use/requires of NS, and return whatever one would get by resolving SYM in NS ^^-- is that correct ? I guess the two above cases does simplify to "resolve SYM as if it was in NS"
in the context of a namespace, a symbol can have only one binding
a bare symbol that is. you can have many aliased or unaliased ways to refer to a symbol though.
exactly
so x can mean only one thing given a namespace context
fully-qualified symbols are always valid (assuming the namespace has been loaded)
aliased symbols depend on the current namespace context
and this is why I mention using resolve if you know the exact ns and var name - it doesn't have any of those extra concerns ns-resolve does about some other ns' aliases
to take the example @noisesmith gave: (ns-resolve 'my.ns '+)
returns #'clojure.core/+
. what if my.ns requires foo, which also defines +?
then you can only get it via the alias foo has
and you you tried to do (use 'foo) you would have gotten an error
if you had (require '[bar.foo :as foo]) you would look up 'foo/+
+ would return clojure.core/+, foo/+ would find foo+, just like if you were in the ns
so the full call would be (ns-resolve 'my.ns 'foo/+)
you'd get a compiler error on the refer all
unless you used refer-clojure to exclude +, then sure, yeah
right
thanks, i did not know that. i just can't wait for all my ns-resolve
code to break.
the docs for ns-resolve
are correct, people just misread or don't understand the implications or even more often don't read it and make some assumptions based on the name
there's clojuredocs which accepts submissions though
@noisesmith disagree. in the docs "resolve" is undefined, so "resolved in a namespace" (from ns-resolve) is ambiguous. the docs for ns-resolvee' and
resolve` are circular.