This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-13
Channels
- # aleph (6)
- # architecture (29)
- # beginners (175)
- # cider (22)
- # clara (5)
- # cljdoc (5)
- # cljs-dev (28)
- # cljsrn (6)
- # clojure (62)
- # clojure-finland (7)
- # clojure-italy (7)
- # clojure-nl (2)
- # clojure-spec (23)
- # clojure-uk (194)
- # clojurescript (90)
- # core-async (2)
- # cursive (23)
- # datomic (41)
- # defnpodcast (2)
- # editors (4)
- # emacs (1)
- # figwheel-main (41)
- # fulcro (53)
- # hoplon (15)
- # hyperfiddle (4)
- # immutant (1)
- # jobs (7)
- # jobs-discuss (103)
- # lein-figwheel (9)
- # off-topic (34)
- # onyx (3)
- # parinfer (1)
- # portkey (1)
- # re-frame (7)
- # reagent (2)
- # remote-jobs (2)
- # rum (1)
- # shadow-cljs (148)
- # sql (54)
- # tools-deps (3)
- # vim (7)
I have no idea what that error means. What I'm doing seems straightforward.
The issue seems to be that args
is an ArraySeq
? How do I unpack it into a number? Is there a more elegant way to test one-less-arg
?
if you change (f x args)
to (apply f x args)
it should do what you want
apply takes a function, and a arglist (and N optional args before the arglist)
Hey all, is there a good way to set CIDER to pprint by default? in the process of expriementing with switching over from cursive, and it's something I miss
@michael.ford I just found cider-toggle-repl-pretty-print- method 🙂 You must check it out 🙂
Well. I don't think that it's a good idea. print is for printing pprint is for pretty printing
You can always use pprint to print sth to the repl
Have you tried gloss? I used it once and it was very nice
Yeah, I used it a couple of years ago, was active back then.
any idea what i'm doing wrong here?
; This works
(s/describe :myspec/a-thing)
=> (keys ...)
(s/gen :myspec/a-thing)
FileNotFoundException Could not locate clojure/test/check/generators__init.class or clojure/test/check/generators.clj on classpath. clojure.lang.RT.load (RT.java:463)
recently i've had plenty of missing dependency issues. datomic, spec etc. could that be a java10 thing?
nah, for whatever reason these projects have “optional” dependencies that you only need if you use certain parts
but as you just noticed this becomes confusing if you’re not aware that this is the case, and what these parts are
@michael.ford in the repl press comma and you will see a very useful list of helpers. One of which is to toggle pretty printing
I'm trying to find the first key in a list that exists on a map. With all keywords, I can use (some m (sorted-set :a :b))
. Is there a way to do this when one of the searched keys is a string?
Actually, right after typing, I realised the order of the keys doesn't matter so I'll just use #{:a "b"}
. Would be nice to know if there's a way tho 🙂
@cristibalan Compare (some {:a 1 :b 2} [:a :b])
and (some {:a 1 :b 2} [:b :a])
The key aspect is that order of the elements in the collection is important.
Also, you have to decide if false
-y is important to find
(some {:a 1 :b 2 :c false} [:c :b :a])
if they are keywords or strings, you could sort-by name
name
happens to work on both identifiers and strings and turn them all into strings
What about (first (select-keys m l))
@cristibalan?
@reborg It seems that still returns whatever the collection happens to have sorted first. I am trying to find out the first of the keys in the list (in the order given by the list) that exists in the map, when the keys can be either keywords or strings.
Can you post a counter example? I have the following (I don't think it changes int-str-keyword keys):
(def m (zipmap (range 20) (range 20)))
(def l [:a 5 "1" 6 1])
(some (set (keys m)) l)
;; 5
I'm expecting :b
to be returned here:
(def x {:b 2 :a 1 :c 3 "d" 4})
(some (set (keys x)) #{:b "d"})
Oh wait, misread your example.
Success!
(some (set (keys x)) [:b "d"]) ;; => :b
I see, thanks. I was using a set there probably because I was confusing the location of the pred argument to some.
@alexmiller That's a good alternative to #{"b" :a}
, but changes the order of the searched keys.
@mfikes Thanks. Yeah, I'm definitely not trying to count on the order of the elements in the map.
Right, the order of the elements in the map is not important. The ordered collection is the second argument @cristibalan
In other words counting on (seq #{:a "b"})
being (:a "b")
is the thing to watch out for
is there a way to avoid having to re-launch the REPL just because I'm adding a dependency?
@beders clj-refactor (an emacs package) allows you to add a project dependency and hot-reload the dep into the REPL https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-add-project-dependency
unfortunately I'm on IntelliJ-Cursive. I wish this would be standard part of the repl that leiningen starts
> unfortunately I'm on IntelliJ-Cursive if you are using leiningen the plugin will work (but cursive may or may not understand the new deps correctly)
The trouble I have with becoming skilled with Clojure is that I'm already very familiar with C#. When trying to create a non-trivial system with Clojure, I'm always dragged back into minutia that I take for granted in Visual Studio & C#. And debugging in Clojure vs VS seems night and day 😕
Did you try Cursive (based on Intellij)?
@jonahbenton No, I've so far been very windows/CLR focussed - part of my difficulty I guess (learning JVM) - is it better than the Emacs/Cider combo? I've briefly used Emacs before, and was starting to get the hang of it
@placeboza I come from a java background. I use vim and a basic repl started with leiningen. Using the repl and mostly functional code, I've never felt I needed a debugger like you'd find in java + eclipse.
yeah, the fact that the majority of values in-situ in your running system are immutable means that simply storing the values that come in at runtime then playing with them in the repl can do most of your debugging needs
and you hardly need tooling with that, either def or an atom and swap! or reset! should get you going
the language has so much built in for introspecting and operating on structured data that I tend to just do this for a majority of cases
It is a very different workflow. But I'd argue having the repl in your workflow is a huge advantage that clojure has. I'm far more confident in what I write when I'm using the repl during development because I immediately know what works and what doesn't.
Right, so I guess the power of the language covers for the limited tooling to some extent. But it does require some innovative thinking, which is making it difficult for me to focus on the overall solution I'm trying to make. Like that old saying - "It's hard to think of draining the swamp when you're chased by the crocodiles"
Thanks, just wanted some insight into how others are using it - seems that I need to just get more familiar with the language features then
yeah, and learning a new editor at the same time often makes that worse
there is a vs-code plugin for clojure, I've heard it actually works well
I've actually done some coding with ClojureCLR and it wasn't bad, but it was a bit slow
also, clj-clr exists, you can use it with the standard clr tooling (eg. nuget) - it just lacks dedicated tooling
it's up to date with clj-java usually
the language side is well supported and working afaik, it just lacks 3rd party tools
(this might no longer be true)
I believe the features work well, but the CLR causes some performance issues - it wasn't quite designed for an immutable FP with some innovative ideas
As far as a more traditional debugger. I'd look into the cursive plugin for intelij as @jonahbenton suggested. No reason you can't have the best of both worlds. I'd still highly recommend trying out a workflow focused around the repl.
The way I see it - you can build a relatively bug-free piece of code very well in a repl. But my concern is when you hit an nasty, intermittent bug that isn't obvious - a call stack at least comes in handy then
i.e. the repl is a great way to build the code but doesn't seem like a great way to remove bugs from a sizeable existing bit of code
the call-stack visibility works out in a vanilla repl, but often gets obfuscated by tooling that is too clever for its own good
a lambda is just an instance of an anonymous class implementing IFn
(I mean, that might be rare in your java / c# coding style, but isn't totally alien)
laziness doesn't play nicely with stack trace reading though - easily counterintuitive
Yeah, I just mean for debugging it can complicate things wrt deferring the execution. (Esp if it's anon)
fun trick - you can make an anon-fn with a name
(ins)user=> (fn [])
#object[user$eval158$fn__159 0x61e94def "user$eval158$fn__159@61e94def"]
(ins)user=> (fn foo [])
#object[user$eval162$foo__163 0x5b068087 "user$eval162$foo__163@5b068087"]
right, but I think it does use that optional name arg to fn
so (def xx (fn xx [] ...))
edit: it doesn't do that, but there's a comment saying it should and why it doesn't
I pretty much only use that feature for making stack traces easier to read (though it's also useful for non-tail recursion)
for a beginner using lein is simpler - most documentation for non core libs and tooling assumes lein
boot can be useful for more complex builds that work against lein's assumptions / defaults, but is easier to pick up if you know lein first
I have some basic familiarity with lein, sounds like I will investigate boot when I need more power
in my experience most boot users end up there because they wanted a more optimized build, or their project.clj config in lein was getting overly complex boot lets you run arbitrary code, it's not a declarative data structure file but a script to run
I think most people have a terrible build process, and boot isn't as opinionated as lein is, so it is happy to let you wallow in your terrible build, where as you will have to fight with lein to get it to do the terrible things you want done
to characterize boot as more powerful in some way is just factually wrong, but you won't have to fight it to introduce a build dependency on the phase of the moon as much
another +1 for component
mount relies on singleton global mutable state, component explicitly avoids that
Hi I am unable to loop through the chars of a string (-> "ABCDEF" (seq) (Character/toString) (Character/codePointAt 0) (println))
It's nt working
please advise how to stream chars of a string into the threading
Character/toString takes a character, you are passing it (seq "ABCDEF") which is a list of characters
->
isn't a streaming operator, it's a macro that manipulates your code before compiling it
@manas.marthi perhaps what you want is (->> "ABCDEF" (seq) (map #(Character/toString %)) ...)
- note that this requires using ->> (thread last) instead of -> (thread first)
or some other iteration construct, yes
also map implicitly calls seq, I left it for simplicity's sake
(map #(Character/toString %) (seq "ABC"))
thank you
@pauld Doesn't the global nature of the defstates hold you back? i.e. don't think it lets you have local contexts like you would typically with other DI approaches
I have a large text. I want to find the frequencies of chars.. I used (frequencies (slurp (io/resource "myfile.txt"))) to get the map
how do I sort this on values?
(sort-by val m)
- returns a list, because maps are not sortable by value (and the default is not sortable at all)
thanks a lot!!
I've never had any issues with needing to rebind local contexts - but I believe yurt solves that.
But I think tolitius can better explain. I just wanted the simplest way to make my code reloadable and to give me fine-grained control over app state during development and mount fit the bill.
It does seem prettier and easier to get going with. But just a little less configurable wrt context
when testing, it's the difference between initializing or mocking / overriding globals (mount) vs. providing the component with stubs of its deps (usually hash-maps and (constantly foo) functions) with component
making things stateless as component requires isn't free design wise, but it has some nice consequences
also with component, you can use an injected dependency from an upstream user of your code (it's just a value passed in at runtime) (this might also work with mount, but with component there's no "trick" to it - it just works like any other component and does the right thing)
Integrant strikes me as an attempt to do stuartsierra/component but with more magic just-do-the-right-thing convenience (that said, I haven't used it in anger)
So perhaps what I need to learn is the common patterns that lispers use when building a system
a simple one that you'll see a lot is replacing f(x)
which modifies y, with (f y x)
which returns a new value for y (along with any other return value needed)
there's actually a proof that any global mutable can be replaced with an argument that is added to the input list of every function, and returned as an extra value from every function
If you were to undertake the quixotic quest to port a Clojure to run on top of Swift/iOS, (with the goal of learning, not with the goal of actually producing a working result), what approach would you take? Would you port Clojure itself (replacing all of the .java files with .swift implementations), or take the ClojureScript approach and write a Clojure->Swift compiler? Why? For either answer, what is the very first step you would take (i.e. which source file would you start examining / porting)?
the main difference of jvm clojure and js clojure is that jvm clojure outputs byte code from the compiler, and cljs emits js from the compiler
Ah, and there is no equivalent concept of bytecode in Swift, which perhaps changes things
what does the swift runtime do, load code at startup?
anyway, sounds closer to js from that
Yeah, I'm not sure. I was guessing that emitting swift might make more sense, because it already has support for immutable value types (structs, enums, etc).
if you find out you want to emit bytecode, you could look at how clojure-clr is done, if you wanted to emit swift source, then look at the main (non-bootstrap) cljs compiler
I have a hunch that you'd find things that don't quite match up with clojure's immutable data structures and swift's such that you need to make compatibility wrappers anyway - I don't know enough about swift to say for sure though
@noisesmith so I'd maybe want to start with looking at comp.clj, shown in this diagram? http://blog.fikesfarm.com/posts/2015-07-17-what-is-bootstrapped-clojurescript.html
well I meant to indicate the non-bootstrapped cljs (the one written in java), I assumed that there would be less to change
@noisesmith yeah, now that I think of the idea of building "persistent" datastructures, I'm not sure that starting with a building-block of an immutable value (as opposed to an object) is any help
but if bootstrapping is a goal you could look at that, sure
yeah, I believe that page is indicating that comp.clj (in the first diagram) is the non-bootstrapped java implementation which spits out js.
right
FYI, this helps me a bit wrt grokking the change of design from C# to Clojure: http://mishadoff.com/blog/clojure-design-patterns/
Spoiler = standard design patterns are a bit moot in Clojure but that page illustrates it
@jasonpepas see also tools.analyzer if you are looking to build a clojure compiler. I just listened to a cognicast episode about it...