This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-16
Channels
- # beginners (103)
- # boot (48)
- # cider (2)
- # clara (12)
- # cljsrn (9)
- # clojure (133)
- # clojure-art (3)
- # clojure-dev (9)
- # clojure-korea (7)
- # clojure-russia (228)
- # clojure-spec (8)
- # clojure-uk (26)
- # clojurescript (131)
- # cursive (8)
- # datomic (30)
- # emacs (4)
- # events (2)
- # hoplon (47)
- # lein-figwheel (5)
- # off-topic (1)
- # om (12)
- # onyx (337)
- # perun (23)
- # planck (15)
- # proton (3)
- # re-frame (5)
- # spacemacs (20)
- # untangled (97)
- # utah-clojurians (1)
- # yada (13)
Hi, I’m trying to generate a java class that would be used as a Builder in the builder pattern. I can get it to work but it’s kind of a strange compile process. Is there a standard way to return self in :gen-class ?
@brycecovert nice, I had thought of doing exactly this which is why I mentioned FFI. There's plenty of things in other languages doing FFI to curses, so lots of examples to reference and improve upon. Just depends on the use-case. Was thinking of releasing some lighter-weight escape sequence parsing/ansi colors related stuff with a friend, eventually for those that don't need a full virtual term.
@hugesandwich very cool. best of luck to you! I’ve also seen some clojure folks use Lanterna, but, of course, it’s not a real terminal either.
I want an ADM-3A
I have kind of solved my own problem but it feels very hacky. I’m still curious if there is a more standard approach. https://stackoverflow.com/questions/40622226/have-clojure-generate-a-java-class-which-is-used-like-a-builder-pattern
Basically, I created a precompile folder and have a file that generates and empty builder.class, the class is overwritten when the general compilation happens and the return values reference the previous builder.class which enables it to compile.......heads spinning
@etherfuse I think this answer is what you are looking for http://stackoverflow.com/questions/29329798/clojure-gen-class-returning-own-class
I notice that when generating transit+json response, special characters like german quotation marks and special back-ticks are turned into question marks. Is there a way to force the response to be utf-8 even when the Content-Type header is set to "application/transit+json"
?
so usually the problem occurs when reading the source data or the emitted data as something else
ok, Im sending an html snippet, which has these characters within its contents. I see from the front-end log in om that the question mark is there already on arrival. But not in the slurp from the backend.
no at no point I manually set the encoding. I slurp the snippet, store it in atom, and send it via
(defn generate-transit-response [data & r]
{:status 200
:headers {"Content-Type" "application/transit+json"}
:body data})
I see in my repl when I dereference the atom this: “live code”
in om I have ?live code?
(hard to see but the these are german quotation marks).
1 min.. repl restart. Yes I would find dangerouslySetHTML to be suspicious here. But in my app state I also have the question mark, so its seemingly not to blame.
typically if you don't mention charsets anywhere it defaults to utf-8 in java/clojure
ok, @thheller I should buy everyone on this channel a beer, for noticing that Im actually not using this transit response function, but I noticed looking deeper in the code that Im doing at other place "Content-Type" "text/html"
so I was asking for a help for a wrong problem.
Im have done the atom and ref chapters of the clojure koans. For real applications can I better use atoms or refs or is this my own preference ?
@roelofw the choice depends on the use case. Atoms are for uncoordinated updates, and refs are for coordinated updates. I've never had a use case for refs personally, I suspect atoms are used much more often.
@roelofw note that the applications I've been developing on Clojure JVM (web apps backends mostly) usually require very little state management (which is mostly done at the level of the database).
oke, so if for example I want to update two financial accounts , I can better use refs
@roelofw or you can hold the state for boths accounts in an atom
what in your applications requires this state to be kept in memory though ?
sure, it's only a matter of data format
so, is it for caching purposes? (I'm insisting on this, having grown suspicious of most use cases for stateful references on the server side )
ah, so it's a GUI application ?
@synzvato have you tried interleave
?
(not interposeb ut interleave, corrected)
something along the lines of (into [(first coll-1)] (interleave coll-2 (rest coll-1)))
@roelofw alright, well in any case be careful with stateful references, for most web application use cases they have no role to play in your server-side application code 🙂
@roelofw what I mean is that you usually want your server-side program to be stateless, and if there is state, it should be scoped globally (typically shared between instances of your server via a database). The use case for process-scoped (which is what atoms and refs give you) application state is rare
if I have a loop
that can easily be rewritten as a reduce
, is it weird to do so if the loop
has side effects as well as producing a result?
Is it possible to have a type hint on an atom or volatile, so when you do (.foo @my-volatile), it knows the class?
I very doubt it
@borkdude does this not work ? (.foo ^MyClass @my-volatile)
@val_waeselynck of course, but then I would have to repeat it everywhere I deference the my-volatile. Not a huge problem, but just want to know if there is support for that
ha, yeah I doubt it indeed
yeah, or make sure that all the code that consumes the value downstream is type-hinted
e.g in function parameters
anyone have experience with a webapp running in tomcat? I'm creating a zipfile for download and running into issues with permissions in creating the file
and I'd like to move to just having the file in memory of course, but this is what i have at the moment
i'm a .NET developer so all of the different streams are very strange to me at first glance
but i'm creating a zip file, everything works locally, just lack permissions to create the file on the server it seems
if u are running it on some linux box, u will need write permissions on the directory in which you are creating the zip file
you could start by chmod 777 __
ing it to make sure that works
otherwise you have weirder problems
also I don’t think creating archives in the same directory is a good idea, that directory is expected to be cleared on a new war deployment
you should have an explicit directory someplace where you do the file stuff, it shouldn't be in the same directory where tomcat is putting war files
I think java file API has an explicit method for creating temp files, if u need a temporary file, that is the right way to do it
here it is = https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createTempFile(java.lang.String,%20java.lang.String)
Kind of a java/framework interop question but we have a lib (lets call it "clj-foo") that pulls in a big java library, and then clj-foo is used by a bunch of apps. One problem I have is that the upstream library depends on logging and json libraries which clash with those used by other dependencies. Looks like I could exclude the problematic dependencies in clj-foo's project.clj with the understanding that the app would bring in it's own versions of these things. Is this a good idea? Is there any downsides I'm missing?
@cddr yes sounds like you want a combination of :excludes in the dependencies, and :provided
can someone help me with a macro?
so, I need inside a macro, inside unquote splicing block ~@
to call another function, this works fine if I call function directly,
but if the function I want to call is referred through another function that doesn't seem to work. It throws null pointer exception.
something like this for example:
(defn get-fn [b]
clojure.core/str)
(defmacro foo
[bindings]
`(do
(defanothremacro bindings
~@(map (fn [x]
(let [bar-fn (get-fn x)]
(bar-fn " - " (first x))))
bindings))))
@ag what would you like to achieve? what is defanothermacro
? can you show the call which throws npe?
so for example if instead of (bar-fn “ - “ (first x))
I do: (str “ - “ (first x))
- it works, right? But when I reference to str
through another function - it doesn't
there’s some quoting/unquoting needed, defanothermacro
doesn’t matter - it’s just to demonstrate why the first quote there (before do
)
@ag you should probably unqoute that bindings
after defanothermacro
- but other than that, I see nothing
@ag when/where do you get the npe? during macroexpansion? at runtime? do you have a stacktrace?
I think there are too many missing details to debug this
the mess that prevents you from posting your code probably contains the problem :)
ok, I still can’t figure it out: so there’s body-fn
how do I properly call it?
https://gist.github.com/agzam/49df3515235a080628f86d7893507d0c
so the last thing would macroexpand properly?
@ag if the call to body-fn
is throwing a NPE, I think the first guess is that your case
on line 2 is not dropping to the default clause
if you comment lines 3->9 do you get that same NPE?
Please remember that this is a professional space and use language appropriate to such (with my Clojurians admin hat on).
Also, as a general reminder, the Code of Conduct for Clojurians is here https://goo.gl/VsJ8q8
https://www.youtube.com/watch?v=824yVKUPFjU <-- TeX in Clojure <-- is this open source anywhere?