This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-01
Channels
- # announcements (5)
- # beginners (151)
- # calva (4)
- # cider (32)
- # cljdoc (27)
- # cljsrn (2)
- # clojars (15)
- # clojure (66)
- # clojure-houston (2)
- # clojure-india (1)
- # clojure-italy (3)
- # clojure-uk (7)
- # clojurescript (15)
- # data-science (1)
- # datomic (2)
- # fulcro (6)
- # off-topic (24)
- # pedestal (1)
- # re-frame (20)
- # reagent (3)
- # remote-jobs (4)
- # rewrite-clj (2)
- # shadow-cljs (9)
- # spacemacs (5)
- # tools-deps (4)
- # vim (1)
- # yada (4)
ok, so if I got this right
- comp
given only transducers returns a transducer
- comp
given only functions does function composition
- comp
given a mixture of transducers and regular functions doesn't work
Now I don't understand why the code above with ->>
works... I just saw it as doing the same as comp
but in reverse.
because ->>
is a macro, does it take the forms given to it and actually "physically" put the output of the previous line as the last argument in the next form?
sort of runs partial
on all the forms?
->>
is purely syntactic rewriting. There's no semantics involved. (->> (+ a b) (let [a 1 b 2]))
=> (let [a 1 b 2] (+ a b))
I need to remember that (= ((comp (partial map inc)) [1 2]) (->> [1 2] (map inc)))
comp
with a single argument is identity
((partial f a) b)
=> (f a b)
by definition
And as hiredman said @calle ((comp f g h) x)
is (f (g (h x)))
I think it's this non-currying that's tripping me up
I'm so used to ((f a) b)
being the same as (f a b)
that's basically the only way I use map
just want to shout out #practicalli. truly an amazing resource for getting up and running with ring + compojure
I think I'm going to use ->>
a lot...
What I'm saying is that when I see (map my-fn)
in a comp
and in a ->>
I need to remember that they mean completely different things.
->>
is not comp
but reversed.
thanks for clearing things up, see you later 🙂
I wanted to change the path that aot dumps to ... seems like it doesn't like the following -- any suggestions?
{:aliases {:aot {:extra-paths ["target/classes"]
:main-opts ["-e" "(set! *compile-path* \"target/classes\") (compile,')"]}}}
@johnjelinek Did you make sure target/classes
exists before you run that?
ya, it throws an exception
{:clojure.main/message
"Execution error at clojure.main/main (main.java:40).\nEOF while reading, starting at line 1\n",
:clojure.main/triage
{:clojure.error/class java.lang.RuntimeException,
:clojure.error/line 40,
:clojure.error/cause "EOF while reading, starting at line 1",
:clojure.error/symbol clojure.main/main,
:clojure.error/source "main.java",
:clojure.error/phase :execution},
:clojure.main/trace
{:via
[{:type clojure.lang.LispReader$ReaderException,
:message
"java.lang.RuntimeException: EOF while reading, starting at line 1",
:data {:clojure.error/line 1, :clojure.error/column 1},
:at [clojure.lang.LispReader read "LispReader.java" 314]}
{:type java.lang.RuntimeException,
:message "EOF while reading, starting at line 1",
:at [clojure.lang.Util runtimeException "Util.java" 221]}],
:trace
[[clojure.lang.Util runtimeException "Util.java" 221]
[clojure.lang.LispReader readDelimitedList "LispReader.java" 1405]
[clojure.lang.LispReader$ListReader invoke "LispReader.java" 1243]
[clojure.lang.LispReader read "LispReader.java" 285]
[clojure.lang.LispReader read "LispReader.java" 216]
[clojure.lang.LispReader read "LispReader.java" 210]
[clojure.core$read invokeStatic "core.clj" 3766]
[clojure.core$read invokeStatic "core.clj" 3741]
[clojure.main$eval_opt$fn__9100 invoke "main.clj" 487]
[clojure.main$eval_opt invokeStatic "main.clj" 487]
[clojure.main$eval_opt invoke "main.clj" 482]
[clojure.main$initialize invokeStatic "main.clj" 508]
[clojure.main$script_opt invokeStatic "main.clj" 533]
[clojure.main$script_opt invoke "main.clj" 530]
[clojure.main$main invokeStatic "main.clj" 664]
[clojure.main$main doInvoke "main.clj" 616]
[clojure.lang.RestFn applyTo "RestFn.java" 137]
[clojure.lang.Var applyTo "Var.java" 705]
[clojure.main main "main.java" 40]],
:cause "EOF while reading, starting at line 1"}}
What exception?
I think it doesn't like my \
in there
You probably need ,
instead of space in that string
See https://github.com/seancorfield/dot-clojure/blob/master/deps.edn#L57 for example
good deal
thanks!
"(set!,*compile-path*,\"target/classes\") (compile,'
Does that work?
needs ,
between forms
but then that works, except -- the clojure.core
stuff doesn't get into the directory
Ah yes. That too.
not sure why the clojure.core
stuff is missing
it's already been compiled
nvm ... ran -A:aot
again and it got it into the directory now
AOT is evil 🙂
unfortunately, I need it for my stuff
Sorry man. We rely on one library that has a single namespace AOT'd. Other than that, we avoid it at all costs.
I don't know how to transpose the following without aot:
package com.myorg;
import software.amazon.awscdk.core.Construct;
import software.amazon.awscdk.core.Duration;
import software.amazon.awscdk.core.Stack;
import software.amazon.awscdk.core.StackProps;
import software.amazon.awscdk.services.sqs.Queue;
import software.amazon.awscdk.services.sqs.QueueProps;
public class HelloStack extends Stack {
public HelloStack(final Construct parent, final String id) {
this(parent, id, null);
}
public HelloStack(final Construct parent, final String id, final StackProps props) {
super(parent, id, props);
Queue queue = new Queue(this, "MyFirstQueue", QueueProps.builder()
.visibilityTimeout(Duration.seconds(300))
.build());
}
}
Concrete inheritance? Ugh 😞
To be fair, I haven't yet figured out how to transpose this in general, but I feel like my options are either proxy
, reify
, or gen-class
Why is AOT evil?
Others with more experience can give more full answers, but I believe the gist of it is that even experienced Clojure developers can have a difficult time diagnosing subtle problems that can occur in some situations when AOT is used.
e.g. .class files that were compiled from different versions of Clojure source code being used, leading to code execution behavior from source code that is not what you are looking at in your editor.
I am having the most frustrating experience with ring ... I have a compojure POST route, that just pprints the request from a client I wrote. My handler is
(def app (-> routes wrap-json-body wrap-reload))
But wrap-json-body leads to the body always being nil. Without it its a HttpInputOverHTTP. I don't know what to do about it, it seems like noone had this problem with wrap-json-body, at least I can't find it. Content-type is application/json.how would i go about writing a macro that can be called like this:
(my-macro
[+ 1 1]
[str "hello " 123]
[inc 5])
and return the following structure:
['(+ 1 1)
'(str "hello " 123)
'(inc 5)]
(take vecs that would be valid forms if they were lists, and return quoted, unevaluated "eval-able" lists)
(i know i can use [+ 1 1]
directly using (apply (first [+ 1 1]) (rest [+ 1 1])
, which is what i'm currently doing, but this stores the functions as function-objects, which isn't directly a problem, but it makes debugging these structures extremely hard, especially when everything gets wrapped with spec instrumentation stuff and is as such turned into some unreadable spec function-object thing)Now I have slurped my input-stream manually and it yields "{\"date-range\":{\"from\":\"2019-09-10\",\"to\":\"2019-09-19\"}}" which at least according to https://jsonlint.com/?code= is valid JSON. Still when I don't slurp it (so it is not gone) and use wrap-json-body it is nil. Also wrap-json-request works fine. Can anyone help me understand this?
it works, i just needed to remove that little '
in the last line to remove double-non-evaluation ;D thanks, person who removed his/her message ^^
@lkowarschick Why not just use a function?
(defn to-lists [& forms]
(map (partial apply list) forms))
that doesn't fully fulfill my requirements, as it results in the following:
(([clojure.core$_PLUS_ 294690511 "clojure.core$_PLUS_@11909ecf"] 1 1)
([clojure.core$str 439674431 "clojure.core$str@1a34e63f"]
"hello "
123)
([clojure.core$inc 1883794397 "clojure.core$inc@70486bdd"] 5))
(it stores function-objects instead of symbols)(defmacro foo [& forms]
(let [lists# (for [form# forms]
(list 'quote (apply list form#)))]
`[~@lists#]))
gonna use this ;DI don't think the generation of special names is necessary here though as the code doesn't make its way in the macro at all
i've got a function that can take any type of collection (it handles maps seperately, so were talking sets, lazySeq, list, vector, etc)
it does stuff to that collection and should then return the modified version as the same type as it got it. how can i achieve this? map and such turn everything into a lazySeq, so i need to somehow (into (type input) output)
my result.. (<- i know that doesn't work)
I recommend Specter for this, it is specifically designed to address this issue (changing the type of the container)
really? do i actually need a additional dependency for that? then i'd rather just (cond)
it on the type..
so is my simplest option to write this function
(defn map-keep-type [fun coll]
(let [mapped (map fun coll)]
(condp #(%1 %2) coll
vector? (vec mapped)
set? (set mapped)
list? (apply list mapped)
map? (zipmap (map first mapped) (map second mapped))
seq? (seq mapped)
mapped)))
?thats why i hoped there would be some kind of into
that takes types and not empty collections...
Hey there, would anybody be willing to help meet out setting out Emacs with Cider? Completely new to this thing and encountering a bug...
Hey, thanks
I'm using cider version 2019090
When I try and do cider-jack-in
, I get this error:
Could not find artifact cider:cider-nrepl:jar:0.22.1 in clojars ( )
This could be due to a typo in :dependencies, file system permissions, or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable
Pretty sure the issue is that nrepl
version 0.22.1
does not exist on Clojars
Latest stable version is 0.22.0
, from what I can see on the web page
ah understood. There was a bug in the 22.0 release and the intention was to release on clojars. But it looks like that hasn't happened yet. CIDER injects its dependencies based on its version.
I tried changing cider-required-middleware-version
in cider.el
to 0.22.0
(according to the Cider docs, "any nearby version will work"...). But after making this changing, restarting emacs, and running cider-jack-in
, I still get the error message about 0.22.1
I edited the file
I just changed the argument to defconst
from 0.22.1
to 0.22.0
if you use a prefix C-u C-c M-j
you can directly edit the jack in command and rewrite the version of the cider-nrepl version that's injected
Ah, OK. How exactly do I rewrite the command?
(Sorry, I'm completely new to this...)
OK, I can see how to do this
if you try it you'll see. The prefix arg will put the jack in command in the minibuffer and you can just edit it directly
It's working now, with a warning
you can probably ignore the warning. its just saying a mismatch but that's what we are intending to do right now
Odd that changing the argument to defconst
in cider.el
didn't fix this, right? I just assumed that I didn't know enough about emacs/clojure and was missing something else...
correct. i'm gonna look into that but this should get you working until the newer artifact is released
thank you, this is really helpful
FYI I just checked cider.el
after editing and restarting -- argument to defconst
is still 0.20.0
(it didn't revert to anything else). So not sure where it's reading 0.20.1
from
there's a clojurescript completion bug in 0.22.0
that's fixed by the .1 point fix but its not out yet
sorry, typo: I'm using 0.22.0
, not 0.20.0
cool, OK
but to summarize the strange behavior: You edited cider.el
in your elpa directory to make cider-required-middleware-version
have the value "0.22.0"
. You restarted emacs but this version was still "0.22.1"
. Is this correct?
No, not quite; I edited the version number to "0.22.0"
, restarted emacs, the version number is still listed in cider.el
as "0.22.0"
, but I still see the bug described above
The error message still complains about not being able to find cider-nrepl
version 0.22.1
hmm. I edited cider.el to "0.14.0", restarted and it was correctly seen. can you walk me through how you changed things?
couple things i can think:
1) are you sure you edited the correct cider.el file? It should be ~/.emacs.d/elpa/[cider-version]/cider.el
2) Are you sure you actually restarted emacs. There's a server that can keep running and its important that you actually kill emacs rather than just kill the client connected to an emacs server
Hey -- sorry for the delay, was away from my machine for a couple of hours
Here's some terminal output in response to your questions:
Jacks-MBP:.emacs.d jackie$ rg "0\.22\.1"
Jacks-MBP:.emacs.d jackie$ rg "0\.22\.0"
elpa/cider-20190901.1056/cider-xref.el
56: :package-version '(cider . "0.22.0"))
elpa/cider-20190901.1056/cider.el
14:;; Version: 0.22.0
90:(defconst cider-version "0.22.0"
407:(defconst cider-required-middleware-version "0.22.0"
1189: :version '(cider . "0.22.0"))
elpa/cider-20190901.1056/cider-repl.el
150: :package-version '(cider . "0.22.0"))
i.e. no reference anywhere in .emacs.d/
to the incorrect version number (`0.22.1`)
running cider-jack-in
still produces the error above i.e. unable to find an artifact for cider-nrepl
version 0.22.1
What is even more curious, is that if I then run cider-jack-in
as you described (using the C-u
optional argument), and set the version number to 0.21.1
, I get a REPL with this warning message:
WARNING: CIDER 0.22.0 requires cider-nrepl 0.22.1, but you're currently using cider-nrepl 0.22.0. The version mismatch might break some functionality!
i.e. it reports that I am using cider-nrepl
version 0.22.0
, as defined in my cider.el
, and not 0.21.1
, which I passed in to the command "by hand"Very strange...
cider-required-middleware-version
-- "0.22.1"
cider-jack-in-lein-plugins
-- (("cider/cider-nrepl" "0.22.1"))
~/.emacs.d/elpa/cider-20190901.1056/cider.el
should I be making the changes somewhere else?
i don't think so. I mentioned it earlier but are you sure you are restarting emacs as opposed to just closing the open windows?
What key command would I use to restart it? I've been doing C-x C-c
Thanks -- I tried that, restarted emacs, ran cider-jack-in
and still get the error!
@lkowarschick I’m also a beginner so take with a grain of salt but maybe this will work nicely for you?
user=> (defn map-keep-type [fun coll] (into (empty coll) (map fun coll)))
#'user/map-keep-type
user=> (map-keep-type #(+ % 1) [1 2 3])
[2 3 4]
user=> (map-keep-type #(+ % 1) #{1 2 3})
#{4 3 2}
user=> (map-keep-type #(+ % 1) '(1 2 3))
(4 3 2)
uhh i didn't know empty
exists, that shouuuld work (i'll reverse lists manually)... ill do some testing, thanks ;D
anyone saw this error recently? https://github.com/danielsz/meyvn/issues/5
@jiyinyiyong for what it's worth, my issue with Clojars was resolved
In Haskell we only need to type :t function_name
on GHCI to see the type of output and inputs of this function. Can we do the same in Clojure’s repl? I only could do this with types like String, Long by (type 10)
or (type "aa")
but it doesn’t work with functions.
clojure doesn't have a static type system you can query type information from, what the type function returns is the runtime jvm type of a thing
On the cli, rebel-readline can do that. Other tools (Emacs CIDER, IntelliJ Cursive) can provide this
user=> (doc +)
-------------------------
clojure.core/+
([] [x] [x y] [x y & more])
Returns the sum of nums. (+) returns 0. Does not auto-promote
longs, will throw on overflow. See also: +'
nil
user=>
as @alexmiller suggests there are some extra tools that you can use that will do things like displaying arglists for functions as you type
Just searched rebel-readline on github and looks great. Thanks! And i love this (doc ) will help me a lot!