#clojure logs

2015-05-23

00:02justin_smithalso, if you need more rationale about top level state / side effects, consider what happens if you compile your code to a jar for deployment
00:03justin_smithor if you want to edit your code and not need to restart your whole vm
00:04WickedShellyeah I'm having the restart vm problem like crazy, not sure if theres a workaround for that though if it requires seesaw/java GUI/tie in. If thats not the case please stop me now :/
00:05justin_smithWickedShell: stuartsierra's component lib can fix the restart issue if you design your namespaces well and use it as intended. At the very least you'll need to stop and start your vm much less often.
00:05WickedShellhmmm sounds promising, watching his talk atm (still unsure how that happens yet with the java side of it but looking forward to finding out)
00:07justin_smiththe talk is good. Big picture answer is that anything stateful should be provided by a component that knows how to initialize it, and then you can explicitly declare which components use which others internally.
00:07justin_smiththis allows reliable cycling of component state without having to restart the vm
00:08WickedShellI guess the part that I'm tripping up on that is, that the java GUI builds a lot of links which need to be maintained to avoid a nullpointer on layout/repaint so I think it would have to rebuild all of it? (which is still probably faster then a full VM restart)
00:08justin_smithYes, much faster. Clojure loads its compiler pretty slowly.
00:09justin_smithso the GUI component would have a stop (the cleans up and destroys the window) and a start (which creates and initializes a window) and anything that needs to access or manipulate GUI state would then declare its usage of that component
00:10justin_smithand you would access the GUI and its constituant parts as needed, not via vars in a namespace, but via args supplied at component start time
00:10WickedShellyeah, the problem is right now I have the components spread out and controlled in their own sub region, which I suspect is not a good plan/practice
00:10WickedShellie some gui parts are built in one namespace and others in another namespace, which seems werid
00:10justin_smithand there are two different kinds of things here called "components"
00:10justin_smithheh
00:11justin_smithWickedShell: I could see a sane variant of that. One system component that builds the window at init, another that builds the document display, another that builds the toolbar, etc. If they had a strong separation / independence of concerns that could totally work.
00:12WickedShellso the goal was to do that, it depends on how much you mean by strong seperation though as some of those areas have to share information periodically
00:12justin_smiththe key things is ensuring that you have a clear way to make sure things get initialized in the right order, get access to the state they need to build on, without everything being a ball of mud. the component system makes that pretty straightforward once you get used to it.
00:13WickedShelland I admit each sub part *seems* to be clean, its just the top level that combines them that is a horror, and the part where they need to share information that is a horror
00:13justin_smithright
00:13WickedShellwhich maybe the component part will help with
00:13justin_smiththe component enforces the restriction that the dependencies are a one way tree without cycles
00:13justin_smithwhich helps a lot
00:14WickedShellyeah I made it here without any cycles but I seem to need one at the moment :/
00:14justin_smithalso it gives a straightforward way to specify who needs what, then it figures out hte initialization order for you, based on that.
00:14justin_smithmost cycles can be solved by creating a third entity containing the subset of state used by the two others
00:15justin_smithwhether it loads and controls the other two, or the other two load and control it, is up to your design
00:15WickedShellsounds like the kind of OO hell of creating classes as data carriers to be passed around
00:15justin_smithwell, we don't have classes as anything other than data carriers in normal clojure
00:15justin_smithour functions are first class, not methods owned by some class
00:16justin_smiththis is explicitly about designing your data dependencies
03:22[mad]hi
04:35entityI have the -main to go into a REPL, but it starts in the wrong namespace. Any way to change this?
04:35entityi.e. (defn -main [& args]
04:35entity(while true (println (eval (read-string (read-line))))))
04:36entitywhen launched from the uberjar, this gets me into clojure.core, rather than the namespace at the top of the file where -main is defined
04:37entityah okay, doing (eval (use 'my-namespace)) before entering the REPL seems to do the trick :)
04:39entityby the way, isn't there some better way to launch a repl? this has trouble with cursor movement keys and crashes the whole app when you make a typo
04:57entityhm, okay, I'm trying to launch the cider repl, but the compilation is failing:
04:57entityException in thread "main" java.io.FileNotFoundException: Could not locate clojure/tools/nrepl/server__init.class or clojure/tools/nrepl/server.clj on classpath: , compiling:(core.clj:1:1)
05:50mmeixShort question: if I have a predicate with two arguments, for example: (defn twice? [a b] (= b (* 2 a))) - and I want to use it in negated form, I have to do: #(not (twice % %2)) ... isn't there a more concise way to say this?
05:52oddcully,(doc complement)
05:52clojurebot"([f]); Takes a fn f and returns a fn that takes the same arguments as f, has the same effects, if any, and returns the opposite truth value."
05:52mmeixah, thanks!
05:52mmeixso it gets (complement twice?)
06:13entityI'm trying to itegrate REPL into my app, but the uberjar build is failing: http://pastie.org/10203453
06:14entitycould anyone please take a look? I have no idea what I'm missing; I followed the readme from https://github.com/clojure-emacs/cider-nrepl
07:59smokeinkwhy is Scalar constructor called with two zero parameters? (Scalar. 0 0) the corresponding java code has only one zero parameter http://docs.opencv.org/2.4/doc/tutorials/introduction/clojure_dev_intro/clojure_dev_intro.html#mimic-the-opencv-java-tutorial-sample-in-the-repl
08:15crocketIs Incanter the best machine learning library on clojure?
08:35noncomcrocket: afaik incanter is not really a machine learning thing at all.. it is more about maths?
08:35noncomand statistic
08:40crocketAll right...
08:41crocketClojure seems to be the best platform for machine learning algorithms.
08:41crocketScrew R and python.
08:42wasamasalol
08:43crocketClojure screws R and python for math and machine learning.
08:44mmeixhttps://www.refheap.com/101515 - the three functions at the top: did I reinvent the wheel? Did I oversee something in core to do this?
08:46mmeixI only found coll splitting with one-arg predicates
08:50noncommmeix: ummmmm so, your aim is to first break the sequence in pairs and then split the new sequence in places where pairs satisfy a pred?
08:51mmeixno, I want to split, if a condition is met between two consecutive list elements
08:51mmeixsay the list would be [1 3 4 6 8]
08:51mmeixand I want to split if and only if the difference between two elements is 1
08:52mmeix[1 3 4 6 8] --> [ [1 3] [4 6 8] ]
08:52mmeixso my pred takes two numbers
08:53noncomah, i see
08:53mmeixand would be (= (inc a) b), in this case
08:53mmeixbut this pred should be a var
08:54mmeixmy solution works fine, but I thought, there is a ready made function for this maybe, on core or another lib
08:54mmeix(in core)
08:55mmeixnot reinventing things is the motivation (of course reinventing is fun :-))
08:56noncommmeix: well, aside from the fact that i'd rewrite this with a single reduce, i cannot recall any other ways of doing this :)
08:57mmeixa single reduce: you wouldn't write the helper function, you mean?
08:58mmeix(I mimicked David Nolen's solution in http://stackoverflow.com/questions/2720958/clojure-finding-sequential-items-from-a-sequence)
08:58noncommmeix: yeah, but that is highly opinionated and depends on a usecase i think
08:59noncomaha, that's perfectly fine i think
08:59noncomthere are no such functions in the core that i aware of
08:59mmeixso this would depend on use case and possible modularity
08:59mmeixok, thanks!
10:07entityI made a siple REPL in my -main, but it annoys me that I have to (eval (use .. .. )) multiple namespaces if I want them to be available at startup
10:07entityhttp://pastie.org/pastes/10203661/text
10:07entitynotice, how I use the .genetic namespace at the top of the .core namespace
10:08entitybut then, when trying to bring all the clojure-robby.* namespaces into space in the REPL, I have to iterate through all of them
10:08entityI'd have thought that if NS1 uses NS2, then using NS1 also uses NS2
10:20justin_smithentity: have you checked out the vinyasa lib?
10:21justin_smithentity: namespaces don't work that way
10:21justin_smithuse only creates references in the namespace where use is called
10:22entityah okay, I see
10:23justin_smiththere is no global namespace for things like this to be inserted into - it might almost seem like there is one because everything refers clojure.core automatically
10:33shafirehi
10:33mmeixhi from rainy Austria :-)
10:33shafireWhat was the name of the other clojure ide plugin for eclipse? (I know only ccw)
10:34justin_smithshafire: is there another one? the most advanced clojure plugin right now is probably cursive for intellij
10:34mmeixthere is Cursive for IntelliJ
10:34shafirethere was another one for eclipse, if I rember correctly
10:35TEttingeryep, cursive is pretty excellent.
10:35shafireoh, I think it was cursive :)
10:35shafireand remembered eclipse wrong
10:35justin_smithhaha - shafire says "what's the other plugin for eclipse" 3 people respond "dunno, use cursive"
10:38TEttingerI like CCW, I actually contributed a tiny bit to it back in the day
10:38mmeixif anybody could have a short look on https://www.refheap.com/101515 - the first three functions ... any improvements I could do to them?
10:38TEttingerCursive just uh, has debugging
10:39TEttingerhttp://clojuredocs.org/clojure.core/partition-by
10:40mmeixyes, but partition-by only looks at one value
10:40mmeixwhat I need is comparison from one value to the next, and partitioning based on this comparison
10:42mmeixexample: "split [1 3 4 7 8 11] everywhere, where the delta between two numbers is exactly 1", so [1 3 4 7 8 11] ==> [ [1 3] [4 7] [8 11] ]
10:42mmeixand so on
10:43mmeixanything I'm overlooking?
10:43dnolenmmeix: mapcat first + partition-by + partition could probably work.
10:44mmeixbut I want the pred configurable
10:44dnolen,(doc partition-by)
10:44clojurebot"([f] [f coll]); Applies f to each value in coll, splitting it each time f returns a new value. Returns a lazy seq of partitions. Returns a stateful transducer when no collection is provided."
10:45dnolenmmeix: ah you want predictate
10:45mmeixyes
10:45mmeixin order to have it configurable
10:46dnolenmmeix: well technically partition-by could work, since splits happen on true and false
10:46mmeixI took inspiration from your example in http://stackoverflow.com/questions/2720958/clojure-finding-sequential-items-from-a-sequence
10:47mmeixand liked the way, it can be made general
10:47mmeixwould anything involving partition-by get me more performance?
10:48TEttinger,(let [chord [1 3 4 7 8 11] paired (mapv vec chord (rest (conj chord nil)))] (partition-by (fn [[a b]] (= (- b a) 1)) paired))
10:48clojurebot#error {\n :cause "Wrong number of args (2) passed to: core/vec"\n :via\n [{:type clojure.lang.ArityException\n :message "Wrong number of args (2) passed to: core/vec"\n :at [clojure.lang.AFn throwArity "AFn.java" 429]}]\n :trace\n [[clojure.lang.AFn throwArity "AFn.java" 429]\n [clojure.lang.AFn invoke "AFn.java" 36]\n [clojure.core$map$fn__4554 invoke "core.clj" 2627]\n [clojure.lang.Lazy...
10:48TEttinger,(let [chord [1 3 4 7 8 11] paired (mapv vector chord (rest (conj chord nil)))] (partition-by (fn [[a b]] (= (- b a) 1)) paired))
10:48clojurebot#<NullPointerException java.lang.NullPointerException>
10:48TEttingerhaha
10:49dnolenmmeix: I don't think so.
10:49mmeixthen I#ll keep my solution for now :-)
10:50mmeixwhat I find evrytime: it's not easy to find proper names for functions
10:55edannenbemmeix, there are only two hard things in computer science: cache invalidation and naming things :p
10:56mmeixobviously
10:56mmeix:-)
11:05mmeixanother ad hoc question: testing if a series of integers is monotonically growing ( [3 4 5 6] )
11:05mmeix(= c (range (apply min c) (inc (apply max c))))
11:05mmeixis there something more concise?
11:05mmeix(c being the series being tested)
11:07mmeix(growing by one, I forgot to mention)
11:11mmeixmy other idea was: (every? #(= 1 %) (map - (rest c) c))
11:12dnolenmmeix: that one is better since you don't have min max scans
11:12mmeixah, ok...!
11:12mmeixthanks
11:12dnolenit's lazier
11:12mmeixwhich is good, I understand
11:13dnolen(every? #{1} (map - (rest c) c))
11:13dnolenif you want to make it a bit shorter
11:13mmeixah, of course - thanks!
11:14TEttinger,(let [c [1]] (every? #{1} (map - (rest c) c)))
11:14mmeix(in my application, no vector is longer than around 15 elements though, so it's mostly a question of readability, I guess)
11:14clojurebottrue
11:14TEttingernice
11:14TEttingerI'm surprised that worked
11:14TEttinger,(rest [1])
11:14clojurebot()
11:14TEttingerah, because they're map args
11:14dnolen(every? true? '())
11:14dnolen,(every? true? '())
11:14clojurebottrue
11:15dnolenTEttinger: it's because map will work over the shortest seq, which is nil and every? return true
11:15dnolenfor empty seq
11:15justin_smith,(every #(= Double/NaN %) ())
11:15clojurebot#error {\n :cause "Unable to resolve symbol: every in this context"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Unable to resolve symbol: every in this context, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6543]}\n {:type java.lang.RuntimeException\n :message "Unable to resolve symbol: every in this...
11:15mmeixaha, and then I can do tests like (every? #{0 1} (map - (rest c) c))
11:15justin_smith,(every? #(= Double/NaN %) ())
11:15clojurebottrue
11:16justin_smith,(every? #(= Double/NaN %) '(Double/NaN))
11:16clojurebotfalse
11:17TEttinger,(let [nana Double/NaN] (every? #(= nana %) '(nana)))
11:17clojurebotfalse
11:17TEttinger,(let [nana (/ 0.0 0.0)] (every? #(= nana %) '(nana)))
11:17clojurebotfalse
11:17TEttingerhmmm
11:18mmeix,(let [c [1 1 2 3 3 4]] (every? #{0 1} (map - (rest c) c)))
11:18clojurebottrue
11:18mmeixgreat
11:19mmeixthanks everybody!
11:26kaiyin,(disj [1 2 3] 3)
11:26clojurebot#error {\n :cause "clojure.lang.PersistentVector cannot be cast to clojure.lang.IPersistentSet"\n :via\n [{:type java.lang.ClassCastException\n :message "clojure.lang.PersistentVector cannot be cast to clojure.lang.IPersistentSet"\n :at [clojure.core$disj invoke "core.clj" 1452]}]\n :trace\n [[clojure.core$disj invoke "core.clj" 1452]\n [sandbox$eval25 invoke "NO_SOURCE_FILE" 0]\n [clojure.l...
11:27kaiyinHow can i remove an element from a vector?
11:28ionthas_Noob question: I want to apply a pop 3 times into a vector to drop the last 3 values. I'm doing de following without success: (dotimes [n 3] (pop [1 2 3 4 5 6 7 8])).
11:28ionthas_kaiyin: You can remove the last element with (pop v)
11:29kaiyinionthas_: yeah, but that's a special case, i want to remove by value
11:30ionthas_kaiyin: I think there's no way to remove with the vector index. You should use a list instead. (Maybe I'm wrong)
11:32kaiyinok
11:37justin_smithkaiyin: you can use remove, but that returns a lazy-seq, even if the input was a vector
11:37justin_smith,(remove #{1 3} [0 1 2 3 4 5 6])
11:37clojurebot(0 2 4 5 6)
11:37kaiyincool.
11:38dnolenionthas_: you can't mutate vectors like that
11:39ionthas_dnolen: Ok. I supose I will use loop/recur :) thanks!
11:40dnolen,(reduce #(%2 %1) [1 2 3 4 5] (repeat 3 pop))
11:40clojurebot[1 2]
11:40dnolenionthas_: ^
11:41justin_smith,(nth (iterate pop [1 2 3 4 5]) 3)
11:41clojurebot[1 2]
11:41ionthas_that was exactly what I was looking for. Thanks
11:41dnolenone day will learn to use iterate :)
11:42justin_smithI'm always trying to make things recursive generative systems, so I don't pass up the chance when the problem actually maps to that
11:42justin_smithwell this is kind of the opposite of generative though
11:43ionthas_justin_smit: what do you mean with recursive generative?
11:43justin_smithionthas_: in general, iterate takes an input, and some operation, and gives you all the steps of repeated, recursive, applications of that operation
11:44justin_smith,(iterate inc 1)
11:44clojurebot(1 2 3 4 5 ...)
11:44ionthas_I see. Interesting. I will play with that function. It seems useful.
11:45justin_smithor (iterate markov \a) (where markov is a markov chain function that's been trained on some input)
12:03kaiyinhow do you update a vector at multiple indices?
12:04kaiyin,(update-in [1 2 3 4] [1] inc)
12:04clojurebot[1 3 3 4]
12:04kaiyinImperative code would use a for loop here.
12:07justin_smithkaiyin: what kind of updates are being done?
12:07kaiyinReplace with another value.
12:08kaiyinconditionally.
12:09justin_smith,(reduce #(if (even? (% %2)) (update % %2 inc) %) [1 2 3 4 5 6 7] [1 2])
12:09clojurebot[1 3 3 4 5 ...]
12:09justin_smiththe function does the conditional update, the last arg represents the indexes to check and maybe update
12:33kaiyinjustin_smith: this looks ineffecient.
12:33justin_smithwhy?
12:34clojurebotwhy is Why
12:34kaiyinyou have to traverse through all the elements.
12:34justin_smithno, you traverse the indexes to update
12:34justin_smithnot the elements
12:34kaiyinah, i see.
12:34kaiyincool.
12:38justin_smithit's a pattern I am fond of - finding a way of encoding each update as data, then walking a sequence representing all the updates
13:06kaiyinvery nice.
13:07borkdudeis there a way to check you're running in dev without environment variables or lein environ?
13:08borkdude{:profiles {:dev {:env {:dev true}}}} seems a bit too much
13:08justin_smithborkdude: off the top of my head, (.getCanonicalPath (java.io.File. ".")) or something that gets your hostname?
13:09borkdudejustin_smith possible
13:09borkdudeI wonder if they have solved that problem in boot
13:10justin_smithborkdude: another things to consider is that ideally on production lein should not be present
13:10borkdudejustin_smith true... it isn't in my case
13:11borkdudejustin_smith well, I cheated. I used lein to install immutant
13:11borkdudeI guess lein environ is the best option I've got then
13:11justin_smithin production, you end up needing to set a proper environment var
13:12justin_smithunless you are just checking for the absence of anything being set of course
13:13justin_smithborkdude: you could also set something your code can check at entry point, if immutant and lein repl or lein run have different entry points
13:14borkdudejustin_smith yeah. I've done that, also with environ. I discovered now that the settings from ~/.lein/profiles.clj, {:user :env {...}} and project.clj {:profiles {:dev {:env ...}}} get merged into .lein-env, which makes it better suited for the problem I had
13:15justin_smithahh
13:20justin_smith,(.getHostName (java.net.InetAddress/getLocalHost))
13:20clojurebot"localhost"
13:20justin_smithhaha
13:20justin_smithon my machine that shows my actual hostname
13:44kaiyincould anyone help me with this? http://stackoverflow.com/questions/30415771/strange-illegalargumentexception-in-clojure
13:48bensucan you tell me which line is 70?
13:49bensukaiyin, ^
13:49kaiyinbensu: (vec (repeat *world-size* c)))))
13:50kaiyinI think this error msg doesn't quite make sense.
13:50justin_smithkaiyin: ##([:a :b :c] :a)
13:50lazybotjava.lang.IllegalArgumentException: Key must be integer
13:50justin_smiththat's the error
13:51bensukaiyin, a vector needs a number as key
13:51Bronsakaiyin: you're invoking a vector with a non-key, in (min-by f-score openset)
13:51kaiyinah, i see.
13:51Bronsawith a non-integer*
13:52kaiyinwhy then does the compiler direct me to line 70?
14:05entityhow can I get w out of \w? str does not do what I want:
14:05entity,(str \w)
14:05clojurebot"w"
14:07entityI'm trying to write a vector of characters into a file
14:09justin_smithentity: wait, what?
14:10justin_smithdo you mean ##(apply str [\h \e \l \l \o])
14:10lazybot⇒ "hello"
14:10entityI have '[\a \b c\]' and I want to write '[a b c]' into a file
14:10justin_smith,(mapv (comp symbol str) [\a \b \c])
14:10clojurebot[a b c]
14:11entityawesome, thanks :)
14:29kaiyinanyone knows how to solve this? https://github.com/amalloy/ordered/issues/15
14:30justin_smithwhy wouldn't the regular conj work?
14:31kaiyinah, that's the regular conj on the github homepage... sorry.
14:32justin_smithyeah, conj is already polymorphic
14:32justin_smithso he wouldn't be likely to implement his own namespaced version of conj
15:29kaiyinfinally got this A* algorithm done: http://codereview.stackexchange.com/questions/91588/a-search-algorithm-in-clojure
15:50justin_smithis this related to the one talked about in joc?
15:53tsunnyHey room
16:03arohnerI'm calling Thread/setDefaultUncaughtExceptionHandler, but it doesn't appear to be working when I do (future (throw (Exception. "test"))). Any recommendations on where to look?
16:14arohnerah, the answer is that j.u.c.FutureTask.run catches the exception, so defaultuncaughtException is never called: http://stackoverflow.com/questions/23177331/concrete-example-of-a-defaultuncaughtexceptionhandler
16:18ConfusionI want to use 'and' as a value. I solve it by defining (defn- and-fn [& args] (every? identity args)). Is there a different way?
16:19TEttingerhm? 'and' is a macro?
16:19SeyleriusIf I need 9 9x9 grids of text boxes in seesaw, and need to get data out of them, and put data into them, would y'all recommend creating them all individually, or making a function that spits out the 9x9 grids with an appropriate title?
16:20TEttinger,(map and [true true false false] [false true false true])
16:20clojurebot#error {\n :cause "Can't take value of a macro: #'clojure.core/and"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.RuntimeException: Can't take value of a macro: #'clojure.core/and, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyze "Compiler.java" 6543]}\n {:type java.lang.RuntimeException\n :message "Can't take value of a macro: #'clojure....
16:20TEttinger,(map #(and %1 %2) [true true false false] [false true false true])
16:20clojurebot(false true false false)
16:21TEttingerSeylerius, I'd recommend making a function that spits them out
16:21TEttingerit shouldn't actually be that hard
16:22arohner,(:macro (meta #'and))
16:22clojurebottrue
16:22arohnerTEttinger: 'and guarantees it only evaluates arguments as necessary, so that necessarily makes it a macro or special form
16:23TEttingerah!
16:23amalloyConfusion: that is the way to do it
16:24TEttingerand-fn will still evaluate all args though, right?
16:25kaiyin,(let [x 9, y '(- x)] (println `y) (println ``y) (println ``~y) (println ``~~y))
16:25clojurebotsandbox/y\n(quote sandbox/y)\nsandbox/y\n(- x)\n
16:26amalloyTEttinger: yes, but it takes its args as a seq, so passing in a lazy seq would be fine
16:26TEttingerah!
16:26arohneramalloy: but chunking is an issue?
16:26mullrConfusion: do you just want to pass it to reduce? That's what I always want to do, and that's what 'every?' is for.
16:26mullr,(doc every?)
16:26clojurebot"([pred coll]); Returns true if (pred x) is logical true for every x in coll, else false."
16:27TEttingerok, this seems like a good place to ask about macro design.
16:28TEttingerI'm working on a programming language, it's pretty much a functional language but shares some similarities with stack languages. I'm trying to implement defmacro
16:29Confusionmullr, no, I'm parsing expressions from strings and some operator in the strings is equivalent to 'and'. Short circuiting would be nice, though not strictly necessary.
16:30TEttingerthe language compiles to Lua, with a Lua standard lib, and currently all the macros I have written have been in Lua, but they are pretty clunky
16:31mullrConfusion: ah, wrapping it in an fn is probably your best choice then.
16:32TEttingerlike I have the macro fn . it can be called like (fn [ a b ] (+ a b)) , equivalently (fn [ a b ] a + b)
16:32TEttingerthis is implemented in a really awful way though.
16:33kaiyincould anyone help me with this? http://stackoverflow.com/questions/30417291/illegalstateexception-in-nested-quote-and-unquote
16:34TEttingerwhen evaluation of a group (everything between parentheses) hits a macro, it puts the macro on top of the eval order, and until that macro has reached its target arity or the group ends, it adds things as arguments to that macro (all functions work like this). macros in my language treat values as values, and identifiers as the quoted names of those identifiers (which can be used to look them up)
16:37TEttingerthe problem is, in my implementation of fn, given the args: [ a b ] a + 9 , it gets '[ 'a 'b '] 'a '+ 9
16:38TEttingerand it only knows what are supposed to be names of arguments to fn by reading from the second arg (always skipping the first because it expects it will be '[ ) until it finds the symbol ']
16:38SeyleriusTEttinger: I've been thinking that would be the right idea, but wasn't sure how much of a pain referencing back into them would be.
16:40TEttingerwell the other thing it does is it specifically creates a table of names that can be used in the function when it's generated. when the generated function is called, it makes a new subscope, takes each argument it was given, and a name from the table, and assigns in the subscope the value to the name
16:41TEttingerthen it evaluates the body and deletes the subscope
16:42TEttingeror rather, in the fn implementation, it unquotes all the values in body before it evals them
16:43TEttingerso 'a becomes an identifier that will look up the value of a (finding whatever it has in the subscope)
16:43TEttingerI understand that macros don't evaluate their arguments
16:43TEttingerI'm not sure when defmacro should cause things to be evaluated
16:45mullrkaiyin: ~ is a reader macro which turns in to 'unquote', and ` is a reader macro which turns into 'syntax-quote'. I can tell you that it only makes sense to unquote inside syntax quote, but I can't for the life of me find the code that makes it work that way.
16:47mullrkaiyin: Ah, I think I see it. The reader is knows about syntax-quote, and interprets unquote as a special form in that context only. Outside of that, it looks just like any other function, which is not actually defined.
16:48kaiyinmullr: that makes sense.
16:50kaiyin,(println ''y)
16:50clojurebot(quote y)\n
16:50kaiyinso this means println explicitly unquote once?
16:50kaiyinimplicitly, sorry.
16:51TEttinger,(println 'y)
16:51clojureboty\n
16:51TEttinger,(class 'y)
16:51clojurebotclojure.lang.Symbol
16:51TEttinger,(class ''y)
16:51clojurebotclojure.lang.PersistentList
16:53kaiyinTEttinger: nice illustration, thanks.
16:53kaiyin(inc TEttinger )
16:53lazybot⇒ 5
16:53TEttingerah, thanks
16:53TEttingerme with space has more karma now!
16:54kaiyin(inc mullr)
16:54lazybot⇒ 1
16:54TEttingermultiple quotes are weird but can be handy
16:54TEttingernot often
16:54TEttingerin macros that generate macros, yes
17:03kaiyinTEttinger: could give an example of macro-generated macro?
17:03justin_smithTEttinger: now I want to implement def-def-def
17:03TEttingerhaha justin_smith
17:03TEttingerkaiyin, it's rare. I do have one
17:03justin_smithwhich is of course a macro that generates a macro that creates definitions
17:04TEttinger,(defmacro import-alias [new-name imported] `(defmacro ~new-name [f# & body#] `(. ~'~imported ~f# ~@body#)))
17:04clojurebot#'sandbox/import-alias
17:05TEttinger,(import-alias J Math)
17:05clojurebot#'sandbox/J
17:05TEttinger,(J PI)
17:05clojurebot3.141592653589793
17:05TEttingerin the body of the second macro is some really gnarly macro work
17:06TEttingerthat took a long time to get right, especially since I had never really written a complex macro before
17:07TEttingerhttp://amalloy.hubpages.com/hub/Clojure-macro-writing-macros was VERY helpful
17:09amalloybut also like...don't do it. you don't need a macro that produces maros in real life
17:10amalloyTEttinger: i still have trouble with the differene between ~'~ and ~~'
17:11TEttingerhehe amalloy. I'm crediting you (and justin_smith and gfredericks and #clojure in general) on the credits page for my programming language, since you fellas have been handy in my understanding of lots of tricky concepts
17:12kaiyinwhat is the differene between ~'~ and ~~'
17:12kaiyin?
17:13TEttingerwell they both make amalloy's head asplode, so avoid them :)
17:13Bronsadoes ~~' even make sense?
17:14Bronsaonly in the context of nexted syntax-quotes, right?
17:14amalloyBronsa: well that's true of ~'~ too
17:14amalloy,(let [sym 'x] ``[~'~sym ~~'sym]) ;; they both do something, of course
17:14Bronsano, I don't think so
17:14clojurebot(clojure.core/apply clojure.core/vector (clojure.core/seq (clojure.core/concat (clojure.core/list (quote x)) (clojure.core/list sym))))
17:14Bronsa`~'~a
17:14Bronsa,`~'~a
17:14clojurebot(clojure.core/unquote a)
17:14TEttinger,(defmacro [blah] `(inc ~~'blah))
17:14clojurebot#error {\n :cause "Don't know how to create ISeq from: clojure.lang.Symbol"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol, compiling:(NO_SOURCE_FILE:0:0)"\n :at [clojure.lang.Compiler macroexpand1 "Compiler.java" 6644]}\n {:type java.lang.IllegalArgumentException\n :message "Do...
17:14Bronsa,`~~'a
17:14clojurebot#error {\n :cause "Attempting to call unbound fn: #'clojure.core/unquote"\n :via\n [{:type java.lang.IllegalStateException\n :message "Attempting to call unbound fn: #'clojure.core/unquote"\n :at [clojure.lang.Var$Unbound throwArity "Var.java" 43]}]\n :trace\n [[clojure.lang.Var$Unbound throwArity "Var.java" 43]\n [clojure.lang.AFn invoke "AFn.java" 32]\n [sandbox$eval95 invoke "NO_SOURCE_FI...
17:14amalloyyes, if you want to emit an unquote or something, but that is just weird and you shouldn't
17:14TEttingerhaha
17:15Bronsatrue
17:15TEttingermore symbols than letters in these recent codes
17:15justin_smith"emit an unquote" is the weirdest euphamism ever
17:15Bronsaunless I'm dynamically generating macro bodies :)
17:15Bronsabut yeah, I wouldn't do that
17:17TEttingerhey baby I wanna emit an unquote all over your body and get your value
17:17Bronsaare nested syntax-quotes actually used in CL? I remember feeling like it was something that would come up often while reading PG's book but I don't think I've ever nested them in CLJ
17:18Bronsaor I might have used it once in neurotic, but anyway it's not something I see in code
17:29kaiyinTEttinger: you are probably the best person to answer this question: http://stackoverflow.com/questions/30417758/how-does-macro-generating-macro-work-in-clojure :-)
17:31TEttingeroh no
17:31TEttingerI am not the best person for any question!
17:33TEttingerI strongly suspect it has to do with it being a macro within another macro
17:33TEttingerthat was I think the second macro I ever wrote
17:33TEttingerso I can't say I understand it that well
17:34TEttingeralso, I have to say: I only wrote it because someone said it couldn't be done
17:34TEttingerit still can't alias classes that need to be instantiated
17:35kaiyinalright, let's just wait for some clojure gods to take care of it.
17:35TEttingerhaha
17:35TEttingeramalloy will scold me :)
17:36amalloykaiyin: (concat (list x) (list y) (list z)) is of course equivalent to (list x y z), but it's just simpler for the compiler to generate stuff if it makes everything a list and then calls concat as necessary
17:37amalloyand since it's all happening at compile time instead of runtime, the performance issues of doing stuff in a simple but silly way don't really matter
17:46kaiyinok.
18:08entityif I def something in a namespace, I can later re-def it only from the same namespace?
18:08entityI'm getting "java.lang.IllegalStateException: gold-prob already refers to: #'clojure-robby.genetic/gold-prob in namespace: clojure.core"
18:09justin_smithwhy are you adding defs to clojure.core?
18:09entityhm, good question
18:10entityI def it in clojure-robby.genetic
18:11entityalthough, I then "(eval (use 'clojure-robby.genetic))" and launch a repl
18:11entityI want to bundle a REPL in my app, so I wrote a one-line that does that
18:12entityit's probably messing up the namespaces
18:15entityI'm open to suggestions as to how to properly implement a REPL in my app
18:16justin_smithclojure.tools.nrepl.server lets you launch your own nrepl network server
18:16entitybut I'd need both the server and the client
18:16entityit seem excessive
18:17justin_smith"lein repl :connect" can connect to a running nrepl
18:17entitybut requires a dependency - leiningen
18:17justin_smiththat's true
18:17entityI'd like to get a single portable .jar file
18:17justin_smithentity: for a regular repl, you can just invoke clojure.main
18:20entityokay, that's cool
18:20entityis there any way to have it use a couple namespaces at startup?
18:21justin_smithentity: the default namespace at startup is user, so you could switch into namespace user, then use whatever namespaces you like from user
18:21justin_smiththe repl is not a sandbox
18:21justin_smithit's the same namespaces and bindings as the rest of clojure
18:21justin_smithif you do want a sandbox, you could check out eg. clojail
18:21ionthas_Anyone can explain me why this code is only dropping one of the values of the vector? (loop [n 0 lol v1] (if (< n 10) (recur (inc n) (pop v1)) lol)) with (def v1 [[0 [1 0 4 3]] [6 [3 2 1 1]] [3 [3 1 1 1]]]). It only drops the last element of the vector. It doesn't depend of the number in the condition. Anyone has some idea what's going on? Thanks!
18:22justin_smithionthas_: you want (pop lol) not (pop v1)
18:22justin_smithbecause of course v1 never changes
18:23justin_smithso you end up with the result of popping it once
18:23ionthas_shit XD
18:23ionthas_you're right. That's the sign. Not more programming for today.
18:24entityjustin_smith: thanks, this was very helpful :) I think I'll figure it out now
18:50entityjustin_smith: I am now in a user namespace by binding *ns* to a newly create namespace
18:51entitybut I still get shuted at for trying to redefine a var: "java.lang.IllegalStateException: gold-prob already refers to: #'clojure-robby.genetic/gold-prob in namespace: user-ns"
19:02entityI do not understand why I'm suddenly not allowed to re-def a var in my namespace
19:03entityI can create new bindings and re-def those
19:03entitybut I can't re-def what I've imported from other namespaces
19:16sandbagsI've written a small API server using Liberator which has been great. I'm deploying it using Jetty but something that has me stumped is how I can pass configuration data to the app... i guess this may be more of a Java/Jetty question but I'm not turning up anything via Google
19:16sandbagshoping someone can point me in the right direction
19:27fourqHey all, Clojure/Clojurescript book ideas for a noob? (I have 18+ years, background: vb6, c#, js, node, fullstack) I'll be mainly working on web apps for enterprise.
19:28sandbagsfourq: one of either "Clojure Programming" or "Programming Clojure" as a jumping off point
19:28sandbagsPragProg vs O'Reilly
19:30sandbagsas to web app stuff there is "Web Development with Clojure" which covers 'classic' server side app development
19:30sandbagsthe client side stuff in CLJS is probably moving too fast
19:35fourqsandbags ty very much
19:37fourqIs Chas Emerick in here ever? I listened to a podcast a few days ago and he had 2 book suggestions. (I just forget what they are)
19:38sandbagsWell I found Clojure in Action a good jumping off point
19:39amalloy$seen cemerick
19:39lazybotcemerick was last seen quittingPing timeout: 264 seconds 4 hours and 24 minutes ago.
19:39amalloyso he was here 4 hours ago
19:39sandbagsit's a bit less heavy than the other two, Joy of Clojure is often cited also
19:39fourqamalloy ty
19:40epicheroOm and dev tools like figwheel are good clientside. (it is moving really fast though that's true)
19:41fourqI've been playing with om, and fig along with the unreleased book Clojure for the Brave and True
19:41fourqgreat read btw
19:42fourqOm would be a hell of a learning curve if I didn't have prior React exp
19:44sandbagsI quite enjoyed Functional Programming for the OO programmer by Brian Marick
19:44sandbagsi came to CLJ from Ruby so it was pretty on-point
19:44fourqI'll add that to my list. I have a weekend without the kids. Should be good for a few books
19:45sandbagsif you're writing services rather than apps i can definitely recommend looking at Liberator
19:45sandbagsi've found it a breath of fresh air
19:45fourqboth eventually
19:51epicheroi haven't tried liberator, i'm wanting to do some websocket stuff myself
19:52epicheroany suggestions on that front?
19:59edannenbefourq, can recommend http://www.braveclojure.com/
20:03fourqedannenbe I've read it! ty. I loved it
20:03edannenbeyea very entertaining read
20:04fourqIt really was
20:04fourqSomething pretty rare in the tech book world. Well it's not that rare, but it's rare that it worked out, and wasn't horribly overdone.
20:14postpunkjustinDoes anyone know a good way to redirect to a URL in ClojureScript?
20:27justin_smithpostpunkjustin: use js interop to make the browser load the other page?
20:27postpunkjustinyeah, I'm having a lot of trouble getting that to work
20:28justin_smith(set! (.href (.location js/window)) "http://www.google.com&quot;))
20:28justin_smithsomething like that
20:28justin_smithmaybe it's set and not set!
20:29justin_smithoh, and you likely need (.-href (.-location js/window))
20:30justin_smithone minute, I'll load up my app and actually see what works
20:31postpunkjustinawesome, thanks
20:31justin_smithI've been learning cljs myself the last month or so
20:32justin_smithusing figwheel, sente, reagent
20:32justin_smithported stuartsierra/component to cljc (once I make all the frontend and backend tests pass I'll make a pr / announcement)
20:33postpunkjustinoh sweet, that's really cool
20:33postpunkjustinI'm using a similar stack
20:33justin_smithit's been a cool experience so far
20:33justin_smithalso, I set up a /test route that runs frontend tests in the console, and backend tests show in the browser page
20:33justin_smithI might try to make that a plugin
20:34justin_smithlein plugin, that is
20:35epicherowhat do you think of sente?
20:36justin_smithepichero: so far it is awesome
20:36justin_smithpostpunkjustin: (set! (.-href (.-location js/window)) "http://www.google.com&quot;) verified to work in the figwheel repl
20:37justin_smithepichero: I ended up making some wrappers so the api for accessing and sending messages was more uniform on each side
20:37justin_smithbut overall I like
20:38justin_smithepichero: a great addition was using json-web-tokens for session storage. Just make sure that you explicitly state which storage algo you are checking for when unencrypting
20:38justin_smithby default there is a "none" encryption method, and the client by default sets the encryption method when sending the data
20:39justin_smithso there is a stupid thing where they can forge any data they like, and the server's like "lol, encryption method is none so obviously the data is valid, I'll go ahead and use it now"
20:39justin_smiththere's an extra arg to declare exactly which encryption method you will allow
20:41epicherojustin_smith: thats standard fare, sometimes people just get used to things be built-in
20:41postpunkjustinjustin_smith: ok, cool, that definitely works if I put it at the top level, but now I'm trying to call it from a button :on-click handler and it doesn't work there for some reason
20:41postpunkjustinany ideas why that might be?
20:41justin_smithpostpunkjustin: weird...
20:42justin_smithso to make it an on-click you wrap it in an anonymous function, right?
20:42postpunkjustinyeah, the :on-click val is an anonymous function
20:42justin_smithoh, is this reagent?
20:42postpunkjustinyeah
20:44justin_smithpostpunkjustin: do you have to override the default button click handler? there's a css trick for that and it's slightly different for different browsers
20:44postpunkjustinoh, interesting idea
20:44postpunkjustinI didn't realize that would be necessary
20:44justin_smiththat's a frequent problem I've seen with button actions
20:46justin_smithbut I am far from being a frontend expert
20:46postpunkjustinyes, I think you're totally right
20:47postpunkjustinit was a form submit button. changing it to a regular button fixed it. thanks!
20:47justin_smithahh!
20:47justin_smithyeah, that would do it
20:52justin_smithso this is the nifty testing setup I have right now... maybe I'll make it a plugin this weekend http://i.imgur.com/GbPXAJb.png
22:34Shiro-IchidaYes! I got a clojurescript repl running! Probably no big deal for most people here but it's exciting to me and none of my friends use Clojure, so...uh. Yeah, that's it.
22:34justin_smithShiro-Ichida: it's a cool thing!
22:34Shiro-IchidaIt's very cool.
22:35blkcatShiro-Ichida: congrats :)
22:35blkcatclojurescript looks very very interesting. i need to give it a shot.
22:36dnolenShiro-Ichida: nice!
22:36justin_smithit's nice to do a webapp end to end all clojure
23:40crocketDoes clojure beat C++ when you need to hit GPU?
23:40justin_smithbeat by what criteria? for performance I'd be surprised if clojure was ever as fast as c++
23:41crocketGPU performance would be more important than performance differences among languages.
23:42crocketIs clojure fast enough for GPU operations? Does clojure make it easy to hit GPUs?
23:44justin_smith"fast enough for GPU operations" is a weird quesiton, to use the GPU at all from clojure you'll need a lib like jcuda, and there's some stuff out there, but not very much, and not very mature that I know of
23:44crocketIf your operations stay on GPUs most of the time, clojure could be good enough.
23:45crocketThen, it should be simple to hit GPUs on clojure.
23:45justin_smithOK, but the tooling really isn't there at the moment
23:45justin_smithand making your code run on the GPU isn't a simple thing in most cases
23:45justin_smithit requires a different programming style
23:46crocketSo, does GPU programming suit C++ better?
23:48epicheroyou can do it, but you are misunderstanding how all of this works
23:48crocketepichero, I don't understand it at all.
23:49justin_smithcrocket: gpu programming is easiest from c++, because it is targetted to the types of applications where you would be using c++ for speed reasons already
23:50crocketjustin_smith, Why not C?
23:50justin_smithcrocket: clojure is better suited to situations where you want to have less code, and less time developing code, in particular when it comes to doing concurrency correctly.
23:51justin_smithcrocket: because outside of things like the Linux kernel, c++ has much more mainstream adoption right now
23:51crocketConcurrency can be achieved by GPUs.
23:51justin_smithif you program in a very specific way, yes
23:52justin_smithbut not every situation in a typical program can simply be thrown at a GPU to make it concurrent
23:52crocketI think haskell and clojure will take over C++ on GPU programming.
23:52justin_smithany more than every situation in a typical program can be thrown at threads to make it concurrent
23:52justin_smithcrocket: first someone needs to build the tooling, it's really not there right now.
23:52justin_smithor there, but very immature
23:52crockethaskell has accelerate
23:52justin_smithOK
23:53epicherohaskell is pure so there are no conflicts
23:53crocketGiven the momentum given to haskell and clojure, they'll get tooling supports soon.
23:53crocketIn the next 10 years.
23:53epicherotheres already proof of concept stuff around, you can do it now if you want to
23:53epicherofinding a niche where it makes sense is a bit more difficult
23:54justin_smithcrocket: idiomatic clojure (or even full idiomatic haskell) is a bad fit for the GPU because we rely heavily on GC, and use a lot of RAM
23:54justin_smithcrocket: even with accellerate, it only works if you translate all your data into arrays of numerics
23:55justin_smithso at best you get a sub-language where most of the host language is unavailable, but it performs well
23:55justin_smithjust see how many lines of clojure code you can write that don't allocate or leak heap space
23:56crocketjustin_smith, Does haskell have chance, then?
23:56justin_smithIt can use that stuff, but in a limited sublanguage. A chance to what?
23:57crocketbeat C++
23:57crocketin GPU programming
23:58crocketHaskell is getting a lot of momentum.