This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-27
Channels
- # bangalore-clj (1)
- # beginners (27)
- # boot (16)
- # cider (14)
- # cljs-dev (94)
- # cljsrn (8)
- # clojure (229)
- # clojure-dev (5)
- # clojure-dusseldorf (6)
- # clojure-italy (8)
- # clojure-norway (8)
- # clojure-russia (22)
- # clojure-sanfrancisco (2)
- # clojure-spec (48)
- # clojure-uk (44)
- # clojurescript (47)
- # core-async (87)
- # cursive (43)
- # datascript (22)
- # datomic (20)
- # defnpodcast (5)
- # emacs (6)
- # hoplon (4)
- # jobs-rus (4)
- # keechma (2)
- # klipse (8)
- # leiningen (2)
- # luminus (2)
- # lumo (14)
- # om (38)
- # onyx (4)
- # overtone (3)
- # pedestal (41)
- # planck (72)
- # powderkeg (42)
- # proton (46)
- # protorepl (9)
- # reagent (9)
- # ring (47)
- # ring-swagger (5)
- # rum (7)
- # sql (22)
- # unrepl (1)
- # untangled (24)
- # vim (19)
- # yada (5)
it's not just a convenience - being able to do something in a local scope is an important feature - the semantics are different
@bcbradley what do you mean? spreading ns stuff across multiple files?
you are aware of https://github.com/ztellman/potemkin?
or is it like the major thing in maven? I want to say something like lwjgl-clojure.package-name/function-name
bcbradley there are no rules about package names, except for how they map to the class path
package name doesn't imply access the way it does to javac
and it need not be related to the artifact or group defining it
(but good practice is to use package names that make sense of course...)
so you are saying i could use the name lwjgl-clojure.glfw
for one "package" aka "library", and lwjgl-clojure.openal
for another?
I don't know how that would make them separate libraries, but OK
@bcbradley sorry, i don't follow you. please post the code that is giving you trbl.
you can nest packages however you like
for instance each class there would be a namespace-- according to what i had planned to do
you can have as many packages as you want in one library
(or as few)
right, and each namespace has a package
the package is the prefix leading up to the namespace name
Um no sorry
when functions inside a namespace are compiled, they become classes, and that defines the package those classes will be in
Clojure really has no concept of packages.
@bcbradley : what exactly is causi g trouble. please post code so we do not need to guess.
Maven might, but Clojure just looks for classes on the class path. And files that match the namespace name
i'm wondering how i should organize what i'm making, not fretting over a line of code
@tbaldridge but when my function foo is compiled to foo.class the jvm thinks that class is in a package, no?
not that this "package" does much - but it's there
@bcbradley well i'd like to help, but unless you can be more specific i cannot.
here is the gist of it: C has no namespaces so when you look at opengl code you see that every function begins with gl
, and its annoying. It wouldn't be too annoying to deal with except that java has no namespaces either (it has classes) and with lwjgl opengl
is a package that contains a bunch of classes (for instance gl11
), so the fact that both of these languages don't have namespaces forces you to say gl
twice if you want to use it through interop in clojure
i want to make it less painful to use these native libraries from clojure, so i'm making a clojure library or set of libraries to strip out the nonsense and just use namespaces (since clojure has them)
@bcbradley just stick it all in one dependency, with 30 namespaces. No reason not to do it that way
(but to be honest, writing gl 4x times really isn't a show-stopper in any GL app I've worked on)
@tbaldridge so each "package" in lwjgl would map to a "namespace" in clojure?
some of the classes have functions with identical names, so i can't just flatten it into one namespace
i figured the only way to do this would be to have each package become its own "library" or dependency, and each class to become its own namespace
why make them separate dependencies? why not have multiple groups of namespaces in one library?
you can nest the directory paths however you like if you feel like grouping them
I don't even know why they would need grouping, but sometimes that makes the relationships clearer
i mean i guess i could just make one dependency and have each namespace name be the concatenation of the abbreviated lwjgl package name and class name
rather than multiple dependencies in order to use one library, yes
It seems to me the simplest solution would be something like clojure-gl.gl.10/vertexf
So top level is library name, then "package", aka, GL, CL. Then the version number. And in that namespace are all the functions for that version/subpackage combo
People can use (:require [clojure-gl.gl.10 :refer [vertexf])
to remove some of the name redundancy
yeah, that works too
based on what noisesmith was saying it would be easier for people to depend on if all the libraries came together under one dependency
lwjgl comes with a bunch of native binaries that it depends on, depending on which packages you need to use
Well to be honest, at that point ^^ all you're saving is this: in lwjgl I can simply do (:import [.... GL])
then do: GL/glVertexF
which not only matches all the OpenGL documentation (that's huge), but isn't that much writing either
the extra gl is annoying, besides i've already produced the data structure that describes lwjgl
But one more point: Any serious GL work is going to use shaders and vertex buffers, so you end up writing GL
even less...and you write it once, and then you're done.
i spent some time going through the entire library and making a record of all the annoying repetitive namespaces being prepended to the function names
Personally I don't find library that reduce a few characters in typing that useful.
the other thing i wanted to do is have a clojure library for this stuff where you could pull up the documentation in clojure
besides, using java interop for this stuff can be annoying too once you start to try to build abstractions on it, often you have to wrap the java interop in an anonymous function to use ifN
But you have to consider this: going agains a few decades of OpenGL programming guides isn't going to be that helpful. I would rather be able to download the NeHe tutorials for Java and just copy most of them
i realize most people wouldn't go through all this just to sanitize some names and i guess it is a lot of work for something trivial
in any case its already basically done, so that isn't really a valid concern (would have been a few weeks ago)
so if each package has a native dependency associated with it, would i be better off making each package a separate library?
is there something like group-by crossed with index? Like group-by, except instead of {:key [item]}, {:key item} (I know keys are unique.)
I usually do (defn index-by [k coll] (into {} (map (juxt k identity)) coll))
- uses a transducer, it's a small bit of code, it works
definitely not something that exists in clojure.core
note the usage of map transducer instead of calling map on the coll
I’m writing here because #clojure-sanfrancisco seems to be deserted. Anyone in SF Bay Area? Are there any meetups here?
yes we have a bunch of people in the Bay Area 🙂 the meetup in SF is pretty regular, here’s link https://www.meetup.com/The-Bay-Area-Clojure-User-Group/events/231945973/
@bcbradley I don't follow everything in above discussion but seemed like inadvertent 3-way misunderstandings to me. Noisesmith's point is that you can add as many dots to a namespace name as you want, as long as you put source files in a corresponding directory structure. If you have a lot of namespaces that will give them more order, but won't do anything else. Maybe that's already clear. Maybe that's all you need? Or is the only misunderstanding mine?
I’m trying Lacinia, the GraphQL library from Walmart. Where is the best place to ask questions about it?
Is anyone doing clojure app clustering? What do you use for remote logging/monitoring instances? Doesn’t matter if it’s a commercial service
@singen we've been using ELK for logging... pipe stdout logs to host (mounted) syslog in docker container -> logstash-forwarder -> logstash -> elasticsearch+kibana
@ido @schmee no need for selected?
there, [MAP-VALS even?]
is equivalent
@singen ELK here too, all logging to stdout.
discussed between logstash and fluend
I want to run live/repl mode in docker swarm. When I try to run lein repl swarm service with this code; docker service create -w /olexibus --mount type=bind,source=/root/app/corporate/olexibus,target=/olexibus -p 3000:3000 --name corporate --network olxnet pandeiro/lein repl I get full repl initialization while repl input turn. It’s says "Bye For Now” like end of repl session. But I didn’t enter anything.
You probably need to allocate a pseudo-terminal (with -t
). Otherwise, the repl doesn't have stdin.
fwiw. This is a docker topic, not specific to Clojure. https://docs.docker.com/engine/reference/commandline/service_create/#add-bind-mounts-or-volumes
is there some obvious reason that there is no map-zipper
in clojure.zip
that I’m missing?
seems like xml-zipper
is a special case of a map zipper
I'm having trouble java-interopin' these chained calls: String logoutUri = UriBuilder.fromUri("http://localhost:8180/auth") .path(ServiceUrlConstants.TOKEN_SERVICE_LOGOUT_PATH) .queryParam("redirect_uri", "http://localhost:8080/product-portal") .build("Realm") .toString(); to clj: logoutUrl (-> (UriBuilder/fromUri "http://localhost:8180/auth") (.path ServiceUrlConstants/TOKEN_SERVICE_LOGOUT_PATH) (.queryParam "redirect_uri" "http://localhost:8080/product-portal") (.build "Realm") (.toString)) I get "java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Object;" (on line 2)
fbielejec that makes me think one of those calls is actually varargs
to do varargs, you need to put all the “extra” args into an array of the right type (in this case it wants Object, clearly)
(into-array Object [s1 s2 …])
I assume queryParam is vararg, from context
or maybe path is
@noisesmith it's a bit hard to debug, becasue I uberwar and deploy to a container (wildfly)
ok - it’s build that is vararg
change (.build “Realm”)
to (.build (into-array Object [“realm”]))
oh, and the same change is needed for queryParam
- oh, that’s a little different (.queryParam “redirect_uri” (into-array Object [“
fbielejec try adding items to the -> in your repl, one of those lines at a time
it should need both, according to the api docs
clojure interop with java is great, except varargs are kind of clumsy (and inheritance …)
glad I could help
I wonder how hard it would be to make something like ((varargs foo object-instance arg arg2 type) arg arg arg) and turned it into (.foo object-instance arg arg2 (into-array type [arg arg arg]))
Have a luminus re-frame app, and looking to let someone run it who is new to clojure... is there a way to get a lein run
that includes all the cljs steps?
that’s not an ideal syntax I guess - but there should be a nicer way to do it
albaker you can define the :prep-tasks for the profile run uses, or have them do lein do cljsbuild once, run
lein help sample
has examples for setting up :prep-tasks
@ddellacosta wouldn't you use seq-zip most of the time?
@bja I must be missing something because that doesn’t seem to know what to do with the map I’m passing in
@ddellacosta no I'm missing something
yeah, I assume that seq-zip
wants a seq
@fbielejec I was thinking about how clumsy varargs can be - this macro appears to work
=> (defmacro vararg
[method object & args]
(let [[regular [_ t & variable]] (split-with #(not= % '|) args)]
`(. ~object ~method ~@regular (into-array ~t ~(vec variable)))))
#’user/vararg
=> (macroexpand-1 '(vararg get java.nio.file.Paths "foo" | String "bar" "baz"))
(. java.nio.file.Paths get "foo" (clojure.core/into-array String ["bar" "baz"]))
=> (vararg get java.nio.file.Paths "foo" | String "bar" "baz")
#object[sun.nio.fs.UnixPath 0x14ebb640 "foo/bar/baz”]
@bja I’ve been using this definition FWIW: http://stackoverflow.com/a/15020649, it does exactly what I need
seems like the obvious implementation in terms of how it behaves. Just curious why that or something like it isn’t included by default.
@noisesmith nice, I'm saving it
let me know if it fails in some unexpected way - for simple stuff it works so far though
I’m a little skeptical of 10 minute old macros on principle 😄
I like that macro @noisesmith
oh yeah, … is probably more readable there
easy enough to swap in
I wonder how it handles hinting
CLJ-440 has been open for years. Probably should be closed IMHO unless someone can find some new vararg interop syntax that has 0 implications on existing code
Is it appropriate to ask the idiomatic way to do something in clojure here? I've only been doing funcitonal/clojure programming for about a week and am trying to improve on how some of my code looks/works.
@greg_arcara always better to just ask the question 🙂. But sure, here is a good place or also in #beginners
@tbaldridge #beginners sounds like a good place for me hah
thanks
can someone help me translate this psuedocode to Clojure?
01 function negamax(node, depth, color)
02 if depth = 0 or node is a terminal node
03 return color * the heuristic value of node
04 bestValue := −∞
05 foreach child of node
06 v := −negamax(child, depth − 1, −color)
07 bestValue := max( bestValue, v )
08 return bestValue
lvh something like this?
(defn -negamax [game depth color]
(if (or (g/game-over? game) (= depth 0))
(* color (evaluate game))
(apply max (map #(- (-negamax % (dec depth) (- color))) (advances game)))))
this is one of the few times where I’ve seen an imperative approach be much cleaner and more readable then the functional one
yeah, wait, I’m just an idiot. I used to have a bunch of atoms in there but I don’t need those anymore
okay, the next step for this seems a lot trickier… https://en.wikipedia.org/wiki/Negamax#Negamax_with_alpha_beta_pruning
heh, someone already did it, and got stuck in the same place as me: http://chongkim.org/programming/2013/05/29/an-elegant-negamax-with-alpha-beta-pruning-in-clojure.html
>>> Note The flaw in this code is that it is not updating the alpha after checking each child. It does get set when the cousins are calculated. This means I will need to write a new function that combines the map and take-while.
@schmee something that might help is reduced form with reduce
specifically for the if val >= beta return val
part
notice that there would have been an exception thrown if it got to nil - it effectively short circuits
schmee the alteration of alpha directly translates to part of the reduce (based on the code snippet on the chong kim site)
instead of foreach you have reduce, instead of changing alpha you return an accumulator with the new alpha in it, instead of the early return of val you use (reduced val)
it all translates directly without mutation
oh, and val would also be a value in the accumulator
is clojureql dead? all the doc sites are down and the last commits were years ago. asking because it seems to be the way to get data from a sql db into incanter.
You should be able to use to-dataset
from a sql library of your choice, since most clojure sql libraries return a sequence of maps
and...the incanter project itself seems to be pretty much dead, but you can find some discussions in #incanter
There’s also #sql channel for any SQL topics
@schmee essentially (reduce (fn [[alpha val] child] (cond (> val beta) (reduced val) (> val alpha) [val val] :else [alpha val]))) init node)
oh wait there’s also the part where val gets calculated - exercise for the reader, heh
but that should be pretty close to a working pure version of the foreach
you seem to have this one in the bag, I might just ping you if a need the answers sheet for this one… 🙏
Every time I see Dakrone
I think "Dankthrone" which sounds like a rad Stoner Metal band
1. I am writing code in cljs. 2. This code requires a macro. 3. I wrote a macro in a clj file. 4. This macro does something stupid and throws an exception at compile time. 5. The error I get back from the cljs compiler does not seem very helpful. 6. Is anyone else running into this problem?
@qqq wrap the macro in a try catch and .println to System/out
@adambros: I'm not sure I understand. Are you suggesting:
(defmacro ...
(try ....
(catch / println )))
?Sorry I'm on my phone, but basically yes
That way you control what you see, it's usually helped me, as the unhelpful errors are a npe and it just give me one line
It's (catch Exception e (.println System/out ...))
Is there a function like this in core, specter, or somewhere else?
(defn apply-if [f p x] (if (p x) (f x) x))
I find that I need this a lot, to e.g. optionally do a transform in a (->> …)