This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-06
Channels
- # beginners (147)
- # boot (12)
- # chestnut (12)
- # cider (22)
- # clara (10)
- # cljs-dev (6)
- # cljs-experience (3)
- # cljsrn (12)
- # clojure (58)
- # clojure-austin (3)
- # clojure-dusseldorf (25)
- # clojure-finland (20)
- # clojure-gamedev (1)
- # clojure-greece (3)
- # clojure-italy (32)
- # clojure-new-zealand (5)
- # clojure-russia (12)
- # clojure-serbia (1)
- # clojure-spec (4)
- # clojure-uk (51)
- # clojurescript (75)
- # cursive (8)
- # datomic (81)
- # fulcro (29)
- # graphql (16)
- # heroku (6)
- # incanter (1)
- # keechma (1)
- # lumo (44)
- # off-topic (21)
- # onyx (22)
- # parinfer (5)
- # portkey (40)
- # re-frame (43)
- # reagent (5)
- # spacemacs (37)
- # specter (8)
- # unrepl (3)
@dimovich An important note: luminus is not really a framework, more of a premade, preconfigured collection of composable libraries. Still super useful and a great way to get started
Hi - I am new to clojure and wondering if there is a good resource that explains how state is maintained within a typical clojure app? For example I want to know what exactly does def-ing an atom within a namespace file actually do? Is the atom visible globally for example and what does changing the state of the atom do when you are in a REPL?
all namespace level bindings are globally visible (but, of course, namespaced)
changing the state of the atom in the repl changes the only global value of that atom
for state that represents initialized resources, it's best to use a library like stuartsierra's component or weavejester's integrant
in that case the state would be visible as a var during development, and would be an ephemeral shared binding visible to components that use it in production
@eggsyntax @genec @donyorm thanks for the suggestions!
Could anyone walk me through deploying app to heroku? it's my first deploy and my first clojure app so assume i am noob
i saw https://www.heroku.com/java (clj tab) is it really this easy??
Hi... I would like to know if (:gen-class) is necessary? Or just for the core with -main? (I use Java Interop but not the otherwise)
you only need gen-class if you need to create a class for something from java to call
without gen-class you can do java -cp my-uber.jar clojure.main -m my.ns
though yeah, you need gen-class or a shim if you want a jar that can be run directly without such a trick
@noisesmith do you still need to AOT compile that namespace?
no- since clojure.main is already compiled, you don’t need aot or gen class to start your code that way
also, you can use a similar trick to use your production jar to start up a repl that has all your namespaces in scope but doesn’t run your main
(sometimes useful for emergency exploritory debugging)
that’s exactly it, yes
and even then, there’s the alternate choice of having the client call your code via clojure.lang.RT clojure.java.api.Clojure or writing a small java wrapper that uses RT yourself
also, there are a few categories of bugs that never happen if you avoid aot and gen-class, so there’s decent reasons to avoid it if possible
I see, thanks @noisesmith
oh, I guess RT isn’t the right entry point any more, now they recommend clojure.java.api https://clojure.org/reference/java_interop#_calling_clojure_from_java
Okey... another.. what is the best way to manage state in clojure? (erlang the state is always received as a parameter), thinking about immutable we always have to drop and create a new one, but how to do that in clojure when for example you use dbcon in several namespace
some popular libs for this include stuartsierra/component and weavejester/integrant
what ends up happening is that you have a global top level binding of your stateful components at dev time, and in production it’s passed as an argument to the things that use it
there’s an alternative called mount that just makes everything global but gives you shorthands to control the state
that’s arguable - for things that are immutable, typically global is better than hidden is
for stateful things, there’s active argument
if you start with a full featured web app template, they’ll typically be opinionated and offer some sort of app state management setup by default
(eg. luminus, liberator, pedestal)
lein new luminus
State is kind of auto when I read erlang code (I don't program erlang, but a friend does)
each of the popular ones have a few options (eg. if you want to set up a frontend SPA using cljs and a react wrapper with the figwheel dev tool)
I will take that as a reference to lean how to manage state in clj... but I'm not building a web app, at least not for now
yeah - erlang is definitely a bar other langs should be aiming for. Clojure tends to be better for pragmatics (high performance, library availability) but definitely isn’t as resilient
if you aren’t making a web app, you could just start with the example code on the component or integrant github pages
Mayber one day this will be good (https://github.com/jfacorro/clojerl)
since the web apps are doing a bunch of setup you probably don’t care about
Okey, thanks @noisesmith
well, that loses the library and performance benefits of clojure
there’s also LFE which is inspired heavily by clojure
it’s definitely the lispy erlang that I hear about the most at least
it’s not nearly as much like clojure as the one you linked though
when i push my project to heroku while it's doing it's thing i get
WARNING: Use of undeclared Var cljs-time/core at line 634 /tmp/build_0f5901ac8b59834755b6b827adb2602c/target/uberjar/cljsbuild-compiler-0/cljs_time/core.cljs
http://htembh.herokuapp.com - app error
google cant help me what do i do?@lepistane your app is a ClojureScript app?
Mmh. I am not familiar enough with Clojure/Script to help about the warning, but until someone more competent than I shows up: what happens if you ignore the warning? 😄
(you don’t need to add it; Heroku adds it automatically, you will only need to use it in your Clojure code)
Not sure. Is your code exactly matching a luminus template? And in that case, can you send me the command you used to generate the project?
https://github.com/StankovicMarko/htembh - project
added heroku remote
then git push heroku master
@lepistane ah, it’s already using the DATABASE_URL env var, so it should just work once the heroku addon is provisioned
On the readme of that github project it mentions you should load a bunch of sql files in the DB. This should guide you in how to connect to the DB from your laptop: https://devcenter.heroku.com/articles/connecting-to-heroku-postgres-databases-from-outside-of-heroku
I would personally just get the connection string and use a GUI (e.g. Sequel if you are on os x)
also 😞
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
if you cannot then follow this https://devcenter.heroku.com/articles/connecting-to-heroku-postgres-databases-from-outside-of-heroku and run the migration locally
All the SQL files are there https://github.com/StankovicMarko/htembh/tree/master/resources/migrations
they are not objects
even those are not actually private (the vars are still globally accessible)
but regardless protocol methods cannot be marked as private - the whole point of implementing an interface or a protocol is to provide a public implementation
(since we hardly ever have mutable state in Clojure, you might ask yourself "What do I want private functions for?"...)
I believe a true private would be a useful security tool. I think its one of the reason Java 9 is going back to private having no mechanism of being accessed at all.
But I'd rather see it as its own thing, like mark something as secure, or even better, having first class capabilities of some sort: "https://en.wikipedia.org/wiki/Capability-based_security"
So you could restrict access to certain Vars to only specific code which had explicit access.
I'm thinking:
(def ^{:secure :login} creds {:user "aa" :pass "bb"})
(defn ^{:permission :login} login [] ...)
Then at compile time, :login is replaced by a crypto-key, and access of creds is automatically authenticated with it. The login fn would know it, but no other method would.@seancorfield the only use-case I can think of is trying not to leak implementaton details out of namespaces
use multiple namespaces then
well I’d say the main reason is to communicate to a user which parts of a namespace I publicly commit to supporting