2015-12-13
| 00:44 | domokato | if i have one macro that needs to generate a new symbol based on a passed-in symbol (gensym passed-in-sym), and i have a separate macro that needs to refer to this generated symbol, what's the best way to do that? |
| 00:44 | domokato | the same symbol will be passed in to the second macro |
| 00:45 | domokato | so i basically need a mapping of symbols to their generated symbols |
| 00:46 | domokato | but only during compile time. is there a way to do that? |
| 01:05 | jeaye | How would I parse 20151212T134758Z into a simpler format? |
| 01:18 | domokato | jeaye: probably with regexes |
| 01:18 | jeaye | Trying to use clj-time, currently. |
| 01:19 | jeaye | Ah, got it. |
| 01:20 | jeaye | (parse (formatters :basic-date-time-no-ms) "20151212T134758Z") ; works |
| 01:21 | domokato | jeaye: nice |
| 01:30 | jeaye | Any idea why clojure.java.shell/sh would return quickly but make the program take a very long time to exit? |
| 01:30 | jeaye | It quickly returns, runs my main, and then takes ~1m before it fully quits. |
| 01:30 | jeaye | (no errors) |
| 01:56 | lambda-11235 | Is it bad practice to attach :forms metadata to your own macros? |
| 01:58 | lambda-11235 | or :arglists? |
| 03:16 | BRODUS | can anyone recommend any good exercises to get familiar with the metaprogramming aspects of clojure? |
| 03:18 | amalloy | BRODUS: try implementing let (without destructuring) yourself |
| 03:18 | amalloy | (as a macro over fn) |
| 03:19 | BRODUS | cool, i'll try that. |
| 03:23 | opqdonut | I think something like locking or with-open might be a good exercise too |
| 03:24 | opqdonut | amalloy: what would you implement let with? let?-) |
| 03:24 | amalloy | opqdonut: like i said, a macro over fn |
| 03:24 | opqdonut | oh |
| 03:24 | opqdonut | reading comprehension 0/5 |
| 04:39 | wickedshell | I was reading the docs on last, and it promises linear time, is there a variant or a function that can find the last element in constant time on a vector? |
| 04:41 | MJB47_ | wickedshell: peek? |
| 04:42 | MJB47_ | http://clojuredocs.org/clojure.core/peek |
| 04:42 | wickedshell | MJB47_, hey that will do quite nicely, thanks :) |
| 05:11 | kungi | Is there a way to debug ring middlewares with cider? I really would like to be dropped into the debugger on loading a page. |
| 05:19 | shiranaihito | pffft.. i wish i could only write Clojure and wouldn't have to deal with the mad proliferation of front-end tools that plagues the world today |
| 05:21 | kungi | shiranaihito: such as? |
| 05:22 | shiranaihito | kungi .. everything, pretty much.. i want to use redux.. then there's react-redux, react-router, redux-router or whatever.. |
| 05:23 | kungi | shiranaihito: yes the javascript world churns libraries pretty fast |
| 05:23 | shiranaihito | and they tell me to use npm and webpack and whatever the hell.. and each of those projects lies in a heap of Node-centric config files etc, aaand no one seems to care because obviously everyone in the world is a Node-developer and doesn't mind doing everything based on Node |
| 05:24 | shiranaihito | it's insane |
| 05:24 | kungi | shiranaihito: this is madness??? NO THIS IS JAVASCRIPT:-) |
| 05:24 | shiranaihito | and all the sources for JS libs are wrapped in some strange "module" incantations that i don't know if i'm supposed to get rid of somehow (like by running them through webpack or something) .. or if they'll just magically work by including them with script tags etc |
| 05:24 | shiranaihito | yeah.. :p |
| 05:25 | shiranaihito | aaand these days they're writing example code in the ES6(or 7?) module style that browsers don't support yet .. even though everything still depends on all that other crazy module shit |
| 05:25 | shiranaihito | oh and i'm using Babel too, because React.. |
| 05:26 | shiranaihito | .. and because ES6 ofc |
| 05:26 | shiranaihito | but all in all it's just deranged |
| 05:27 | kungi | I work in a clojure only place. We use python for sysadmin stuff and clojure / clojurescript for the rest. |
| 05:27 | shiranaihito | oh? well, i tried to use CLJS but figured it was still a bit too scary after all |
| 05:28 | kungi | shiranaihito: when did you try it the last time? It got much better since I started two years ago |
| 05:28 | shiranaihito | there's another proliferation of silly little libs in the CLJ/CLJS ecosystem of course.. all hanging off of Leiningen and ancient Apache Commons libs from 1998 or whatever the hell.. |
| 05:28 | shiranaihito | kungi: i was faffing about with CLJS earlier this year |
| 05:29 | shiranaihito | actually i guess my main problem was that debugging the resultant JS code felt impossible |
| 05:29 | kungi | shiranaihito: it probably is ... I don't "debug" CLJS |
| 05:29 | shiranaihito | .. no clue what was happening basically anywhere, because everything is done through the CLJS implementation code etc |
| 05:30 | MJB47_ | there is proper sourmapping support now |
| 05:30 | MJB47_ | but personally i find the compiled js to be relatively easy to read |
| 05:30 | MJB47_ | i use node at work though :( |
| 05:30 | shiranaihito | MJB47_ oh :p well, you must be made of sterner stuff then :p |
| 05:31 | MJB47_ | compared to coffeescript or something |
| 05:31 | shiranaihito | so with a source map i could theoretically see exactly where there's a problem in my own CLJS sources? |
| 05:31 | MJB47_ | the compiled js code is waaaaaaay better |
| 05:31 | MJB47_ | but yer exactly |
| 05:31 | shiranaihito | oh, weird |
| 05:31 | MJB47_ | you debug clojurescript, never nee dot look at the js |
| 05:31 | MJB47_ | need to* |
| 05:32 | shiranaihito | well, i seem to recall encountering plenty of cryptic error messages that happened somewhere in JS |
| 05:32 | shiranaihito | not sure if they'd even map to my CLJS sources |
| 05:32 | MJB47_ | error messages have always been lackluster in cljs :( |
| 05:32 | MJB47_ | i believe they are getting better though |
| 05:33 | shiranaihito | i spent too much time scraping together something like my own version of Reagent.. but eventually gave up on it because i had no idea what the hell was wrong with the way i was calling React from it |
| 05:34 | shiranaihito | i found the compiled CLJS code too hefty too.. yeah sure, that could be mitigated (to an extent) through google-clojure-minimizing the shit out of it, but still.. it felt problematic |
| 05:35 | shiranaihito | MJB47_ yeah i guess i encountered some of those |
| 05:36 | kungi | Hmm cider inspect does not seem to work in the debugger :-( |
| 05:36 | shiranaihito | maybe i'll end up using CLJS someday.. i liked the idea of writing all my front-end stuff with it |
| 05:52 | BRODUS | say you have function with an inner recursive that does all the work, whats a good convention for naming that inner function? |
| 05:54 | MJB47_ | i typically do -outer-function |
| 05:54 | MJB47_ | but i doubt thats a standard practise |
| 05:55 | BRODUS | would 'f' be frowned upon? |
| 05:55 | MJB47_ | no |
| 05:56 | schaueho | I usually use <outer>-helper |
| 05:56 | schaueho | matter of personal preference or company-wide coding conventions |
| 08:06 | lxsameer | what's so special about datomic ? |
| 08:09 | ridcully | what do you mean? |
| 08:10 | ridcully | special compared to other dbs? |
| 08:15 | BRODUS | is there any difference between returning (cons x (lazy-seq ....)) and (lazy-seq (cons x ...)) |
| 08:16 | BRODUS | I see them equally as much so I'm wondering if its for a reason or just preference. |
| 08:18 | lxsameer | ridcully, I can't understand the noble thing behind it |
| 08:34 | Bronsa | ,(def a (lazy-seq (cons (println "foo") ()))) |
| 08:35 | clojurebot | #'sandbox/a |
| 08:35 | Bronsa | ,(def a (cons (println "foo") (lazy-seq ())))) |
| 08:35 | clojurebot | foo\n#'sandbox/a |
| 08:35 | Bronsa | BRODUS: ^ |
| 08:36 | BRODUS | so the second version the head is already 'realized' |
| 08:37 | Bronsa | yes |
| 08:38 | BRODUS | but when would you want that? seems like the first is better generally speaking since an element should only be realized unless its needed |
| 08:45 | oracle | how to convert [1 2 [3 4] 5] to [1 2 3 4 5]? just want to have something like mapcat. |
| 08:45 | MJB47_ | ,(vec (flatten [1 2 [3 4] 5])) |
| 08:45 | clojurebot | [1 2 3 4 5] |
| 08:47 | hyPiRion | Well, you have mapcat |
| 08:47 | hyPiRion | ,flatten |
| 08:47 | clojurebot | #object[clojure.core$flatten 0x26a4e79a "clojure.core$flatten@26a4e79a"] |
| 08:47 | hyPiRion | ~flatten |
| 08:47 | clojurebot | flatten is rarely the right answer. Suppose you need to use a list as your "base type", for example. Usually you only want to flatten a single level, and in that case you're better off with concat. Or, better still, use mapcat to produce a sequence that's shaped right to begin with. |
| 08:49 | oracle | great. I have thought only scala has flatten, just found clojure also have it. |
| 09:40 | Morgawr | Hello, I am using prismatic schema in clojurescript and I want to validate atoms. I've seen in their changelog that they added an s/atom validator but when I try to use s/atom in my code it says it's an undefined var. Does anybody know anything about it? Is this the right place or is there a better place to ask? |
| 11:20 | RedNfire | heya. what's the situation on android these days? |
| 11:23 | RedNfire | For Android, I just swiched from Java to Kotlin (less verbose Java with some neat extras), but I had great fun on nodejs with CoffeeScript (less verbose JavaScript with some neat extras) and an FP library so I now wonder if a dynamic FP language like Clojure would work well for Android. My understanding is that it basically works but the interop with the Android API is awkward because that API is very java-centric. Is that correct? |
| 11:45 | Morgawr | Why is it that I am getting different regex matches/results when using (.match text my-regex) and text.match(my-regex) between clojurescript and javascript? It's the same text and it's the same regex (created with js/RegExp.) |
| 11:51 | harja | Hi all, any core.logic people awake? I'm having problems with https://gist.github.com/mharju/9b21e68969994bb151ec |
| 11:51 | harja | The one in line 33 stops as expected, but the larger version just keeps on going without ever stopping |
| 11:51 | harja | What are the best practises in debugging these kinds of programs? |
| 11:54 | harja | This is literally my first stab at core.logic, so bear with me :) |
| 12:03 | xyh | how can I use mutable vector in clojure ? |
| 12:04 | justin_smith | xyh: first you find a mutable vector - what lib provides one? |
| 12:04 | justin_smith | after that, you use it |
| 12:05 | xyh | I come from scheme. so no built-in mutable vector ? I have to import mutable vector from java lib ? |
| 12:05 | MJB47_ | you can use java arrays |
| 12:05 | justin_smith | xyh: clojure doesn't define a mutable vector |
| 12:06 | justin_smith | there are arrays, but unlike vectors, arrays do not resize |
| 12:06 | justin_smith | there is also java.util.ArrayList - that's probably closest |
| 12:07 | justin_smith | ,(let [al (java.util.ArrayList.)] (.add al :a) (.add al :b) (into [] al)) |
| 12:07 | clojurebot | [:a :b] |
| 12:08 | kungi | Thanks everyone for the cider debugger \o/ |
| 12:08 | justin_smith | ,(let [al (java.util.ArrayList.)] (.add al :a) (.add al :b) al) |
| 12:08 | clojurebot | [:a :b] |
| 12:08 | justin_smith | cool - it prints nicely even without putting it in a vector at the end |
| 12:08 | MJB47_ | you can also (vec al) |
| 12:09 | MJB47_ | though idk which is more efficient |
| 12:09 | justin_smith | you don't really need to do either though |
| 12:09 | MJB47_ | indeed |
| 12:09 | justin_smith | xyh: arraylists are 100% non-thread-safe |
| 12:09 | justin_smith | xyh: if used with multiple threads, you need locks etc. or your data will be garbage |
| 12:12 | xyh | I am writing a vm [an interpreter] of another language, the image of the vm is a byte-array, and the vm load the image and interpret it. |
| 12:13 | justin_smith | then why not use a byte array? |
| 12:13 | justin_smith | ,(java.util.ByteArray. 1024) |
| 12:13 | clojurebot | #error {\n :cause "java.util.ByteArray"\n :via\n [{:type clojure.lang.Compiler$CompilerException\n :message "java.lang.ClassNotFoundException: java.util.ByteArray, compiling:(NO_SOURCE_PATH:0:0)"\n :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 6891]}\n {:type java.lang.ClassNotFoundException\n :message "java.util.ByteArray"\n :at [java.net.URLClassLoader$1 run "URLClassLoader.java... |
| 12:14 | justin_smith | err... |
| 12:14 | irctc | Hi everyone. :) |
| 12:14 | justin_smith | ,(byte-array 1024) ; that's the one |
| 12:14 | clojurebot | #object["[B" 0x5d794897 "[B@5d794897"] |
| 12:14 | xyh | cool |
| 12:14 | justin_smith | that's a non-resizable actual contiguous array of primitive bytes |
| 12:14 | xyh | thx |
| 12:15 | justin_smith | xyh: you can use aget and aset to manipulates the elements of a byte array |
| 12:15 | xyh | when I know the word 'byte-array', where can I find the docs about it ? |
| 12:16 | justin_smith | xyh: a byte-array is one of the primitive array types |
| 12:16 | MJB47_ | http://clojuredocs.org/clojure.core/byte-array |
| 12:16 | irctc | I am trying to save in a local variable a list of two functions to be executed if a condition is not met and if it is then it will execute some other function. Now when the condition is true the right function executes but when the condition is false I don't know how to pass more than one function to the variable wich will then be inserted into a threaded list of functions for execution. Does anyone know how this can be done? |
| 12:17 | xyh | thanks MJB47_ |
| 12:17 | justin_smith | MJB47_: that's a doc for the constructor, but not the type created |
| 12:17 | MJB47_ | http://clojure.org/cheatsheet <- always useful |
| 12:17 | MJB47_ | oh |
| 12:17 | MJB47_ | that is true |
| 12:20 | irctc | For example I have (-> function1 function2 variable-that-holds-a-function-based-on-met-condition function4) Now how do I pass more than one function to variable-that-holds-a-function-based-on-met-condition that will then execute those functions in sequence? |
| 12:21 | justin_smith | xyh: I'm not finding any really good intro for java arrays right now. The important things are that the size cannot change, they hold only one type (either some class or one of the primitive types, in your case byte), and they don't really have methods - you use static methods on other classes to work with them. |
| 12:22 | justin_smith | xyh: in particular the java.util.Arrays class has a bunch of useful methods for doing things with an array |
| 12:24 | harja | Sorry for repeating my question but I'd need pointers on how to debug core.logic-based code. https://gist.github.com/mharju/9b21e68969994bb151ec The "smaller" version of the problem starting on line 32 halts with a correct solution but the bigger one just keeps on grinding when I start it. |
| 12:24 | xyh | thanks justin_smith, I only need basic primitive functions about byte-array, I can implement the functions I need on the way to my vm :) |
| 12:25 | justin_smith | xyh: then aget and aset should suffice |
| 12:25 | xyh | justin_smith: indeed |
| 12:25 | justin_smith | xyh: the other gotcha! bytes in the jvm are all signed |
| 12:25 | justin_smith | but there's some simple math to work with signed bytes as if unsigned (inconvenient though it is) |
| 12:25 | xyh | oh! that is not cool |
| 12:26 | justin_smith | xyh: it's the same bits, so all you need is to make sure the right bits are in there before your other program sees the data |
| 12:26 | justin_smith | but yes, inconvenient |
| 12:27 | xyh | the idea of the macro '->' is learned from forth the language right ? |
| 12:29 | justin_smith | xyh: umm... I would doubt it -> is a syntax transform and forth doesn't have syntax per se |
| 12:32 | lambda-11235 | Is it bad practice to attach :arglists metadata to your own macros after definition? |
| 12:33 | justin_smith | lambda-11235: it will annoy the folks who make code analyzing tools |
| 12:35 | irctc | Doesanyone know how I can put several functions into one variable and then insert that variable in -> macro to have those functions executed? |
| 12:37 | justin_smith | the easy way is with comp |
| 12:37 | justin_smith | ,(-> 1 ((apply comp [inc inc inc])) vec) |
| 12:37 | clojurebot | #error {\n :cause "Unable to convert: class java.lang.Long to Object[]"\n :via\n [{:type java.lang.RuntimeException\n :message "Unable to convert: class java.lang.Long to Object[]"\n :at [clojure.lang.Util runtimeException "Util.java" 221]}]\n :trace\n [[clojure.lang.Util runtimeException "Util.java" 221]\n [clojure.lang.RT toArray "RT.java" 1671]\n [clojure.lang.LazilyPersistentVector creat... |
| 12:37 | justin_smith | ergh |
| 12:38 | justin_smith | ,(-> 1 ((apply comp [inc inc inc])) vector) |
| 12:38 | clojurebot | [4] |
| 12:39 | lambda-11235 | justin_smith: My reasoning is for cases when macros have a complicated syntax, and their arg lists is [& form]. |
| 12:39 | irctc | Thanks justin_smith. |
| 12:40 | lambda-11235 | In which case the argument lists provide very little information about the macro. |
| 12:41 | justin_smith | lambda-11235: I wish I could describe the issue in more detail, maybe Bronsa is around to explain why this is a problem for his work |
| 12:45 | Bronsa | justin_smith: lambda-11235 the issue is more with changing arglists on functions than on macros |
| 12:46 | justin_smith | what exactly is the issue anyway? I remembered it being a problem but not why. |
| 12:46 | Bronsa | :arglists is used both for documentation purposes and to guide the compiler on some optimizations + it's the only way tools have to get the arities of a function |
| 12:46 | lambda-11235 | Bronsa: I can get how that would effect arity checking. |
| 12:47 | Bronsa | there were a bunch of proposals for having both a :arglists and a :doc-arglists but never went anywhere |
| 12:48 | pvinis | you know `take-while`? i want to make a `take-while-coll`, which works as `take-while`, but instead it would return a collection of the subcollections passing the test. for example |
| 12:48 | Bronsa | justin_smith: Compiler.java uses :arglists to figure out whether it can compile calls using primInvoke for example |
| 12:48 | pvinis | (take-while pos? '(1 2 3 -5)) would return '(1 2 3) |
| 12:48 | Bronsa | eastwood uses it to warn on mismatching arities |
| 12:49 | pvinis | (take-while-coll pos? '(1 2 3 -5)) would return '((1) (1 2) (1 2 3)) |
| 12:49 | pvinis | how would i do that? |
| 12:50 | alive876 | hi, whats the best way to load a clojar file into a repl? |
| 12:50 | Bronsa | pvinis: look at reductions |
| 12:56 | pvinis | Bronsa: hmm.. interesting |
| 12:56 | pvinis | now to find how to combine it.. |
| 12:57 | justin_smith | I did a lame version - reductions would be better: |
| 12:57 | justin_smith | ,(defn take-while-coll ([pred coll] (take-while-coll pred coll [])) ([pred coll so-far] (let [e (first coll) with (conj so-far e)] (when (seq coll) (if (pred e) (lazy-seq (cons with (take-while-coll pred (rest coll) with))) (take-while-coll pred (rest coll) [])))))) |
| 12:57 | clojurebot | #'sandbox/take-while-coll |
| 12:57 | justin_smith | ,(take-while-coll even? [2 2 4 1]) |
| 12:57 | clojurebot | ([2] [2 2] [2 2 4]) |
| 12:57 | justin_smith | ,(take-while-coll even? [2 2 4 1 42 44 100]) |
| 12:57 | clojurebot | ([2] [2 2] [2 2 4] [42] [42 44] ...) |
| 12:58 | Bronsa | ,(rest (reductions (fn [acc x] (if (pos? x) (conj acc x) (reduced acc))) [] '(1 2 3 -4))) |
| 12:58 | clojurebot | ([1] [1 2] [1 2 3] [1 2 3]) |
| 12:58 | pvinis | aha.. |
| 12:59 | Bronsa | justin_smith: I think you reimplemented reductions :) |
| 12:59 | justin_smith | almost - mine doesn't stop |
| 12:59 | Bronsa | ah, right |
| 12:59 | justin_smith | it does another take-while after the first non-matching item |
| 13:00 | pvinis | right |
| 13:01 | pvinis | hm, ok give my brain a minute to process :) |
| 13:01 | pvinis | thank you both |
| 13:01 | pvinis | ,(defn keep-taking-while |
| 13:01 | pvinis | ([pred coll] (keep-taking-while pred [] coll)) |
| 13:01 | pvinis | ([pred old coll] |
| 13:01 | clojurebot | #<RuntimeException java.lang.RuntimeException: EOF while reading> |
| 13:01 | pvinis | (if (not (empty? coll)) |
| 13:01 | pvinis | (let [new (first coll) |
| 13:01 | pvinis | rest-of-new (rest coll) |
| 13:01 | pvinis | old-and-new (conj old new) |
| 13:01 | pvinis | result (pred old-and-new)] |
| 13:01 | pvinis | (if result |
| 13:01 | pvinis | (recur pred old-and-new rest-of-new) |
| 13:01 | pvinis | old)) |
| 13:01 | pvinis | []))) |
| 13:01 | justin_smith | pvinis: don't do that |
| 13:02 | pvinis | this is what i had so far.. i think an accumulator was missing somewhere.. |
| 13:02 | pvinis | sorry |
| 13:02 | justin_smith | the bot doesn't accept multi line input, and multi line pastes are rude |
| 13:02 | pvinis | i didnt know it will go multiline |
| 13:02 | pvinis | let me try again |
| 13:03 | pvinis | ,(defn keep-taking-while ([pred coll] (keep-taking-while pred [] coll)) ([pred old coll] (if (not (empty? coll)) (let [new (first coll) rest-of-new (rest coll) old-and-new (conj old new) result (pred old-and-new)] (if result (recur pred old-and-new rest-of-new) old)) []))) |
| 13:03 | clojurebot | #'sandbox/keep-taking-while |
| 13:04 | pvinis | ,(keep-taking-while even? [2 4 24 5 25]) |
| 13:04 | clojurebot | #error {\n :cause "Argument must be an integer: [2]"\n :via\n [{:type java.lang.IllegalArgumentException\n :message "Argument must be an integer: [2]"\n :at [clojure.core$even_QMARK_ invokeStatic "core.clj" 1359]}]\n :trace\n [[clojure.core$even_QMARK_ invokeStatic "core.clj" 1359]\n [clojure.core$even_QMARK_ invoke "core.clj" -1]\n [sandbox$keep_taking_while invokeStatic "NO_SOURCE_FILE" 0]... |
| 13:04 | pvinis | ops.. |
| 13:04 | justin_smith | pvinis: you need to check for the collection being empty |
| 13:04 | justin_smith | oh wait, that's another issue |
| 13:04 | justin_smith | n/m |
| 13:05 | pvinis | anyway. i will look at your and Bronsa's solutions |
| 13:05 | pvinis | and try to understand them |
| 13:05 | justin_smith | yours is almost exactly mine - except for a couple of simple to fix bugs, and mine is lazy |
| 13:16 | l1x | '(apply str (concat (apply concat (interpose ["_"] (partition 1 '("x" "y" "z")))) ".json")) |
| 13:17 | ridcully | ,(str (clojure.string/join "_" '("x" "y" "z")) ".json") |
| 13:18 | clojurebot | "x_y_z.json" |
| 13:18 | l1x | thx! |
| 15:35 | ghost__ | Hello! I have an if condition, and if it satisfies the predicate, I want to print something and recur that function. How do I do that? ((println "something")(function param)) gives a NPE |
| 15:35 | __ior | (do (thing1) (thing2)) |
| 15:35 | bluezone | yeah you need to use the do statement |
| 15:36 | ghost__ | thanks, I love you guys |
| 15:36 | MJB47_ | if you dont need the else part |
| 15:36 | MJB47_ | you can use when |
| 15:36 | __ior | he probably needs an else for the base case of the recursion |
| 15:37 | ghost__ | I kind of need else for debugging, it's my first "serious" program (tic tac toe) |
| 15:37 | ghost__ | and I want to know if my awful hacks work or not |
| 15:38 | ghost__ | anyway, will someone be my code friend? I'm so lonely |
| 15:39 | bluezone | haha |
| 15:39 | pontiki | having a code buddy would be awesome. i might actually spend time on learning clojure :/ . sadly, i have no time now. :(( |
| 15:40 | ghost__ | me neither, so I gave up on school a bit, it's not that important |
| 15:47 | pvinis | can i use parition to split a colleciton into two collections, one has the 1st, 3rd, 5th etc, and the other has the 2nd, 4th, 6th etc item |
| 15:48 | ridcully | ,(apply map vector (partition 2 (range 10))) |
| 15:48 | clojurebot | ([0 2 4 6 8] [1 3 5 7 9]) |
| 15:49 | ridcully | (only works for even length) |
| 15:50 | pvinis | yea but i guess partition-all works for odd |
| 15:50 | amalloy | probly not |
| 15:50 | ridcully | nope |
| 15:50 | amalloy | because of the apply map |
| 15:50 | ridcully | because map will choke on it then |
| 15:50 | ridcully | ,(apply map vector (partition-all 2 (range 9))) |
| 15:50 | clojurebot | ([0 2 4 6 8]) |
| 15:51 | pvinis | how can i make odds work then? |
| 15:51 | amalloy | well, start by deciding what you want the result to be |
| 15:52 | pvinis | like if its [1 2 3 4 5], the result will be [1 3 5] and [2 4] |
| 15:56 | amalloy | you probably can't do a lot better than something like (map #(take-nth 2 %) [xs (rest xs)]) |
| 15:57 | pvinis | mm.. do you think it would be better if is just Start iterating over the list, and depending on the index, add it in one list or another? |
| 15:59 | amalloy | that's not very lazy |
| 15:59 | pvinis | no.. |
| 15:59 | justin_smith | ,,((fn two-parts ([coll] (two-parts coll [] [])) ([coll a b] (if (empty? coll) [a b] (recur (rest coll) (conj b (first coll)) a)))) (range 10)) |
| 15:59 | clojurebot | [[1 3 5 7 9] [0 2 4 6 8]] |
| 16:00 | justin_smith | also not lazy |
| 16:01 | justin_smith | pvinis: in my example above, instead of alternating which coll it adds to, it always adds to the second, but flips their order also |
| 16:04 | pvinis | let me try that |
| 16:11 | MJB47_ | you can do it with keep-indexed |
| 16:11 | MJB47_ | ,[(keep-indexed (fn [idx item] (if (even? idx) item)) (range 9)) (keep-indexed (fn [idx item] (if (odd? idx) item)) (range 9))] |
| 16:12 | clojurebot | [(0 2 4 6 8) (1 3 5 7)] |
| 16:12 | MJB47_ | it can probably be written more cleanly |
| 16:15 | lambda-calculus | ,((fn [xs] [(take-nth 2 xs) (take-nth 2 (rest xs))]) (range 10)) |
| 16:15 | clojurebot | [(0 2 4 6 8) (1 3 5 7 9)] |
| 16:18 | pvinis | lambda-calculus: thats nice |
| 16:21 | lambda-calculus | It's also lazy. |
| 16:22 | MJB47_ | and it makes me look bad |
| 16:22 | MJB47_ | trifecta of good code :P |
| 16:30 | amalloy | isn't that the longhand version of what i suggested? |
| 16:30 | justin_smith | yes |
| 16:31 | lambda-calculus | amalloy: Sorry, didn't see your comment. |
| 17:09 | orzn | Does anyone know the "proper" way to generate an API key? |
| 18:10 | domgetter | Is there something like doseq but that doesn't run the cartesian product of its bindings? |
| 18:12 | domgetter | so like (dothese [x (range 10) y (range 10)] (println [x y])) --> [0 0] [1 1] [2 2] [3 3] [4 4] ... [9 9] |
| 18:13 | MJB47_ | dont think so |
| 18:14 | MJB47_ | how would tha work with unequally sized bindings? |
| 18:16 | domgetter | MJB47_: I might have an XY problem here |
| 18:17 | lambda-calculus | ,(dorun (map (fn [x y] (println [x y])) (range 10) (range 10))) |
| 18:17 | clojurebot | [0 0]\n[1 1]\n[2 2]\n[3 3]\n[4 4]\n[5 5]\n[6 6]\n[7 7]\n[8 8]\n[9 9]\n |
| 18:17 | domgetter | The reason I ask is I'm doing something like this: (doseq [color (-> pixels transform palette)] (aset array index color)) but by the time I get to the aset, I don't have an index to refer to anymore |
| 18:18 | justin_smith | domgetter: (doseq [[index color] (map list (range) (-> pixels transform palette))] ...) |
| 18:19 | domgetter | I think I have to go back to the drawing board. Thanks for your input :) |
| 18:21 | TEttinger | if you're doing lots of aset consider amap |
| 18:21 | TEttinger | (or areduce) |
| 18:22 | justin_smith | TEttinger: it's as if they did (map (fn [f] (defn (cons 'a def) ...) clojure.core) |
| 18:22 | TEttinger | ha |
| 18:22 | TEttinger | except amap has a totally insane signature |
| 18:22 | TEttinger | ,(doc amap) |
| 18:22 | clojurebot | "([a idx ret expr]); Maps an expression across an array a, using an index named idx, and return value named ret, initialized to a clone of a, then setting each element of ret to the evaluation of expr, returning the new array ret." |
| 18:23 | justin_smith | right, and my map above is totally nonsense |
| 21:39 | jjttjj | I set up an emacs copying these config files: https://github.com/flyingmachine/emacs-for-clojure everything's great except in the cider repl, matching curly braces are not correclty inserted when I type an opening curly brace |
| 21:40 | jjttjj | When I manually enable clojure-mode on this buffer the closing brace is correctly created, but pressing enter no longer causes the repl input to be evaluated, it just adds a new line |
| 21:41 | jjttjj | Anyone know what might be going wrong here? |
| 21:46 | amalloy | jjttjj: you kinda have to either not have paredit-mode on in your repl buffer, or use C-RET (maybe it's shift-RET?) to send expressions |
| 21:46 | amalloy | because paredit-mode expects you to be pressing enter in the middle of unfinished expressions all the time |
| 21:47 | amalloy | so you can either live with the default (which is what i do, as someone who doesn't write big expressions in the repl), or add a (paredit-mode 1) hook to your cider repl hook and then use a different key to send expressions |
| 21:49 | jjttjj | amalloy: thanks! |