This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-04-08
Channels
- # admin-announcements (7)
- # aws (5)
- # beginners (37)
- # boot (39)
- # cider (4)
- # clara (2)
- # cljs-dev (32)
- # cljsjs (1)
- # cljsrn (12)
- # clojure (235)
- # clojure-austin (3)
- # clojure-belgium (7)
- # clojure-berlin (11)
- # clojure-dev (36)
- # clojure-france (10)
- # clojure-japan (10)
- # clojure-poland (2)
- # clojure-russia (39)
- # clojure-uk (4)
- # clojurescript (81)
- # code-reviews (9)
- # core-async (6)
- # core-logic (1)
- # datomic (32)
- # editors (7)
- # emacs (1)
- # hoplon (191)
- # jobs-discuss (14)
- # juxt (4)
- # lein-figwheel (4)
- # leiningen (3)
- # off-topic (7)
- # om (49)
- # onyx (34)
- # other-lisps (1)
- # overtone (11)
- # parinfer (1)
- # proton (5)
- # re-frame (11)
- # reagent (12)
- # spacemacs (2)
- # untangled (90)
- # yada (15)
So, I was in here yesterday with some questions about namespaces, and I think they've only expanded over the last day or so. Are there any really basic namespace mistakes a beginner is liable to make that would prevent vars in a namespace from being accessible? Or obvious things to look for in the error message that would tell me if I'm in (or have access to, in the case of something like 'use') the namespace in question?
Apologies for being vague, I would be glad to provide more information on what I've specifically tried but I don't want to text dump.
in-ns is a very low level tool to manipulate the namespace that following forms will be compiled in the context of
if you (in-ns 'foo) will drop you in the foo namespace, but won't set the namespace up for easy access to the functions in clojure.core
and speaking of foo, outside of sort of toy examples you shouldn't use single segment namespaces
namespaces don't really have any kind of access control, vars in a namespace can be marked as private, which means the compiler will throw an error if you try to use them outside of that namespace, but it is hard to do that accidentally (and you shouldn't do it anyway)
new comers (and old salts) sometimes start thinking of namespaces as being hierarchical, but they are not, just a flat single space of names
namespaces are largely compile time contexts, they are used by the compiler when generating code, but not really used by that generated code at runtime
Hrm, I'm getting the same unable to resolve error when I use in-ns, which I guess means it has to be down to the clojure file itself, but it's just copy-paste from the ring getting started tutorial
if you want your code to be available at the repl, you need to load, usually using 'require'
One second, I am just looking over everything again because it is still not cooperating.
if require is throwing an error about not being able to find the namespace, your files on disk aren't in a directory structure that matches the namespace, or the root of that structure is not on the classpath
I thought so but I realised there was a duplicate and I am moving the one I want because I think that was the problem
if you edited the file, make sure the namespace still corresponds to its name and place in the directory tree under src
if I recall, that doesn't matter and lein will just figure it out as long as you are in the tree
for long and laborious reasons, when you have '-' in a namespace name it needs to be a '_' in the filesystem, since you didn't get an error from the require, you must not be reporting what is happening correctly
the error you are reporting there is from the compilation of the (run-jetty ...) form
you need to either refer to the names from that namespace in fully qualified form, or make them available in an abbreviated form in the current namespace (the default current namespace is user, as seen in the repl prompt)
the easiest way to make the symbol 'handler' in the user namespace resolve to 'handler' in the namespace you required is to alter the require form to do that
there are dedicated functions to do it, but it is generally done using require or even more commonly using the (ns ...) form, which has the ability to run requires and other similar things for you when first setting up a namespace
Ok I clearly need to dedicate serious time to actually figuring these out, but that worked
http://clojure.org/reference/namespaces has some links to namespace related functions and macros, and has some namespace related documentation that is likely to wiz by without context, but just keep it handy for later
Though I'm now really unclear as to what use is, because I thought it was require with :refer for free
Whatever, in any case it's more information about the language I should familiarise myself with.
vars are in some sense a compiler detail leaking out, but they end up being super useful
depends who you ask, some people would call it a reader macro (in fact clojure's reader calls { a reader macro)
my understanding is at least some lisps have allowed users to arbitrarily extend the reader, and that facility is traditionally called reader macros
clojure (and lisps in generally) have many more sort of phases in the lifecycle of code than C does
{} is syntax
macros let you take s-expression like things that are Clojure-ish and turn them into Clojure code
reader macros would let you read arbitrary things that weren't s-expressions
the problem they introduce is that if you don't have the reader macros, you can't read the code
so Clojure constrains you, but makes things universally readable
but gives you back some flexibility to create custom data with tagged literals
tagged literals can be read and passed on without being semantically understood
#_ is another interesting read macro to throw away the next form
yeah, they nest so that's a good trick
reader conditionals also do this trick of reading selectively
it's still reading {:a}
only ;; will prevent that
Hey so, I wanted to reiterate my thanks because I think now I've figured out how to do what I was trying to do more conveniently and in cider so the workflow makes sense
@escherize: when using #_, all of the forms ‘inside it' still need to be syntactically valid, they are just discarded after being read
e.g. mismatched parens and square brackets will break it
yeah, I guess? I don’t really use (comment) but it makes sense it would be the same
yep, just checked
thanks @danielcompton :]
#_
is useful to remove a single form, (comment ..)
is useful to "remove" a series of forms -- although it produces nil
instead.
I tend to only use (comment ..)
to wrap examples of code usage when I'm thinking out loud about how things should hang together -- and you can still evaluate forms embedded in (comment ..)
in Emacs with CIDER
@hiredman: @zentrope I must have missed the answer or something, so, did I get this right? you should not "dissoc" components on stop? Just leave it like it is if there is no shutdown function or something similar?
what would be the best approach to monitor the http traffic going over the wire when using http-kit client ?
@sveri: no, the issue is, dissoc from a record turns the record in to a map, if your stop implementation dissocs from 'this' the result will be a system full of maps, no records, and you won't be able to start the system again
@hiredman: Now as you say that, it totally makes sense, so, you say it would be better to just return the component as is in the stop function?
@lmergen: maybe https://github.com/plexus/tracer-gui is helpful? (shameless plug 😉)
Do you want to inspect outgoing http requests? Should be possible as well but haven't tested it
@plexus: well actually, this solves a very real problem for me as well, which is that my (strict) compojure-api
specification sometimes rejects incoming requests (400 Bad Request) before I can even inspect the request in a handler.
I am looking at pedestal and needing some design advice. We are trying to talk to an existing postgres database, and from a pedestal design with interceptors what would be a good way to integrate this access into the services ?
@lmergen: you can intercept all request validation errors with c-api server-side too, they have type :compojure.api.exception/request-validation
I have a question regarding keywords: In clojure, keywords can behave like functions e.g. (:a {:a 36})
. How does it work?
hi folks. thinking of using one of the public images for clojure from docker hub. At a quick glance neither lein or boot seem to explicitly download or refer to clojure. Is that something that the tools handle under the covers?
@dominis: cool. thanks
viebek: keywords are invokable (implement the IFn interface) as if they were a function that took an associative data structure. the implementation of that function calls get on that data structure with itself as the key.
So how does it work for keywords?
viebek: the keyword class is defined in java as extending IFn
, it's not defined and then extended to IFn
So in a sense, clojurescript is more powerful than clojure!
in a sense javascript is more powerful than java!
in a sense the browser is more powerful than the server 😂
I’m kidding 😃
@bronsa: what about creating a custom type that could behave as a function. Is it doable in clojure?
And implementing what protocol?
The clojure.lang.IFn
interface
Ok. I’m testing it...
Hourra! The following works in clojure
Thanks @bronsa and @donaldball
I’m writing an article about extending IFn in clojure
I’d like to point out the differences between clojure and cljs
the big differences are:
1. IFn is defined in java in clj while in cljs it is defined in cljs
2. base types are not extensible in clj; they are extensible in cljs (although it is very dangerous)
any other differences you guys are aware?
protocols are a clojure concept, interfaces a java/jvm one. protocols are open, interfaces are not
you can extend any type to a protocol, you can only make classes you define implement an interface
hmm… very interesting
I guess that is is for legacy (or maybe perf) reasons
I’d expect a lot of java code from clojure repo to be re-written in clojure
I once heard about a project named: “clj in clj"
Do you see what I mean?
I find myself using this pattern fairly often:
(loop [thing (get-the-next-thing :with :lots :of :stupid :arguments)]
(do (stuff :with thing))
(recur (get-the-next-thing :with :lots :of :stupid :arguments)))
which rubs me the wrong way due to calling get-the-next-thing twice for what is the same operation.
Is there a better way to get around this other than something like this:
(loop [thing nil]
(when thing
(do (stuff :with thing)))
(recur (get-the-next-thing :with :lots :of :stupid :arguments)))
?but it's not an an official clojure effort, and it currently only focuses on the compiler bits. what you'd want is the whole runtime to be rewritten in clojure, and that's hardly going to happen
could you share a link to this project?
Somehow cljs made it a reality...
@viebel: the original CinC project has been split into a set of libraries: https://github.com/clojure/tools.reader https://github.com/clojure/tools.analyzer https://github.com/clojure/tools.analyzer.jvm https://github.com/clojure/tools.emitter.jvm
thx @bronsa could you quickly go over my article to make sure I didn’t write any big inacurracies?
It’s a honour for me to chat with CinC author!!!
Thanks!
BTW, did you play with http://app.klipse.tech ?
I think it’s great for education/blogs etc...
Do you know any good communication channel I could use to let the community know about KLIPSE
I have tried in the google groups but it was not a success.
@viebel: Seems like the clojurescript and announce-to-everyone channels here would be the right place to announce or ask that question.
I made a type on clojurians 😞
@dominicm: happy to hear
@viebel: it may intereste you to know then that Klipse murders mobile safari and crashes my rss reader (ReadKit)
I know and I have fixed it a couple of hours ago
@mrg: please confirm that it works on safari now
@viebel: you can change your username from https://clojurians.slack.com/account/settings
@mrg Could you give me a confirmation over twitter when you are home?
if you want to make it so you will always have say 2 spaces in front , you could decrement l in the recursion but change the comparitor to (> l 0)
http://accidentallyquadratic.tumblr.com/post/142387131042/nodejs-left-pad brings up some things to think about writing left-pad in a language with immutable strings
does anyone know if there are alternatives to drawbridge for securely running a repl in a production server?
@codonnell ssh tunnel with port forwarding?
@curtis.summers: that would work! thanks for the suggestion.
I thought I saw someone used an ssh library to make a repl you could directly ssh in to
that would be interesting
I'm not sure adding an extra dependency would be worth it to avoid ssh tunneling with port forwarding