This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-24
Channels
- # adventofcode (13)
- # beginners (163)
- # boot (8)
- # cider (1)
- # clojure (86)
- # clojure-germany (1)
- # clojure-italy (2)
- # clojure-spec (66)
- # clojure-switzerland (1)
- # clojure-uk (25)
- # clojured (1)
- # clojurescript (58)
- # core-async (1)
- # cursive (4)
- # datomic (11)
- # events (1)
- # funcool (3)
- # hoplon (86)
- # off-topic (8)
- # om (11)
- # onyx (1)
- # protorepl (7)
- # re-frame (15)
- # ring-swagger (4)
Is there a way to track hosted nrepl server state changes like namespace creation or var binding without explicitly messing with op's code and tools.analyzer?
What i'd like to achieve is the clojure ref behaviour(add/remove-watch) for entire nrepl state
I managed to get the hello world to run and the jar too and finally figured out I did not specify the proper template š
@steverob Welcome to Clojure! You'll probably enjoy the #beginners channel where folks are very, very helpful and happy to work through step-by-step on issues. What's your background prior to Clojure?
Thanks @seancorfield š
A lot of Rubyists seem to move to Clojure -- but there are a lot of stark differences: Clojure doesn't do frameworks, but instead it favors composable libraries, which you may find a big surprise after Rails.
(and of course you're going from an almost OO-everywhere language to an almost FP-everywhere language š )
First spec problem. I have wrote this code :
defn ->long [s] (try (Long/parseLong s) (catch Exception _ ::s/invalid)))
(s/def ::page (s/and (s/conformer ->long) (s/int-in 1 471)))
(s/def ::optional-page (s/nilable ::page))
(defn home-page [page]
(let [page-num (or (read-string page) 1)
[page nil page-num (or (s/conform ::optional-page page) 1)] page-num
url ""
options {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True" :p page-num :ps 10}}]
(layout/render
(if (s/invalid? page-num)
(println "pagenumber is not right")
"home.html" {:paintings (-> (client/get url options)
api/read-numbers
api/fetch-paintings-and-images-front-page)}))))
what I try to do it that if someone enters a false pagenumber like "a" then I see a error message else the code will continue and some paintings are shown.
But now I see this error :
Caused by: clojure.lang.ExceptionInfo: Call to clojure.core/let did not conform to spec:
In: [0 2] val: [page nil page-num (or (s/conform :paintings2.routes.home/optional-page page) 1)] fails spec: :clojure.core.specs/local-name at: [:args :bindings :binding :sym] predicate: simple-symbol?
In: [0 2 3] val: ((or (s/conform :paintings2.routes.home/optional-page page) 1)) fails spec: :clojure.core.specs/seq-binding-form at: [:args :bindings :binding :seq] predicate: (cat :elems (* :clojure.core.specs/binding-form) :rest (? (cat :amp #{(quote &)} :form :clojure.core.specs/binding-form)) :as (? (cat :as #{:as} :sym :clojure.core.specs/local-name))), Extra input
In: [0 2 0] val: page fails spec: :clojure.core.specs/map-binding at: [:args :bindings :binding :map :mb] predicate: vector?
In: [0 2 0] val: page fails spec: :clojure.core.specs/ns-keys at: [:args :bindings :binding :map :nsk] predicate: vector?
In: [0 2 0] val: page fails spec: :clojure.core.specs/map-bindings at: [:args :bindings :binding :map :msb] predicate: vector?
In: [0 2 1] val: nil fails spec: :clojure.core.specs/map-binding at: [:args :bindings :binding :map :mb] predicate: vector?
In: [0 2 1] val: nil fails spec: :clojure.core.specs/ns-keys at: [:args :bindings :binding :map :nsk] predicate: vector?
In: [0 2 1] val: nil fails spec: :clojure.core.specs/map-bindings at: [:args :bindings :binding :map :msb] predicate: vector?
@roelof this has only slightly to do with spec, as spec is what generates the error output you are seeing. Also the error message says what is wrong: Call to clojure.core/let did not conform to spec. So your let macro is messed up. I would advise you again to turn on parinfer.
I am trying to make sense of that whole line: [page nil page-num (or (s/conform ::optional-page page) 1)] page-num
I copied it from this code from seanconferfiels :
boot.user=> (require '[clojure.spec :as s])nilboot.user=> (defn ->long [s] (try (Long/parseLong s) (catch Exception _ ::s/invalid)))#'boot.user/->longboot.user=> (s/def ::page (s/and (s/conformer ->long) (s/int-in 1 471))):boot.user/pageboot.user=> (s/def ::optional-page (s/nilable ::page)):boot.user/optional-pageboot.user=> (let [page nil page-num (or (s/conform ::optional-page page) 1)] page-num)1boot.user=> (let [page "42" page-num (or (s/conform ::optional-page page) 1)] page-num)42boot.user=> (let [page "a" page-num (or (s/conform ::optional-page page) 1)] page-num):clojure.spec/invalidboot.user=> (let [page "500" page-num (or (s/conform ::optional-page page) 1)] page-num):clojure.spec/invalid
here a better layout :
boot.user=> (require '[clojure.spec :as s])
nil
boot.user=> (defn ->long [s] (try (Long/parseLong s) (catch Exception _ ::s/invalid)))
#
boot.user/->longboot.user=> (s/def ::page (s/and (s/conformer ->long) (s/int-in 1 471)))
:boot.user/pageb
boot.user=> (s/def ::optional-page (s/nilable ::page)):boot.user/optional-page
boot.user=> (let [page nil page-num (or (s/conform ::optional-page page) 1)] page-num)
1
boot.user=> (let [page "42" page-num (or (s/conform ::optional-page page) 1)] page-num)
42
boot.user=> (let [page "a" page-num (or (s/conform ::optional-page page) 1)] page-num)
:clojure.spec/invalid
boot.user=> (let [page "500" page-num (or (s/conform ::optional-page page) 1)] page-num)
:clojure.spec/invalid
@roelof this line, is wrong.
(let [page-num (or (read-string page) 1)
[page nil page-num (or (s/conform ::optional-page page) 1)] page-num
or can I make this one like this
(let ] [page nil page (or (s/conform ::optional-page page) 1)] page
Iām trying to understand a convention Iāve not seen before:
(defn
^{:macchiato/middleware
{:id :wrap-restful-format}}
wrap-restful-format
ā¦
ā¦
ā¦)
The part I donāt understand is the part before the function name wrap-restful-format
that starts with the ^
. Can anyone explain what that segment is doing?there's nothing "wrong" with shadowing variables in a let, other than the person who comes along to read the code might give you a kick. that code would work (minus the extra ])
oke, I will try to make it work but I think spec is at this moment more then I can chew
spec is not the issue you're having here, you're misunderstanding how a basic clojure form (let) works. you're just getting a reasonable error about it from spec
@ezmiller that attaches metadata to a fn: http://clojure.org/reference/metadata
thanks @pesterhazy. and hello!
cljs.user=> (defn ^{:a :b} foo []) (-> #'foo meta :a)
#'cljs.user/foo
:b
hello ethan š
actually the metadata is attached to the var, not the fn
related (asked yesterday but nobody knew):
#{
^{:reason "Bogus nullary argspec; also general market metadata."}
#'amazonica.aws.ec2/describe-spot-datafeed-subscription
}
What is the :reason metadata attached to? Itās not the var.it's only available at compile time as metadata attached to the (var amazonica..)
list
I wonder what Iāll do with it; Iād like it to be available for introspection, but I guess maybe comments are good enough
another convention I am not sure about: (req->map node-client-request node-server-response opts)
. Whatās the ->
doing here in req->map
?
it's an arrow and means "to" š
@mpenet hi! Iāve seen your stuff! Iām trying to write a HTTP server in pixie, basing on nodeās http-parser lib. Iām stuck on the ffi part, or āwriting C in pixieā. Since the maintainers are unavailable, I was looking for someone who could explain few things to me.
but tbh I barely recall how adv. ffi stuff works in pixie. Your best bet is probably to dig into the source, or maybe try to ping @tbaldridge
@nooga I'm here
@tbaldridge Iām trying to figure out how to copy n bytes from CCharP and make that a pixie string or buffer
sure, the best examples to start with are probably here: https://github.com/pixie-lang/pixie/blob/master/pixie/io-blocking.pxi
@nooga pixie strings are unicode, so there's some conversion that has to take place, but you can look at the code for spit
and slurp
in that file to see how it's donw
What about copying memory? C land calls callbacks of type typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);
and I need to copy length
bytes from at
.
@nooga most of the code in pixie makes its own buffers, I'm sure it's possible to copy, but it's been way too long since I've been in this code.
@tbaldridge Yup, thatās what I noticed. Thatās why I couldnāt figure out how to copy from pre-allocated buffers just by reading the sources š
I have a data-analysis question. I have a CSV of timestamped power output measurements. So each row is a timestamp + milliwatts tuple. I want to detect 'types of peaks', ie. cluster them in an unsupervised manner. Ideally i would like to have like 8 groups that i then can label them. The signal data is from a 'smart plug' to which an electrical device is connected. I want to detect what is happening in the electrical device (ie. what function is running) and measure the total usage time of each function. There is some variance in the spikes, and some functions have quite similar-ish output. Anyone got any pointers? I know this is not a clojure question, but I will implement this in clojure š