This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-04-21
Channels
- # admin-announcements (2)
- # beginners (22)
- # boot (223)
- # cider (161)
- # cljs-dev (19)
- # cljsrn (4)
- # clojure (186)
- # clojure-austin (6)
- # clojure-beijing (1)
- # clojure-boston (3)
- # clojure-china (1)
- # clojure-czech (1)
- # clojure-france (1)
- # clojure-greece (10)
- # clojure-russia (17)
- # clojure-uk (154)
- # clojurebridge (3)
- # clojurescript (82)
- # component (12)
- # cursive (12)
- # datomic (71)
- # dirac (3)
- # editors (2)
- # emacs (29)
- # flambo (31)
- # hoplon (21)
- # immutant (11)
- # instaparse (17)
- # jobs (2)
- # jobs-discuss (2)
- # jobs-rus (1)
- # lein-figwheel (12)
- # leiningen (2)
- # off-topic (44)
- # om (78)
- # onyx (38)
- # parinfer (1)
- # re-frame (34)
- # reagent (32)
- # spacemacs (56)
- # untangled (74)
- # vim (12)
- # yada (2)
When I started using Clojure a few weeks ago, I didn't understand why require
needed a quoted vector, i.e., (require '[clojure.string :as string])
. Now, I still don't understand because I've never seen or used a quoted vector. So: why does require
need the vector to be quoted?
clojure.string presumably evaluates into a known thing, :as is a keyword, but string would evaluate to something unknown. and then there would be a symbol interred erroneously
presumably (and i really don't know for sure here) you are passing all this info to the macro which can do what it wants on its own with the raw info before the code is evaluated. the macro can form this into valid forms
@fasiha: what actually need to be quoted are the symbols inside the vector. before it’s been required, ‘clojure.string doesn’t map to anything, and neither does ‘string, as @dpsutton pointed out. quoting the whole vector is easier than quoting each symbol.
you do not need to quote the require vectors in the ns
macro, also, because the macro receives the unevaluated forms anyway
Well I'll be a monkey's uncle. (require ['clojure.string :as 'string])
does work as you say @loganmhb. So what I get from this is require
isn't a macro, like ns
You know how with some authors, you just have to be erudite to understand the various layers and allusions and subtexts of their writing? I feel that way when working with Clojure. I'm not a very learned person but somehow I feel like I have to think very hard when getting things to work in Clojure.
that's the way i've found lisps. I'm only a few weeks into clojure but i've done some elisp and some common lisp
the great thing about this is that your boss won't laugh in your face if you suggest putting a lisp into production when its on the jvm
but read peter norvig's book on ai. its in common lisp and its absolutely crazy. I'm halfway through
@dpsutton: I love that book. One of the BEST programming books I have read during my CS studies and it wasn't even on the curriculum.
@fasiha: you're not the only one having this experience. Some other newcomers find the Clojure docs a bit terse.
(= #(println %1) #(println %1))
can anyone explain why the above returns false?
i was expecting it to be true after all the value of values and PLOP talks
i understand it must be different references underneath, kind of like if you compare two array/list literals in something like ruby/python/js - even if they have the same data the equality is still false
clojure has that one solved
it would’ve been nice if it extended to functions too
my line of thought was that function equivalence should be easier for languages that are homoiconic
is that wrong?
@borkdude: but if i def two lists, they still compare to true
user=> (def a '(1 2 3))
#'user/a
user=> (def b '(1 2 3))
#'user/b
user=> (= a b)
true
@bojan.matic: function equivalence is an undecidable problem
It is not a Clojure problem, but a CS problem: http://stackoverflow.com/questions/1132051/is-finding-the-equivalence-of-two-functions-undecidable
but in lisp, functions are just lists, and we can already compare lists for equivalence
i think i see what you mean, function equivalence in the broader sense may be undecidable
but two functions with the exact same AST?
shouldn’t that be decidable?
@bojan.matic: like I tried to say, that should be decided at compile time, but =
is a function, so it can't
what about a macro that overrides = and at compile time can figure out if it’s passed all functions? 😄
trying to compare functions is just meaningless, there's no sane/consistent/possible/meaningful way of doing it
@bojan.matic: I couldn't resist
but can we do it without using fn+ in the body, but just plain old fn?
you need some way to hang on to the original form, which clojure doesn't do. Even if it did it wouldn't be terribly useful.
Hey all, how can I change the representation of a record in the REPL/println? Is there a protocol like toString
that I can implement?
user=> (defrecord X [])
user.X
user=> (defmethod print-method X [_ w] (.write w "FOOO"))
#<MultiFn [email protected]>
user=> (X.)
FOOO
I feel like this is probably an FAQ, but haven't found a good answer: any way to re-export a symbol from one namespace to another? Let's say I have a library foo
with several namespaces foo.ex
, foo.run
, foo.parse
but my clients would like to write a single [require foo.api :as foo]
and get all the symbols they need
i could just define vars and set them to the value of the vars in the other namespaces
(ns foo.api (:require [foo.parse :as parse])) (def stylesheets parse.stylesheets)
@telent: potemkin has import-vars
for that purpose, but I don't think that will help with rebinding https://github.com/ztellman/potemkin
in this particular case: I have a list of prefixes used in generating/parsing rdf triples. There is a default list with all the conventional prefixes, but some users may wish to add their own
right, I don't think there's a perfect solution to this. Personally I think it's fine to expose multiple namespaces. It also makes documentation friendlier
you could define all dynamic vars that you expect to be rebound directly at the top level. also not perfect though, as you'd have to watch for circular dependencies
What do people use for full-text search in Clojure? Is Lucene / https://github.com/clojure-cookbook/clojure-cookbook/blob/master/06_databases/6-05_text-search.asciidoc still state of the art?
pesterhazy: I'd go with elasticsearch - if that isn't overkill in your situation. Otherwise I'd say lucene is a good choice.
I used https://github.com/weavejester/clucy for lucene last time I was playing with it, worked fine up until the point where I decided that I didn't want full-text search after all
@schmir, it depends a bit on how hard it is to set up, ops-wise
@telent: using lucene directly seems like an elegant solution, though clucy hasn't been updated in a while
also I'm wondering what elasticsearch gives you in addition
@pesterhazy: i guess you could break it down to :it gives you the benefits of being distributed and having a set of common features implemented on top of lucene, which you normally would have to build yourself
@pesterhazy: Depending on your needs and existing environment, sometimes Postgresql's full text search is good enough: http://www.postgresql.org/docs/current/static/textsearch.html
Thanks, I'll check it out
Maybe there's an elastic search as a service
That might take away the ops issues
AWS has ES as a service
IIRC it’s a relatively old version ES but that might be the best option if you’re running on AWS already
I think I'll just use that then
I’m just wondering if I can’t use sth. `(require '[uncomplicate.fluokitten [core :as f/core] [jvm :as f/jvm]]) `
although the require completes ok, the repl doesn’t seem to recognize “f/core” - I assume the slash cannot be used in this case
f/core means var core in (aliased) namespace f
I don’t think you can have an alias with / in the name
using dots is supported in aliases so you cold use f.core and f.jvm
foo/bar is always either static method or property bar in class foo or var bar in namespace foo.
This mentions issues with pmap. https://rasterize.io/blog/clojure-the-good-parts.html It doesn't really say what the problems are though. Does anyone have more information on that?
@pesterhazy: You can get hosted Elasticsearch from https://www.elastic.co/cloud. There is also hosted Solr available. Whether you should use a hosted service, run Elasticsearch or Solr yourself, or just use Lucene as a library depends on what exactly it is you want to do.
@bsvingen: ideally I want to get things running in a day (product search), not too advanced but I do need a few features that Datomic fulltext doesn't provide
http://elastic.co looks great
I just want to get started quickly, I can always move things to self-hosted ES later
Unless all you need is non-distributed search within a simple application, in which case using Lucene directly should also be fine.
Hello, any recommended clojars to calculate the sha1_hex of strings ? (I need to create a signature as detailed in https://eu.api.ovh.com/g934.first_step_with_api, signin requests part)
I think last time I did that stuff I used the apache commons codec java classes directly
(defn md5 [s]
(let [algorithm (MessageDigest/getInstance "MD5")
size (* 2 (.getDigestLength algorithm))
raw (.digest algorithm (.getBytes s))
sig (.toString (BigInteger. 1 raw) 16)
padding (apply str (repeat (- size (count sig)) "0"))]
(str padding sig)))
this is code I've used to calculate MD5, shouldn't be hard to change to SHA1
looks convoluted though, maybe not the best approach (that's java.security.MessageDigest by the way)
oddly, can't find any actual evidence I've ever done this. if it's not on github did it really happen?
@pesterhazy: thanks I’ll check this. @telent I’m sure it’s hidden somewhere
@pesterhazy: probably a stupid question, but can I also use SHA1_HEX instead of MD5 or is just SHA1 supported ?
SHA1 will returns bytes, so you'll have to encode that in hex yourself (as in my snippet)
You could use https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/binary/Hex.html as well I think.
@pesterhazy: thanks for your help.
@pesterhazy: just replacing MD5 with SHA1 in your function did the trick.
My go-to for hashes is always Apache Commons Codec.
It has all the variants you could want: hex strings, bytes, etc.
@stuartsierra: thanks, this is good to know
SHA1 is on its way out and is no longer considered safe for many common cryptographic uses. E.g. browsers are starting to deprecate SHA1 in TLS certs. Someone should ask OVH to update their API.
(defn sha256 [body] (Base64/encodeBase64URLSafeString (.digest (doto (java.security.MessageDigest/getInstance "SHA-256") .reset (.update (.getBytes body)))))) (assert (= (sha256 "hello world") "uU0nuZNNPgilLlLX2n2r-sSE7-N6U4DukIj3rOLvzek"))
(:import [java.security SecureRandom] [org.apache.commons.codec.binary Hex Base64] [javax.crypto Mac] [java.security MessageDigest]
Not sure if buddy is using UTF-8... I feel like I get nailed by this madness when hashing unicode every time
Not sure if this is the right channel for this question, but how does someone get invited to the Clojarians team?
I'm running a simple clojure web site with compojure and ring. I build with lein ring uberjar
and run with supervisor and nginx in front of it. The first request is always slow due to creating the jvm. Subsequent quick requests are fulfilled quickly. After a while, it seems like the jvm "dies" so that future requests pay this overhead of waiting on the jvm to crank back up. Is there a simple fix to this that doesn't require switching to netty or tomcat for their keepalive features? Perhaps there's a java option that I can pass in saying just stay alive?
http://stackoverflow.com/questions/36774386/using-a-dynamic-variable-binding-in-a-leiningen-plugin Anyone got any ideas?
@loganmhb: I believe it is all running in the same thread. But that’s where the head scratching comes in.
I’m wondering if it has something to do with two separate codebases. There is the lein plugin source tree and a separate project that uses that plugin. When it was all in the same source tree it worked great. That’s really the only difference I know of.
depends on whether the lein plugin injects its codebase into the project as a dependency
I look clojure.lang.ISeq
and see that this interface requires next
and more
, but ASeq
defines more
in pseudocode as next || PersistentList.EMPTY
and i think it’s common sense.
Why when require definition of more
in interface? Can it be different from next
implementation?
they have different laziness guarantees, it is the difference between rest
and next
in clojure
@hiredman: could you bring example with different implementations? I look at LazySeq
and they’re almost same (except when reached end of seq - nil vs ‘() )
that is exactly the difference, one is guaranteed to return nil at the end of the seq, the other is not
the nil returning means you have to force at least one "cell" in the lazy seq, to determine if you can return nil or a lazy seq of more elements, the not returning nil means you can always just return the rest without any kind of check
there was a blog post someone wrote right before that got changed (this may have been pre 1.0) illustrating the laziness in seqs
Is there any special serialization I need to do for a ring handler? Or can I just return a clojure data structure and expect serialization to happen?
the ring spec says the return value of a handler is a map, that contains some special keys, and those keys are specified as being certain types
ahh ok I'll check it then. Was just returning a map of data I wanted to get to the client
the ring spec permits a limited set of types, but there are various middlewares people use to do automic serialization to json or edn or whatever
@hiredman: I got the thing about the end of seq, but still don’t about why do I need to implement more
in ISeq
when it’s always next || ()
@hiredman: ok, then could you bring example when they’re implemented differently and the reason why so
and the reason they are implemented differently is because they permit different amounts of laziness
i seem to be doing something wrong using clj-http.client
@hiredman: yep, but it could be not a part of interface, just implemented as next || ()
right in LazySeq
- nothing will change in behaviour, but we’ll not be forced more
be part of interface. or do I mistake?
I'm using
clj (client/get url {:query-params {:access_token "**token**" ...}})
and when it executes, it tells me that the "access_token" is missing
I even tried "access_token" too
@hiredman: I mean https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LazySeq.java#L77L89
thos are different, and they are different for the reason I keep repeating, they provide differing amounts of laziness
you are confused because you looked the the seqs implemented on top of fully realized collections, which have no laziness, so because those methods only differ in laziness, are the same for those collections
@hiredman: seem I’m missing something and should reread docs, but thanks for answers 👍
that write up is kind of dated, because it describes a pre-release state of something that in some form has been part of clojure for many many releases now
(and it referes to some other experimental work "streams" which never made it in to clojure)
I wish I could find the blog post that was making the rounds before that change was made in clojure, because if I recall it nicely illustrated the limitations of the old model, but my google-fu is weak
using faraday, I appear to be getting back URL-encoded strings. According to the dynamoDB console UI, the strings are not URL-encoded in the DB. Has anyone seen that?
@hiredman: @rohitarondekar reread Extension ISeqs
on link above, thanks, sorry for such RTFM