This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-11
Channels
- # beginners (79)
- # boot (21)
- # cider (28)
- # cljs-dev (1)
- # clojure (88)
- # clojure-italy (3)
- # clojure-russia (6)
- # clojurescript (49)
- # community-development (4)
- # cursive (37)
- # datomic (12)
- # editors (3)
- # emacs (33)
- # fulcro (15)
- # hoplon (9)
- # jobs-discuss (3)
- # keechma (3)
- # lein-figwheel (2)
- # luminus (3)
- # off-topic (146)
- # onyx (5)
- # portkey (11)
- # re-frame (34)
- # reagent (7)
- # reitit (5)
- # remote-jobs (1)
- # shadow-cljs (6)
- # unrepl (11)
I'm having a bit of a negative reaction to list comprehensions 🙂 Are they idiomatic (in which case I should just fight through and embrace) or could I safely favour the use of map
/`filter` etc?
it can often lead to more concise and clear code than the equivalent map/mapcat/filter
version
What's the idiomatic way to look up a key in a map, but if the key is not present I would like it to crash rather than return nil
? If you think I should not be interested in doing this, because the question indicates that I am doing it wrong somehow, I would also be interested in hearing that.
The reason I am asking is that when I wrote an app in Clojure I kept looking up keys in the wrong place (e.g., look up :foo
in a map when I should have looked up :bar
to get a map in which there is actually a :foo
). I am assuming that there is a spec-related full answer to this question, but I am hoping that there is also quick way to just get a crash right where the problem is, instead of somewhere far away where the nil
I got ends up propagating and blowing up stuff.
don't think there is an idiomatic way to make get
throw
you can use spec to validate your data before trying to call get
the simple version is (fn [m k] (if-not (contains? m k) (throw (ex-info "key not found" {:m m :k k})) (get m k)))
I keep forgetting to use find
hey all, is there a "weaker" version of assoc?
For example, If I have a big object db and just want to update one value some layers down in nested maps
(assoc db :items { :muffin {:quantity -1}})
But this will wipe out any other children of the object
there's assoc-in for nested updates, I don't know if that's what you mean by "weaker"
I just meant updating the object without wiping out all the other keys of the maps
user=> (assoc-in {:muffin {:quantity -1 :flavor 'blueberry}} [:muffin :quantity] 3)
{:muffin {:quantity 3, :flavor blueberry}}
see also get-in / update-in for related functionality
thanks!
Hey, thrashing beginner here. I've been working through the Web Development book using the command line, and I'm trying to switch over to IntelliJ IDEA and Cursive to run my project. Got IntelliJ installed, with Cursive within, and opened the 'guestbook' project. But when I try to run the REPL,
all I get is "Error running 'REPL for guestbook': Unknown error. My environment is as follows:
IntelliJ IDEA 2017.3.3 (Community Edition) Build #IC-173.4301.25, built on January 16, 2018 JRE: 1.8.0_152-release-1024-b11 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Mac OS X 10.12.6
Apparently it's using IntelliJ's JDK, which according to earlier reports is the best way to work around Java issues.
"Stuck" doesn't begin to cover where I am, which is completely lost at sea. Any suggestions for an utter noob?
@steve171 man, having to deal with tooling problems, when you really just want to learn a language sucks
True that, brother!
@steve171 is the book web development clojure 2?
Yes, Web Development with Clojure, 2nd Edition
how are you running the repl?
There's a 'REPL for guestbook' choice in the Run menu, and I've created a vanilla configuration and run that. Same result.
hmm i want to try this. your the second person to ask me
to be clear you can start the server right? with lein run?
also, imo cursive is probably the safest editor choice out there for clojure.
I'm noticing that the Leiningen window lists the following tasks: pom, help, upgrade, install, jar, deps, uberjar, test, clean, compile and version. Is it suspicious that there's no 'run' option?
so your fine with your setup.
Yes, I can run lein from the shell...though it does report the following:
WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.xnio.nio.NioXnio$2 (file:/Users/upstill/.m2/repository/org/jboss/xnio/xnio-nio/3.4.0.Beta1/xnio-nio-3.4.0.Beta1.jar) to constructor sun.nio.ch.KQueueSelectorProvider() WARNING: Please consider reporting this to the maintainers of org.xnio.nio.NioXnio$2 WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release
Sounds like you're running on Java 9? These are normal (and harmless) warnings caused by stuff in Java 9 that not everyone has caught up with yet.
Could this be causing IntelliJ to lose it's shit?
i have no idea what any of that means
You and me both.
I've ignored it previously because it didn't interfere with working with the lein REPL
my first guess, is you need to connect to the repl that starts when you run lein run -p 8000
:
$ lein run -p 8000
...
luminus.repl-server - starting nREPL server on port 7000
Sorry, I can't interpret that first line.
Specifically, what does 'âś—' denote?
some random stuff from my terminal.
run > clojure repl > remote > host: 127.0.01 port: 7000 Is what i was hoping would allow me to connect to the repl. but it seems to just stall.
Well, the luminus.repl-server is specified in my src/clj/guestbook/core.clj file. It's not clear how I would get the IDE to run it, since there is only a limited selection of choices for the REPL: 'Use nREPL in normal JVM Process', 'Run nREPL with Leiningen' and 'Use clojure.main in normal JVM process'
there is a remote repl option. which i would assume we want, but i tried to connect to the luminus repl (localhost:7000) and it just stalls.
Now that's interesting. I picked 'Use clojure.main...' (getting warnings about limited functionality) and ran it, and it apparently started up.
@joelsanchez @noisesmith @bronsa @ghadi Thank you for the advice!
hmm. ok. now im guessing we dont want to run lein run -p 8000
from the command line. we want to use intelliji to start it
That sounds like a challenge. BTW, I'm using Colin's instructions for getting started with Cursive, and he suggests that "if you already have an nREPL server running somewhere, you can connect to it using a Remote configuration. There are two options here - either you can configure it to connect to a host and port, or you can configure it to connect to 127.0.0.1 and get the port from the port file written by Leiningen."
Now the trick is to get the nREPL server running...
Yea. i dont see why i can’t connect to it using the remote option. But it just doesn’t when i punch in localhost and the port. so humpf
Sounds like you're running on Java 9? These are normal (and harmless) warnings caused by stuff in Java 9 that not everyone has caught up with yet.
Well, what do you know? When I just 'lein repl', I get an nREPL server on port 60109. Now let's negotiate with IntelliJ...
Hey! I created a Remote configuration, gave it the IP address and port, and it seems to run! No prompt, oddly, but I seem to be talking to the REPL!
@seancorfield yeah, I assumed it was noise. (I just installed Java, like a week ago, so I'm also assuming it's the latest version)
@steve171 There is more then one way to do this. This way also works and is more intelliji compact: 1) run > clojure repl > local: run with lein paramaters: -p 8000 i believe this to be working as i can send parts of my application to the repl now.
That just gets me the same Unknown Error when I try to run.
However, I did set up a Remote configuration with "Use Leiningen REPL port" and it worked. But now, having restarted IntelliJ, Running the config (green triangle next to the Configuration selection) does nothing. No errors, no feedback, nothing. GAH!
@drewverlee is there supposed to be a 'clojure repl' choice on the IntelliJ Run menu?
@steve171 run > edit configurations >create (+ in upper left corner) > clojure repl > local:
BTW, there's a #cursive channel if you need to dig deeper on IntelliJ and Clojure.
(I personally find IntelliJ to be horrible -- I've tried it so many times and just given up... but then I really don't like IDEs with menus and panels all over the place)
When I started with Clojure, I used TextMate with a simple REPL plugin. It was good to be learning Clojure without having to also learn a new editor. Then I switched to Emacs for several years which was its own giant learning curve. Then I switched to Atom/ProtoREPL and I've been very happy with the simplicity of that setup.
But editors are very subjective so my general advice is: if there's a Clojure plugin for the editor you already use, go that route; if there isn't, pick the combination that's closest to what you're used to.
I had assumed cursive to be the most structured and guided approach. But maybe thats not the case.
I’m happy with spacemacs and cider so far. I only get in trouble trying to be on the edge.
@steve171 i would go with #luminus and #cursive for more help. i dont feel like i understand cursive well enough to help. I too wasn’t starting the luminous server with my setup. I’m guessing you do what i said put the profile as “dev” (which might be the default) and then pass the -p 8000
to something. but i can’t figure out what. Maybe its supposed to be a string?
I'm seeing a lot of people working through that Web Dev book and getting into all sorts of difficulties. Web dev in Clojure is very different to most other languages, because you have to assemble a whole bunch of libraries to get the "full stack framework" look'n'feel that is common in other languages -- and I personally think there's too much "magic" going on if you start with a "batteries included" combination of libraries. I recommend beginners start with just a bare bones Compojure / Ring app and then look at Hiccup or Selmer for generating HTML and get a solid handle on all the basics, before attempting to understand something like Luminus.
As Arachne was being developed, I felt it suffered from a lot of the same problems: so much machinery and "magic" in the name of flexibility and elegance...
@seancorfield I really liked Luminus. I think it was the second let project I did, adding some back and stuff to a snake game. It's nice to get all the pieces working, even if you don't really get all the profiles and stuff.
@steve171 by any chance are you the author of “The Renderman Companion”? On my bookshelf 5 feet from where I sit.