This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-19
Channels
- # admin-announcements (2)
- # beginners (25)
- # boot (93)
- # cider (2)
- # clara (2)
- # cljs-dev (63)
- # cljsjs (3)
- # cljsrn (38)
- # clojure (142)
- # clojure-austin (1)
- # clojure-brasil (2)
- # clojure-czech (1)
- # clojure-dev (7)
- # clojure-greece (1)
- # clojure-russia (170)
- # clojure-spec (11)
- # clojure-uk (65)
- # clojurescript (46)
- # clojurex (1)
- # code-reviews (3)
- # cursive (11)
- # datomic (35)
- # euroclojure (6)
- # events (2)
- # flambo (2)
- # hoplon (115)
- # instaparse (11)
- # jobs (21)
- # jobs-rus (3)
- # lambdaisland (2)
- # off-topic (17)
- # om (35)
- # onyx (161)
- # planck (1)
- # protorepl (7)
- # random (1)
- # re-frame (31)
- # reagent (19)
- # ring-swagger (21)
- # rum (5)
- # spacemacs (3)
- # specter (25)
- # test-check (20)
- # testing (7)
- # untangled (2)
- # yada (50)
can a clojure.core.async/sub
be used on multiple topics?
apparently it is not something to do, as I receive multiple copies of my messages..
(or I am doing something wrong of course)
@credulous: as a simplistic approach, you could simply scrape the data off Twitter using clj-http and a Twitter search Url. Here is an example created for a dojo a while back https://github.com/weavejester/dojo-poetry/blob/master/src/poetry/core.clj
The streaming api is probably better for this kind of stuff, no need to keep cursors etc, should take no time using one of the twitter api java wrappers (I used to do this with twitter4j)
the other one is https://github.com/twitter/hbc but I just played with that one, can't vouch
Hey, I'm pretty new to Clojure web deveopment, and I'm running into a problem I'm not finding anything helpful for online. I'm trying to use compojure-api to auto-generate documentation for an api I'm building, and it works as long as the endpoint doesn't have a :return. However, if it does, the response fails any validation I give it with (not ({whatever predicate} a-java.io.BufferedInputStream))
@dkuykendall: Check you don't have duplicate middlewares encoding the response before c-api does the validation
@mpenet: I’m assuming you would have to have an agreement in place with twitter and access to the stream?
that’s perfect for testing stuff though. We have a hypothesis that we want to test before paying..
@dkuykendall @juhoteperi if the endpoint returns a Stream, it will not be read back into clojure data by c-api for validation and the response validation not work. Either disable the response coercion (and just get the docs) or make the endpoints return clojure data structures - will be encoder later automatically by the ring-middleware-format. (There is also #C06GSN6R2)
does anyone have any good resources on JVM Reflection that would be helpful in gaining a deeper understand of how Clojure uses it? I was failing to explain the benefits of using a type annotation like ^java.util.Date
other than just saying “it’s more performant”. I’d like to understand more about reflection and how the JVM handles it
oh cool, thanks @blueberry
Guys, why
(var abc/def)
works ok, but
(var (eval ‘abc/def))
throws error like
clojure.core/eval core.clj: 3081
...
java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol
clojure.lang.Compiler$CompilerException: java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol,
How to get var from symbol?@madvas clojure.core/resolve
?
@anmonteiro: yep, that’s what I've searched for, thanks a lot!
how can i alias a function in a different namespace but keep the original docstring?
(defn alias-with-meta [qsym] (def ~(with-meta (name qsym) (meta (resolve qsym))) (resolve qsym))
thanks
@danielstockton you may also find inspiration in the import-vars
of https://github.com/ztellman/potemkin
In 1.9.0-alpha10, is map destructuring not going to be backwards compatible? For example, in clojure 1.9.0-alpha10:
(let [{:keys [foo/bar]
:or {foo/bar [1]}} {}]
bar)
=> nil
And in 1.8.0:
(let [{:keys [foo/bar]
:or {foo/bar [1]}} {}]
bar)
=> [1]
thanks @timothypratley, can definitely work it out from that
@kenny you are correct that the behavior is different (and that’s intentional). the prior behavior was accidental and broken.
the keys of the :or
should always be the symbols to bind locally (not keywords or qualified symbols)
Clojure 1.9.0-alpha11 release: https://groups.google.com/forum/#!topic/clojure/_slHTn-Ej1Y
speaking of ^^ it contains a new spec for let
that will detect the issue above at compile time
yes, should affect anything that uses destructuring pretty much
@alexmiller: That link to Maven is a 404 — I assume Alpha 11 just hasn’t quite made it there yet?
yeah, maven central updates on a batch process so it takes as much as a day
but the download is available
@kenny the nice part of having a spec for destructuring is you can reuse it :)
@kenny most macros that use destructuring expand to use let
so they automatically get these checks. defn/fn/etc are a little different as they don’t use let
@alexmiller: This link gives me a 404 from nginx https://repo1.maven.org/maven2/org/clojure/clojure/1.9.0-alpha11/
is this different from the conversation we just had?
that link won’t work for maybe a day. the artifact download will work in lein/etc now.
Ah, I misunderstood what you meant about the download...
…yes, indeed, Boot can download it. I didn’t realize that the downloads became available before they show up on Central like that.
yeah, it’s weird
I don’t send out the announcement till it’s downloadable
(slightly off topic) Isn’t there a development HTTPS proxy that handles self-signed SSL certs for you? I know there are manual hacks, but I’m thinking of an app with a brandname a website
@arohner An intercepting proxy? Burp supports that (https://portswigger.net/).
I know there are lots of manual workarounds, but I was thinking of a tool specifically designed for that purpose
Looking for Clojure(Script) Dev’s in the YEG (Edmonton, Alberta) area for a meetup. Trying to get a count of interested parties. Contact Me 🙂
any suggestions for something like Incanter without the macros and $weirdness?
@chrisjd looks like I wanted tunnelss: https://github.com/rchampourlier/tunnelss
I'm trying to figure out how to have some of my test classes return truthy for various metadata as suggested in lein-test-refresh https://github.com/jakemcc/lein-test-refresh/blob/master/CHANGES.md#040
oops.. sorry figured it out... (ns {:meta "goes here"} my-namespace ) ... that's pretty damn cool
Are there known limitations on using with-redefs
with protocol methods? I’m seeing something odd, in tests where the non-redefed method is getting invoked. Interestingly, if I reload the method with the protocol and the defrecord
, then re-run my tests, it all works correctly again.
This is extra confusing, because it is test code that used to work reliably, and I’m unaware of what changed to undermine the tests. Clojure 1.8.0 BTW.
So I'm experimenting with clojure.spec, and although I definitely appreciate how namespaced keywords protect against ambiguity, I'm concerned about constantly accessing properties as (::grid/x cell)
instead of (:x cell)
, for example. It just feels a bit verbose. Maybe in practice, you end up not noticing it? After all, people get great work done in much more verbose languages than Clojure...
Personally I've moved almost entirely to namespaced keywords and I really like it
I do think a keyword :x
is maybe worst-case scenario for that kind of thing
I guess the idea is that a) you abbreviate your aliases as much as possible, e.g. ::m/accessories
instead of ::motorcycle/accessories
.
And even if you have to be a bit verbose, using the namespaced keyword kind of proves you're doing the exact right thing? Even without clojure.spec.
And yeah, :x
is kind of unfair, since it has a pretty well-agreed-upon meaning.
I like that it gives you a little instant documentation throughout your code
Well, at least if you're clojure.spec-ing everything, you can look at a namespace and see all the keywords it defines, if not exactly how they're all used.
I'm also using datomic a lot more than I used to, so going into and out of the datastore tends to be in that format anyways
@hlship if the code in the body doesn’t execute until after with-redefs returns, it’s possible the bindings have been re-set.
I haven't looked at it, but I would be kind of surprised if with-redefs worked with the edge cases inherent in protocol functions
I don’t think that’s the case here, but there is some core.async involved, but I’m using <!!
to block until it’s fully executed.
it’s not like bindings
where you have reliable dynamic scope
with-redefs was written against regular var linkage, protocols extend var linkage in a few ways
Consider the following:
(defn foo ^String [^long x]
"")
(.length (foo 10))
;;=> ReflectionWarning: (...) reference to field length on java.lang.Object can't be resolved
However, if I remove the type hint on x
, I get no warning. Why does it affect the type hint on the return value?you should try replacing your protocol call with (apply protocolFn [args])
, and when/if that makes with-redefs work, then you know the issue is with differences between var linkage and protocol linkage
for a longer term work around (I am just thinking that might be useful for diagnosis), you can indirect the protocol call through a regular function(which means a single callsite cache which could negatively impact performance) and with-redef that regular function
moxaj: a ^long primitive type hint on a function argument is a newer language feature. the addition of being able to type hint function arguments with primitives (and have the arguments actually be passed as unboxed primitives) was added along side the already existing type hinting system. The edges of the two type hinting systems didn't entirely match up, so there has been an on going effort to make them work together.
in the original style of type hinting, the ^String type hint would go on the var name, not on the argument list, and in the new primitive type hinting you would type hint the arg vector with the return type
the fact that ^String works on the arg vector is the result of the work that h as been done trying to unify the two
Clojure 1.9.0-master-SNAPSHOT
user=> (set! *warn-on-reflection* true)
true
user=> (defn foo ^String [^long x] "")
#'user/foo
user=> (.length (foo 10))
0
(http://dev.clojure.org/jira/browse/CLJ-1533 is the ticket I was thinking of for 1.8)
@bronsa just fired up a repl just to make sure it's not the editors console messing with me - and I get a warning
ok, not a regression apparently -- I can repro with direct linking disabled but not with direct linking enabled
@moxaj: don't think there's a ticket open for this one, can you open one? I'd like to take a look at it in the next few days if I have time
@bronsa I don’t see any difference with direct linking and looks the same on 1.7/1.8/1.9
the .length call is a primInvoke and will go through one of the IFn interfaces so will be typed as returning an Object at that point
[~/.m2/repository/org/clojure/clojure/1.9.0-alpha11]> java -jar clojure-1.9.0-alpha11.jar
Clojure 1.9.0-alpha11
user=> (set! *warn-on-reflection* true)
true
user=> (defn foo ^String [^long x] "")
#'user/foo
user=> (.length (foo 10))
Reflection warning, NO_SOURCE_PATH:3:1 - reference to field length on java.lang.Object can't be resolved.
0
user=> ^D
[~/.m2/repository/org/clojure/clojure/1.9.0-alpha11]> java -Dclojure.compiler.direct-linking=true -jar clojure-1.9.0-alpha11.jar
Clojure 1.9.0-alpha11
user=> (set! *warn-on-reflection* true)
true
user=> (defn foo ^String [^long x] "")
#'user/foo
user=> (.length (foo 10))
0
@alexmiller @bronsa whoops, already made the ticket, feel free to edit: http://dev.clojure.org/jira/browse/CLJ-2005
I think that tracks, the direct linking call will generate a custom method that can return String, where as with direct linking disabled, you get a primInvoke returning Object, and because the two tagging systems don't exactly meet up, the String type info is lost
public static java.lang.Object invokeStatic();
descriptor: ()Ljava/lang/Object;
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=2, locals=0, args_size=0
0: ldc2_w #12 // long 10l
3: invokestatic #18 // Method test$foo.invokeStatic:(J)Ljava/lang/Object;
6: checkcast #20 // class java/lang/String
9: invokevirtual #24 // Method java/lang/String.length:()I
12: invokestatic #30 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
15: areturn
LineNumberTable:
line 5: 0
line 5: 9
vs
public static java.lang.Object invokeStatic();
descriptor: ()Ljava/lang/Object;
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=3, locals=0, args_size=0
0: getstatic #15 // Field const__0:Lclojure/lang/Var;
3: invokevirtual #20 // Method clojure/lang/Var.getRawRoot:()Ljava/lang/Object;
6: checkcast #22 // class clojure/lang/IFn$LO
9: ldc2_w #23 // long 10l
12: invokeinterface #28, 3 // InterfaceMethod clojure/lang/IFn$LO.invokePrim:(J)Ljava/lang/Object;
17: ldc #30 // String length
19: iconst_0
20: invokestatic #36 // Method clojure/lang/Reflector.invokeNoArgInstanceMember:(Ljava/lang/Object;Ljava/lang/String;Z)Ljava/lang/Object;
23: areturn
LineNumberTable:
line 5: 0
line 5: 12
line 5: 17
hmm, I tried it a different way, maybe I misspelled the property. I can repro your direct linking result.
ah. I think it has to do with invokePrim calls being rewritten by the compiler as (foo 1)
-> (.invokePrim foo 1)
and thus losing the var info vs invokeStatic calls using a StaticInvokeExpr
and thus keeping and using the var's :arglists
info
the interesting thing about watching the gradual melding of the primitive type hints and the Original Type Hints, is as they mesh together more and more, the places where they don't mesh come as more and more of a surprise to users
i’ve racking my brain with something i really don’t know, i have #’myns/foo generated from (ns-resolve ns (symbol (name :foo)))
If you have a var, deref returns what it holds
Just like every other state construct - atom, etc