2015-02-23
| 02:31 | ewemoa | get an error with fresh check out of mies-node: https://pastee.org/pfbe9 -- does this work for anyone else? |
| 05:23 | robindunbarr | Hi all, I cannot grasp the difference behind comp, compare, and comparator. |
| 05:24 | H4ns | is it idiomatic to use multimethods to tie together multiple implementations of a similar thing? i'm tempted to use a multimethod to implement various file transfer protocols, using the scheme/protocol from the url as dispatch value. |
| 05:25 | H4ns | i.e. (defmulti ls (fn [url] (.getScheme (URI. url)))) and then, in ftp.clj, (defmethod protocols/ls "ftp" [url] ...) |
| 05:26 | H4ns | yay or nay? |
| 05:27 | ordnungswidrig | h4ns: interesting question. I would suggest to think about error conditions. do all protocols handle that the same? |
| 05:27 | ordnungswidrig | e.g. 404 vs. exception |
| 05:27 | i-blis | robindubarr: comp is function composition ((comp first rest) [1 2 3]) <-> (first (rest [1 2 3])), very handy when you map, filter etc |
| 05:27 | H4ns | ordnungswidrig: for my purposes, all protocols would signal exceptions when there was an error |
| 05:28 | H4ns | ordnungswidrig: i subscribe to the fail fast philosophy, so most errors will be treated as fatal anyway |
| 05:28 | robindunbarr | i-blis: Right, so there’s no relation to compare and comparator. |
| 05:28 | ordnungswidrig | h4ns: I think this could. th eonly other options is to register url handlers to some dispatcher. |
| 05:28 | robindunbarr | i-blis: However, I still do not understand how compare works. |
| 05:28 | ordnungswidrig | h4ns: which is what a multimethods does. |
| 05:29 | H4ns | ordnungswidrig: right. the thing is that unless i'm building an uberjar, clojure does not implicitly load the protocol implementations, so at some point, i need to iterate them all. |
| 05:29 | ordnungswidrig | h4ns: not sure what you men |
| 05:30 | ordnungswidrig | ...mean |
| 05:30 | H4ns | ordnungswidrig: but i think i can live with that. i just wondered if that'd be considered abusive. |
| 05:30 | i-blis | robindunbarr: take a look at the examples on grimoire: http://conj.io/store/v0/org.clojure/clojure/1.7.0-alpha4/clj/clojure.core/compare/ |
| 05:30 | robindunbarr | i-blis, thanks I will check it out. |
| 05:30 | robindunbarr | clojure-docs isn’t that helpful, though. |
| 05:31 | H4ns | ordnungswidrig: i mean that just by defining a few methods, i do not force the protocol implementation to be actually loaded. i need to make sure that it is loaded by some other means (i.e. by requiring all protocols explicitly into a top-level namespace) |
| 05:31 | i-blis | robindunbarr: basically it returns positive if the first arg is greater than the second |
| 05:31 | robindunbarr | i-blis it as in compare? |
| 05:31 | ordnungswidrig | I see. |
| 05:31 | H4ns | ordnungswidrig: anyway, i think i'm good, thanks for your comment |
| 05:33 | ordnungswidrig | H4ns: on point againt multis is that you cannot change the implementation for a protocol at runtime. |
| 05:34 | H4ns | ordnungswidrig: that is not a requirement, but what do you mean? i cannot recompile a method? |
| 05:35 | ordnungswidrig | h4ns: I don't think it's good style to redefine a defmethod |
| 05:35 | H4ns | ordnungswidrig: you mean at run time, because it may break optimizations? |
| 05:37 | ordnungswidrig | h4ns: yes at runtime. say a user of the lib wants to use a different ftp implementation. you can redfine a defmethod, (not sure). However, in the case another code path also uses your lib that might lead to unexpected effects. |
| 05:38 | H4ns | ordnungswidrig: ah, ok - well, this is out of scope for what i'm doing right now. i just need to support ftp and sftp for file transfers and would like to use a unified interface for the two. |
| 05:39 | ordnungswidrig | h4ns: then use a defmulti and change it if it sould give you problems at any time |
| 05:39 | H4ns | ordnungswidrig: aye |
| 05:42 | ordnungswidrig | :-) |
| 06:38 | zot | i can't easily tell, since it's a java impl underneath: is doing (seq foo) always equivalent to (when-not (empty? foo) foo) ? |
| 06:40 | zot | ah, yes. i see my own answer now. |
| 06:47 | owl-v- | is openjdk free to use in commercial products? |
| 06:55 | alexyakushev | Hey everyone, I'm getting this error "Can't change/establish root binding of: *warn-on-reflection* with set" when I do (set! *warn-on-reflection* true) inside my namespace. Apparently the thread-binding of *warn-on-reflection* does not happen. My question is: where it is suppose to happen in the first place? |
| 06:55 | alexyakushev | I can find two bindings of WARN_ON_REFLECTION in RT.java, one when loading user.clj, and one when loading precompiled classes. But that's only when loading them, not when evaluating them |
| 06:56 | Glenjamin | i tend to set it via leiningen |
| 06:57 | alexyakushev | Yeah, I know, but I need to handle this case too |
| 07:31 | dejanr | hi, could anyone suggest me a good starting read for Clojure and ClojureScript, i have 10 years of web development experience, but never did Java or Clojure before |
| 07:32 | dejanr | i would like to feel the full benefit of clojure envirionment, and do a small side project |
| 07:32 | agarman | http://www.braveclojure.com |
| 07:33 | agarman | some folks dislike that it steers users toward emacs |
| 07:33 | dejanr | i am vim user for 5 years, but i have been looking to learn emacs too |
| 07:34 | agarman | that's another blog series that's useful for beginners |
| 07:34 | dejanr | thanks, looking into it |
| 07:35 | om | is it safe to assume that only a var with a :arglists entry in its metadata points to a fn, and that if in addition to that it has no :macro entry, then it is a normal (non-macro) fn (to be evaled at runtime)? https://www.refheap.com/97677 |
| 07:40 | dejanr | agarman: what do you think about datomic, and how far profesional project could go with free or first tier of pricing. Or do you prefer usual path by using open source dbs, and whats available |
| 07:42 | agarman | dejanr: it depends |
| 07:43 | alexyakushev | om: For macro part it is true |
| 07:43 | alexyakushev | om: For functions I'm not so sure |
| 07:43 | agarman | dejanr: there is good support for SQL, cassandra, mongo etc in Clojure. pick whatever is best for your app |
| 07:43 | alexyakushev | om: Do you only have the access to var metadata, but can't resolve them? |
| 07:44 | dejanr | agarman: do you think you are more competent building distributive apps, and micro services, with clojure and actor model of concurency? |
| 07:45 | om | alexyakushev: right, I could resolve them; thanks! |
| 07:45 | agarman | dejanr: been using Erlang for distributed parts of my apps of late |
| 07:45 | agarman | dejanr: Clojure is great for concurrency |
| 07:46 | alexyakushev | om: Although be careful to correctly determine if something is a function |
| 07:46 | alexyakushev | For example |
| 07:46 | alexyakushev | (instance? clojure.lang.IFn {}) => true |
| 07:47 | dejanr | agorman: i see thanks, is that common? or people use successfully clojure for distributed parts too? |
| 07:47 | om | alexyakushev: yeap, I thought about such cases where IFn is implemented (so it's functionnaly speaking a function!) |
| 07:48 | om | alexyakushev: I am gathering stats on some of my growing namespaces |
| 07:48 | alexyakushev | om: Maybe your :arglists approach is more reliable |
| 07:49 | alexyakushev | Furthermore, it seems you are doing something tooling-related, so an error here or there wouldn't be much of an issue, right? |
| 07:49 | agarman | dejanr: you can do distributed programming in Clojure or whatever language. Erlang just has most of what you need to build already built. |
| 07:49 | om | right |
| 07:50 | om | still, I had a function to check the instance, so I can cross check if I need to (may be it will reveal some strange edge cases) |
| 07:50 | dejanr | agorman: so you used erlang for supervisoring and distributed part, and clojure for doing real work, right? |
| 07:50 | om | s/I had/I'll add/ |
| 07:53 | om | alexyakushev: спасибо! :) |
| 07:53 | alexyakushev | om: You're welcome;) |
| 08:03 | agarman | dejanr: mostly handling truly distributed aspects with erlang ... next version of app may be mostly erlang |
| 08:11 | dejanr | agorman: would you suggest me to start with Erlang or Clojure. I am looking to find better way of building apps, and solving better scaling problems current web technologies offer |
| 08:12 | dejanr | agorman: and invest in something that would pay off over greater period of time |
| 08:14 | mnngfltg | (object-array [1 2 3]) => #<Object[] [Ljava.lang.Object;@31163991> <-- any info how to read this REPl output? |
| 08:14 | mnngfltg | That is, what does [L...;@n] stand for? |
| 08:16 | Bronsa | mnngfltg: it's the internal jvm representation of the "object array" class |
| 08:17 | agarman | dejanr: Clojure is a great language; learn it. It's worthwhile, especially if you're doing webdev. |
| 08:17 | Bronsa | mnngfltg: "[" means it's an array, L<class name>; tells you the class. primitive types have single letter representations e.g. long is J, int is I etc |
| 08:18 | mnngfltg | Bronsa, I see |
| 08:18 | Bronsa | mnngfltg: so "[[I" will mean a int[][], "[[[Ljava.lang.String;" a String[][][] etc |
| 08:20 | JavaDog | Could anyone enlighten me as to why this throws "java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Long"? http://pastebin.com/hK67eRP4 |
| 08:20 | mnngfltg | and @31163991 is the hash code in hex |
| 08:21 | mnngfltg | which I suppose is some variant of the underlying pointer right? |
| 08:21 | JavaDog | It's gotta be something to do with lazy sequences but I don't know how to solve it because I started with clojure 2 days ago :o |
| 08:21 | Bronsa | JavaDog: take-nth takes n and coll, not coll and n |
| 08:21 | JavaDog | oh, shit |
| 08:22 | mnngfltg | JavaDog, I always get the arg order wrong |
| 08:22 | om | JavaDog: (take-nth n coll) |
| 08:22 | Bronsa | mnngfltg: it's some sort of hash code yeah, no idea exactly what it corresponts to |
| 08:22 | mnngfltg | it's the most frequent mistake I make in clojure |
| 08:22 | timvisher | anyone have an irc channel they like for web development? |
| 08:22 | JavaDog | It's confusing because some of the nth-related functions want (coll, i) and some want (i, coll) |
| 08:23 | mnngfltg | JavaDog, it helps if your editor shows the signature of the function at point automatically |
| 08:23 | om | JavaDog: it is idiomatic clojure to have coll as last argument |
| 08:24 | mnngfltg | Bronsa, do you know what the hash means when you're talking about an array? the first element? or are arrays contained in objects? |
| 08:24 | Bronsa | mnngfltg: usually sequence operations take the coll as the last arg while coll operations take it as first parameter |
| 08:24 | Bronsa | mnngfltg: no it's an instance hash |
| 08:24 | mnngfltg | om, except for, e.g., `conj` |
| 08:24 | Bronsa | ,(object-array []) |
| 08:24 | clojurebot | #<Object[] [Ljava.lang.Object;@49032abc> |
| 08:24 | Bronsa | ,(object-array []) |
| 08:24 | clojurebot | #<Object[] [Ljava.lang.Object;@60a9c6d0> |
| 08:25 | JavaDog | It's the same thing you get if you try to print the value of an object in java and haven't overridden toString() |
| 08:25 | mnngfltg | Bronsa, interesting distnction, between seq operations and coll operations |
| 08:25 | Bronsa | mnngfltg: yeah arrays are objects |
| 08:27 | mnngfltg | Bronsa, Java's object model is certainly a bit confusing but it probably makes sense |
| 08:28 | mnngfltg | sequence functions: map, filter, reduce <--- take coll as final arg, require ->> |
| 08:29 | mnngfltg | coll function: assoc, dissoc, conj <-- take coll as first arg, require -> |
| 08:29 | mnngfltg | I'm looking for a mnemonic :) |
| 08:29 | JavaDog | take-nth appears to grab the first item in the list, and the continue to get the nth item after that. I don't want that, how can I make it just start from the beginning of the list and get me the first n items? |
| 08:29 | JavaDog | er |
| 08:30 | om | mnngfltg: yeap |
| 08:30 | JavaDog | each nth item |
| 08:30 | om | JavaDog: (take n coll) |
| 08:31 | JavaDog | If I processed this list with n=3, then I would want (7 15 25) returned: '(1 3 7 9 13 15 19 21 25) |
| 08:31 | om | ah |
| 08:33 | JavaDog | maybe (take-nth (next (dec n)) coll)? |
| 08:34 | JavaDog | er |
| 08:34 | JavaDog | next being first, rather |
| 08:35 | JavaDog | this is my first foray into functional programming (i'm a java/android/web guy) and let me tell you, it's pretty damn difficult :p |
| 08:35 | Glenjamin | (doc take) |
| 08:35 | clojurebot | "([n] [n coll]); Returns a lazy sequence of the first n items in coll, or all items if there are fewer than n. Returns a stateful transducer when no collection is provided." |
| 08:35 | om | JavaDog: or, (map last (partition-all n coll)) |
| 08:35 | mbac | JavaDog: yeah, it's kind of like learning to program for the first time since it's both a new language and a new paradigm |
| 08:35 | mbac | but only kind of |
| 08:36 | mnngfltg | JavaDog, to take every nth you'll need to generate a lazy-seq yourself |
| 08:37 | JavaDog | How would I do that? |
| 08:38 | maacl | How can I upgrade to nrepl 0.2.7 ? CIDER 0.9.0 is complaining that only 0.2.6 is available and lein (upgraded to latest) also pulls down 0.2.6? |
| 08:40 | om | JavaDog: partition does generate a lazy-seq for you, with sequences of count n |
| 08:41 | om | ,(map last (partition 3 [1 3 7 9 13 15 19 21 25])) |
| 08:41 | clojurebot | (7 15 25) |
| 08:42 | mnngfltg | good call, om |
| 08:43 | om | mnngfltg: thanks! (but probably not very efficient on very long colls) (because of last) |
| 08:46 | JavaDog | om: Aha, thanks. |
| 08:53 | om | JavaDog: you're welcome |
| 08:54 | JavaDog | I'm trying to understand the use of map though. Why couldn't I just run (last (partition ...))? |
| 08:55 | om | JavaDog: because you want the last of each (sub-sequence of length n) |
| 08:55 | JavaDog | oh, okay. I was misunderstanding partition |
| 08:58 | om | JavaDog: you may want to play a little with 4clojure, it is a nice way to discover the core functions |
| 08:59 | JavaDog | I have used it. Unfortunately the core functions lessons are so easy that they didn't really sink in :( |
| 08:59 | JavaDog | I do plan to continue with some more difficult ones though |
| 09:10 | neoartifex | Hi, i've got an issue while using :group-by option in scatter-plot function in Incanter 1.9 |
| 09:11 | patrkris | hi folks. do anyone here know if its possible to have github.com/miner/herbert report *which* validations fail? as far as I can tell, I only get a true or false value |
| 09:30 | JavaDog | Am I doing something wrong here? This line is throwing classcastexception: (if (= iterator (inc (* n n))) |
| 09:30 | justin_smith | JavaDog: what are "iterator" and "n" |
| 09:31 | justin_smith | sounds like n may not be a number |
| 09:31 | JavaDog | (defn myFunc [n] (loop [iterator 1 collection (initializing code)])) |
| 09:32 | JavaDog | and the function is called with (myFunc 5) |
| 09:32 | justin_smith | what does your recur look like? |
| 09:32 | JavaDog | (recur (definitely a collection here) (inc iterator)) |
| 09:33 | JavaDog | OH |
| 09:33 | justin_smith | well the order is wrong |
| 09:33 | justin_smith | haha |
| 09:33 | JavaDog | fucking changed that. right. |
| 09:33 | mbac | shouldn't you... yeah |
| 09:33 | JavaDog | oh man... |
| 09:33 | justin_smith | that's why I'm hear asking the tough questions |
| 09:34 | JavaDog | I need to buy a rubber duck |
| 09:34 | SagiCZ | justin_smith is a free rubber duck |
| 09:35 | JavaDog | $60/mo internet access + $??? custom PC = not free |
| 09:35 | mbac | wait, didn't you get the application for your #clojure monthly rebate? |
| 09:35 | JavaDog | okay cool. Now I just have an infinite loop |
| 09:36 | JavaDog | well, not infinite. but not finishing anytime soon. |
| 09:36 | mbac | you should've been msged that when you joined |
| 09:36 | JavaDog | damn |
| 09:36 | SagiCZ | mbac: wait i thought the premium account has to be earned? |
| 09:37 | mbac | sssh! that's separate! |
| 09:37 | SagiCZ | mbac: darn!.. sorry |
| 09:38 | JavaDog | this was probably not the best problem to choose 2 days into learning clojure: http://codegolf.stackexchange.com/q/45785/38108 |
| 09:38 | mbac | it's okay, we'll roll that out for free and introduce a pro tier |
| 09:38 | JavaDog | see I was like "Oh it's just a bunch of lists, clojure will be perfect" |
| 09:38 | JavaDog | oh yeah except for how I don't know anything |
| 09:39 | hyPiRion | The first rule of #clojure monthly rebate: Do not speak about #clojure monthly rebate. |
| 09:39 | SagiCZ | JavaDog: we are very patient with people who have 'java' in their nick, dont worry |
| 09:40 | JavaDog | hahah |
| 09:40 | FunctionalDog | there you go |
| 09:41 | FunctionalDog | I feel like I'm so close and yet it's taking all my willpower not to give up. http://pastebin.com/j6ZSS8J6 |
| 09:41 | justin_smith | FunctionalDog: 4clojure has some simpler problems, and some harder ones - all are rated for difficulty |
| 09:41 | FunctionalDog | but I don't get internet points on 4clojure |
| 09:42 | justin_smith | FunctionalDog: I am suspicious of that .contains call |
| 09:42 | FunctionalDog | oh, that works for sure |
| 09:42 | FunctionalDog | my only problem right now is that the loop runs forever |
| 09:42 | FunctionalDog | after that is fixed, I'm sure I'll have 4000 other bugs to work on |
| 09:42 | SagiCZ | FunctionalDog: that means that the if condition is never true |
| 09:43 | SagiCZ | is n changing? |
| 09:43 | FunctionalDog | nope. n is hardcoded when passed |
| 09:43 | FunctionalDog | (to 5) |
| 09:43 | SagiCZ | oh i see.. but iterator is increasing |
| 09:44 | FunctionalDog | yeah |
| 09:44 | SagiCZ | add some prints to see whats happening to iterator |
| 09:44 | justin_smith | loop/recur is eager |
| 09:44 | justin_smith | and you clearly have no stop condition |
| 09:44 | justin_smith | you need a lazy version, and to take only N results from the lazy version |
| 09:44 | FunctionalDog | yeah, I was going to sort that out later because I didn't know if I had to do it now |
| 09:44 | justin_smith | oh never mind, you do have a stop condition |
| 09:45 | FunctionalDog | because I can run (range) and get an infinite list just fine, so... |
| 09:45 | SagiCZ | there is a stop condition but its not lazy |
| 09:45 | FunctionalDog | how do I make it lazy? |
| 09:45 | SagiCZ | and making it lazy later wont work very much.. you would have to rewrite it |
| 09:45 | SagiCZ | FunctionalDog: by using lazy-seq or higher order constructs |
| 09:45 | FunctionalDog | that's fine too. I just want to be done with this so I can finally go eat |
| 09:45 | justin_smith | well, concat and take and remove are already lazy |
| 09:46 | justin_smith | it would be a question of changing the loop / recur to a cons / lazy-seq / self-call |
| 09:46 | justin_smith | with a version of your function with some extra args |
| 09:46 | FunctionalDog | this is for code golf though. so even if not efficient, I want the shortest source I can |
| 09:47 | justin_smith | loop/recur is never the most concise answer in clojure |
| 09:47 | SagiCZ | although it may be the most readable one in some cases |
| 09:47 | mgaare | when first learning Clojure, it's generally better to use recursion rather than loop/recur because you're more likely to write idiomatic code that way. Bring in loop/recur later |
| 09:48 | justin_smith | I'm going back to "4clojure has easier problems", I don't think code golfing something like this is a good first intro to clojure really |
| 09:48 | FunctionalDog | oh, it's not, and I'm quite aware. this is day 2. |
| 09:48 | FunctionalDog | however, I am learning it a lot faster than I would be if I were just going through problems one by one |
| 09:49 | FunctionalDog | so I can have recur jump back to a cons statement? |
| 09:49 | SagiCZ | recur can jump only to loop or to function |
| 09:49 | FunctionalDog | oh, a function would work I guess |
| 09:52 | FunctionalDog | the main problem with this code golf is that I chose a mathy one. I suck at math |
| 09:52 | FunctionalDog | especially when it starts getting several levels deep. |
| 09:52 | FunctionalDog | fuck this noise. I'm gonna write a goddamn sailboat. |
| 09:53 | FunctionalDog | oh wait, I can't. this isn't oop |
| 09:53 | FunctionalDog | o__o |
| 09:54 | FunctionalDog | except I probably can with some arcane combination of java library calls |
| 09:54 | piranha | can somebody recommend me a database migrations library? I want to have them in simple '*.sql' files. |
| 09:54 | justin_smith | FunctionalDog: to do a lazy sequence, you do something generally like this: (fn x [arg] (if (foo? arg) nil (lazy-seq (cons (frob arg) (x (quux arg)))))) |
| 09:57 | justin_smith | FunctionalDog: everything doable in java can be done in clojure if you don't mind a bit of interop, in practice everything but concrete inheritence and annotations tends to be reasonable, and those two are iffy. |
| 09:57 | FunctionalDog | annotations are for lazy library slaves |
| 09:57 | FunctionalDog | (and testers, I guess) |
| 09:57 | FunctionalDog | (and overrides too) |
| 09:58 | justin_smith | and we only need concrete inheritence when badly written libraries demand it as well |
| 09:58 | justin_smith | because a good library would use an interface |
| 09:58 | Glenjamin | i do sometimes want sideways code re-use |
| 09:59 | Glenjamin | like when implementing a simple custom collection it'd be nice to implement seq, and make other functions use seq internally |
| 09:59 | FunctionalDog | I'm just waiting until we start to see libraries that let you annotate stuff like @MakeFlappyBirdClone, @RequirePurchaseForProgression, @EntirelyLuckBased |
| 10:00 | FunctionalDog | I thought about writing the ultimate messenger service. It would let you sign in to all your other platforms (twitter, yim, kik, whatever) |
| 10:00 | FunctionalDog | and then every time you send a message, it just sends it to every service! |
| 10:01 | justin_smith | haha |
| 10:01 | justin_smith | like bitlbee in reverse |
| 10:01 | FunctionalDog | "But what if I want to respond to a particular person or conversation, FunctionalDog?" |
| 10:01 | justin_smith | @@@@ |
| 10:01 | FunctionalDog | I will take your intended recipient and put that information directly where it belongs. In the garbage collector. |
| 10:02 | FunctionalDog | If the people who made "Yo" were so successful, why couldn't I be? |
| 10:03 | FunctionalDog | In case you don't know... https://play.google.com/store/apps/details?id=com.justyo&hl=en |
| 10:05 | FunctionalDog | Yeah I'm going to have to throw in the towel on this codegolf. Maybe I could do it in a language I actually know. |
| 10:06 | FunctionalDog | Thanks everyone for your help, regardless. I did learn a lot :p |
| 10:06 | SagiCZ | FunctionalDog: dont give up :) |
| 10:06 | ddellacosta | FunctionalDog: don't give up! |
| 10:07 | justin_smith | FunctionalDog: I'll mention 4clojure again - clojure code golf where you can see other people's answers after you solve it, with a pretty wide range of difficulty |
| 10:07 | ddellacosta | (not even sure what you shouldn't be giving up, but if it is related to learning clojure, then it fits...) |
| 10:08 | ddellacosta | 4clojure is great |
| 10:12 | SagiCZ | also maybe clojure koans? but it might be too late for that |
| 10:15 | FunctionalDog | I was just giving up because I hate this problem |
| 10:15 | FunctionalDog | Math stuff starts to really grind on me after a while and it was getting to that point |
| 10:16 | FunctionalDog | It's largely working except the loop, which I don't know how to construct properly |
| 10:18 | justin_smith | FunctionalDog: so the remove / .contains is removing every nth item, but I wonder if .contains is lazy enough |
| 10:18 | justin_smith | oh, never mind, it is |
| 10:19 | FunctionalDog | this works: (let [coll '(1 3 7 9 13 15 19 21 25), i 4] (remove #(.contains (map last (partition i coll)) %) coll)) |
| 10:19 | FunctionalDog | how do you know that it's lazy? |
| 10:20 | justin_smith | FunctionalDog: my concern was that contains would act weirdly with a boundless lazy first arg |
| 10:20 | justin_smith | but it is fine |
| 10:20 | justin_smith | ,(.contains (range) 100) |
| 10:20 | clojurebot | true |
| 10:20 | justin_smith | that would not return if it realized (range) fully |
| 10:22 | justin_smith | FunctionalDog: so I added a print, it gets to 26 and hangs... |
| 10:22 | justin_smith | I think it's all the stacked up concat / remove |
| 10:24 | FunctionalDog | hm, yeah |
| 10:24 | FunctionalDog | is there a better way to do that? It was just the first thing I came across that worked, ie (concat '(1 2 3) '(4 5 6)) |
| 10:25 | justin_smith | it could be that once you are removing all multiples of N where n is 2..26 it just takes a damned long time to get to the next non-removed items |
| 10:25 | justin_smith | FunctionalDog: using lazy-seq construction instead of eagerly building it up out of stacked concats actually helps |
| 10:26 | FunctionalDog | google: "clojure lazy sex" |
| 10:26 | FunctionalDog | mhm. |
| 10:26 | FunctionalDog | I mean, I just typed that into google |
| 10:26 | FunctionalDog | not that you should search for it |
| 10:27 | justin_smith | $grim clojure.core/lazy-seq |
| 10:27 | lazybot | http://grimoire.arrdem.com/1.6.0/clojure.core/lazy-seq |
| 10:27 | justin_smith | see above link for docs and examples |
| 10:27 | justin_smith | you are very close to solving this, it's just a concat bomb right now is all I think |
| 10:28 | justin_smith | FunctionalDog: you'll notice that same pattern I mentioned before in the examples on that page |
| 10:28 | justin_smith | (fn x [arg] (if (foo? arg) nil (lazy-seq (cons (frob arg) (x (quux arg)))))) |
| 10:31 | justin_smith | FunctionalDog: I'm also concerned with the fact that you aren't dropping from the collection in the second half of the concat |
| 10:32 | FunctionalDog | Oh, I had a drop there before. must have forgotten to re-add it when I changed everything |
| 10:33 | FunctionalDog | added it again but that hasn't fixed anything noticeable yet |
| 10:34 | justin_smith | FunctionalDog: yeah, I put a print inside your remove condition that isn't printing at all |
| 10:34 | justin_smith | which makes me hella suspicious |
| 10:34 | FunctionalDog | hm. why would that happen? |
| 10:34 | justin_smith | nested concats can be a stack bomb |
| 10:34 | justin_smith | because concat is lazy |
| 10:35 | justin_smith | so you end up with a massive pile of ops to do to generate the next item |
| 10:35 | FunctionalDog | I thought I wanted to keep it lazy until the very end |
| 10:35 | FunctionalDog | (of the function) |
| 10:36 | justin_smith | yeah, recursive calls to concat are not a good way to do that in clojure, it's a weird thing |
| 10:36 | FunctionalDog | I guess I want to effectively model the formula, and then just extrapolate based on the input |
| 10:36 | FunctionalDog | not be doing anything with big lists ever until the program is about to exit. right? |
| 10:37 | FunctionalDog | and you're saying everything I have is lazy, like I want, except the concats |
| 10:37 | justin_smith | concat is lazy |
| 10:38 | FunctionalDog | Then I am 100% confused |
| 10:38 | justin_smith | it's just that it is also pathological when nested deeply |
| 10:39 | FunctionalDog | I guess what I'm stuck on with converting to a cons call or something is, how can I join a list to another without concat? |
| 10:39 | FunctionalDog | Because I need to be able to do (1 2 3) + (4 5 6) to get (1 2 3 4 5 6). IIRC cons only adds a single element |
| 10:39 | justin_smith | if you are using cons, why would you need to join two lists for this problem? |
| 10:40 | opqdonut | and why do you want to do it without concat? it's the right tool for the job |
| 10:40 | FunctionalDog | I'm looking at the examples you linked |
| 10:41 | justin_smith | opqdonut: his code stalls after the iterator reaches the goal value. I was suspecting the nested concats, but it could be some other issue http://pastebin.com/j6ZSS8J6 |
| 10:41 | FunctionalDog | is any one of them particularly relevant? I have a hard time reading/understanding these very fast |
| 10:41 | opqdonut | justin_smith: link's broken |
| 10:41 | FunctionalDog | oh, sieve is relevant |
| 10:42 | opqdonut | ok nevermind I see tehre's a huge backlog, carry on :P |
| 10:42 | justin_smith | opqdonut: OK, FunctionalDog can repaste if he wants |
| 10:42 | FunctionalDog | http://pastebin.com/nNrG7YmQ |
| 10:42 | FunctionalDog | I must have hit 10 mins or something |
| 10:42 | FunctionalDog | lol |
| 10:42 | m4farrel | what's a quick way to convert a 1D seq to a 2D seq in clojure? Like take a seq and group parts of the seq of size 'width' together? |
| 10:43 | m4farrel | like (1d->2d 2 [1 2 3 4]) => [[1 2] [3 4]] |
| 10:43 | opqdonut | ,(partition 2 [1 2 3 4]) |
| 10:43 | FunctionalDog | partition! |
| 10:43 | clojurebot | ((1 2) (3 4)) |
| 10:43 | FunctionalDog | oh, yeah ^ |
| 10:43 | FunctionalDog | see, learning |
| 10:43 | m4farrel | sweet, thanks |
| 10:45 | opqdonut | FunctionalDog: it seems to me you're calling (.contains x y) where x is an infinite list |
| 10:45 | opqdonut | FunctionalDog: do you see why this can never return false? |
| 10:46 | FunctionalDog | indeed |
| 10:46 | opqdonut | ,(.contains (range) -1) |
| 10:46 | clojurebot | #<OutOfMemoryError java.lang.OutOfMemoryError: Java heap space> |
| 10:46 | opqdonut | you need to write your own monotonic-sequence-contains function |
| 10:46 | opqdonut | if I understand what you're trying to accomplish |
| 10:46 | FunctionalDog | well, it's for code golf, so I want to inline and reduce as much as possible |
| 10:47 | FunctionalDog | that said, I probably couldn't get it right even if it weren't for codeolf |
| 10:47 | opqdonut | what's the spec? |
| 10:47 | FunctionalDog | http://codegolf.stackexchange.com/q/45785/38108 |
| 10:47 | FunctionalDog | lucky number generator |
| 10:48 | FunctionalDog | I know I need to restructure my loop. the finish condition isn't quite right |
| 10:48 | FunctionalDog | I need to be checking how many lucky numbers I've got |
| 10:48 | justin_smith | FunctionalDog: opqdonut has a good point (.contains (infinite-generator) x) is fine for the true case, but it's just an infinite loop for the false case |
| 10:49 | FunctionalDog | and I do know that to calculate n lucky numbers, you need to start with the range 1 -> n^2+1 |
| 10:49 | opqdonut | FunctionalDog: it should be pretty easy to make a solution of the form (take n (generate-all-lucky-numbers)) |
| 10:49 | opqdonut | a la the haskell solution behind your link |
| 10:49 | FunctionalDog | I've tried to read that haskell several times and it just... yeah |
| 10:49 | FunctionalDog | I'm a java guy. |
| 10:49 | opqdonut | and it'll be a good exercise in laziness |
| 10:50 | justin_smith | opqdonut: that's why I was trying to get him to look at lazy-seq (and also trying to get him to try simpler stuff first) |
| 10:50 | FunctionalDog | well I tried to give up but you guys kept encouraging me :p |
| 10:51 | justin_smith | heh |
| 10:51 | FunctionalDog | yeah, I think that is the ideal solution though |
| 10:51 | FunctionalDog | one function which can generate all lucky numbers lazily, and then just a call to it with the user input n |
| 10:52 | FunctionalDog | and that's what I'm going for. but not attaining. |
| 10:52 | justin_smith | FunctionalDog: yeah, opqdonut hit the nail on the head - the problem was not the concat (it was a small nest of them after all), it's what the .contains call does when the infinite input does not contain the thing you are looking for |
| 10:52 | FunctionalDog | is there an alternative I should use, or some way I can limit its loopiness? |
| 10:52 | justin_smith | FunctionalDog: so your current code will work if you change the .contains to something that scans for a match, or a larger number, returning true for the former, false for the latter |
| 10:53 | TimMc | ,(.contains (range) -1) |
| 10:53 | clojurebot | #<OutOfMemoryError java.lang.OutOfMemoryError: Java heap space> |
| 10:53 | justin_smith | because it's an ordered collection, no match will be found after a larger number |
| 10:53 | justin_smith | so just short circuit it there |
| 10:53 | TimMc | Silly bot, why can't you just look at it? |
| 10:53 | justin_smith | haha |
| 10:54 | FunctionalDog | okay, let's see if I can come up with something |
| 10:54 | justin_smith | based on your other code, I am confident you can write that function (brb, coffee) |
| 11:00 | justin_smith | s/will work/will be close to working/ - you'll still need a drop call in there I think |
| 11:01 | TimMc | ,(unchecked-inc Long/MAX_VALUE) |
| 11:01 | clojurebot | -9223372036854775808 |
| 11:01 | TimMc | ,(unchecked-inc (identity Long/MAX_VALUE)) |
| 11:01 | clojurebot | #<ArithmeticException java.lang.ArithmeticException: integer overflow> |
| 11:03 | FunctionalDog | I added a drop |
| 11:03 | FunctionalDog | it's in that last paste |
| 11:05 | om | if I want a function to resolve the *ns* of the calling namespace, I have to wrap it in a macro, right? |
| 11:06 | alejandrozf | hi people, I'm wondering why clojure works only compiling to JVM, it's not possible create a Clojure->.java compiler_ |
| 11:07 | FunctionalDog | that would be called a translator, not a compiler |
| 11:07 | FunctionalDog | (or something like that) |
| 11:07 | FunctionalDog | (but still not a compiler) |
| 11:08 | alejandrozf | FunctionalDog: a compiler is , in principle, a translator |
| 11:08 | FunctionalDog | Sure, but usually to some "more executable" piece of code |
| 11:08 | FunctionalDog | I feel like java source doesn't qualify as a compilation target |
| 11:09 | FunctionalDog | that's why when you write in some language that gets translated to another language before it's compiled, it's called an interpreted language |
| 11:10 | FunctionalDog | wait, maybe that's not what that means. I don't know. |
| 11:10 | FunctionalDog | Don't listen to me. I don't even know clojure very well lol |
| 11:11 | alejandrozf | well, but I think .java source files would be more "clean" of unpleaseant |
| 11:11 | alejandrozf | ...JVM issues |
| 11:13 | alejandrozf | besides, one could write a program in clojure and present it as a .java program for let say, Java employers, |
| 11:13 | alejandrozf | if such transalator exists |
| 11:14 | alejandrozf | sorry for my poor english |
| 11:14 | daniel` | alejandrozf: don't think anyone really wants it |
| 11:14 | FunctionalDog | have you ever seen the HTML output from tools like dreamweaver? I can only imagine a similar unreadable mess |
| 11:14 | daniel` | i don't see why it wouldn't be possible |
| 11:14 | Glenjamin | afaik early version of clojure did compile to java source |
| 11:15 | alejandrozf | FunctionalDog: would be a cost, but if well designed minimize that problem |
| 11:16 | FunctionalDog | justin_smith: I'm a little confused. I get the logic of the problem I'm trying to solve, but I have no idea how to implement it in clojure |
| 11:16 | alejandrozf | Glenjamin: yes? and why not on recent versions_ |
| 11:16 | FunctionalDog | if(set contains larger number) return false; else if(set contains this number) return true; |
| 11:16 | alejandrozf | ? |
| 11:16 | FunctionalDog | er, 'list', rather than set |
| 11:16 | Glenjamin | presumably it was decided that bytecode was better |
| 11:16 | FunctionalDog | collection, perhaps |
| 11:17 | daniel` | compiling to .java would basically mean compiling it twice rather than once |
| 11:17 | alejandrozf | Glenjamin: :(, both should coexist |
| 11:17 | daniel` | and i dont think many people would prefer to read java over clojure |
| 11:17 | Glenjamin | presumably someone knows why, but i don't |
| 11:17 | FunctionalDog | (at least until I know clojure better, it's damn difficult to read) |
| 11:18 | alejandrozf | daniel`: but integrate better with "java code" |
| 11:18 | favetelinguis | du i need to compile my java class to be able to import it in my clojure namspace? |
| 11:19 | justin_smith | FunctionalDog: not really, because the set is infinite - you need to scan individual items until larger than the item (when you know you hit false) |
| 11:19 | daniel` | alejandrozf: i think as FunctionalDog said, the java output would be a mess |
| 11:20 | daniel` | clojure integrates pretty well with java when needed, as it is |
| 11:20 | FunctionalDog | justin_smith: so in my original code, I guess there's an internal loop happening with that "remove" call, and clojure is trying to loop through the infinite list and it hangs, right? |
| 11:20 | TimMc | FunctionalDog: Clojure-as-Java would be harder to read. |
| 11:21 | justin_smith | FunctionalDog: exactly, what you want instead is a loop where you test each item in the coll - if it equals the thing you return true, if it's larger than the thing return false, otherwise recur and test the next item |
| 11:21 | alejandrozf | people, i'm far far to Clojure expertise but thinking if clojure would look like Hy, like more to more Lisp-people |
| 11:22 | FunctionalDog | justin_smith: Now I have to decide how to build that loop, though. Would I do it with loop-recur, or is there a better way for this instance? |
| 11:23 | TimMc | FunctionalDog: (+ 2 2) becomes clojure.java.api.Clojure.var("clojure.core", "+").invoke(2, 2); |
| 11:24 | FunctionalDog | TimMc: eh? |
| 11:24 | justin_smith | FunctionalDog: you can use (recur) to recur a function without loop |
| 11:24 | justin_smith | FunctionalDog: in the repl, design a function with that logic, it should be pretty straightforward |
| 11:24 | FunctionalDog | justin_smith: aha, that's the sort of thing I was looking for |
| 11:24 | FunctionalDog | yeah that's what I'm doing. I can compact it for golf later |
| 11:25 | justin_smith | premature optimization and all that |
| 11:25 | justin_smith | make it work, then, make it short afterward |
| 11:25 | FunctionalDog | I tend to be okay at optimizing and such. I wrote a pretty efficient MD5 hash collision finder in java for the lols |
| 11:26 | FunctionalDog | ooh, I should make that a codegolf if it doesn't already exist |
| 11:26 | justin_smith | I was speaking in the general sense - code compactness (golfing) is a kind of optimization |
| 11:26 | FunctionalDog | yeah |
| 11:27 | TimMc | FunctionalDog: You said you'd like to see Clojure translated into Java. That's what it would look like. |
| 11:28 | FunctionalDog | Not me. I think you meant alejandrozf :p |
| 11:28 | FunctionalDog | I just mentioned that it would be ugly, like the html output from dreamweaver |
| 11:29 | FunctionalDog | oh, I guess I did |
| 11:29 | FunctionalDog | But it was a joke. that would be horrible |
| 11:29 | FunctionalDog | a really clear, hand-made translation could be useful in learning though |
| 11:30 | FunctionalDog | like, "these programs do the same thing", not "these programs are literally the same" |
| 11:30 | TimMc | Ah, misread "raises hand". |
| 11:34 | Glenjamin | the original discussion was why the clojure compiler emits java byte code instead of java source code |
| 11:38 | SegFaultAX | What would you call a function like (defn name-me [& args] (fn [f] (apply f args))? |
| 11:38 | SegFaultAX | It's kind of like partial application, except you're making the entire argument list a value that you can apply to arbitrary functions. |
| 11:39 | mdrogalis | SegFaultAX: A closure? |
| 11:39 | justin_smith | SegFaultAX: on-args maybe |
| 11:39 | SegFaultAX | mdrogalis: :) I mean what would you call name-me? |
| 11:39 | mdrogalis | SegFaultAX: Derp. Sorry, heh. |
| 11:40 | justin_smith | (def to-twos (on-args 2 2)) (to-twos +) |
| 11:40 | mbac | SegFaultAX: apply-factory :P |
| 11:40 | SegFaultAX | It's weird, right? It's vaguely related to partial, apply, and maybe similar to juxt in a way. |
| 11:40 | SegFaultAX | I guess it's like the dual of juxt. |
| 11:41 | justin_smith | maybe apply-to |
| 11:41 | justin_smith | ((apply-to 2 2) +) |
| 11:41 | justin_smith | that is kind of readable |
| 11:41 | SegFaultAX | apply-with maybe? |
| 11:41 | mbac | can you work combinator into there somewhere? |
| 11:42 | SegFaultAX | mbac: Pff, definitely. |
| 11:44 | FunctionalDog | justin_smith: Well, I wrote a function, but I don't know why it doesn't work |
| 11:44 | FunctionalDog | http://pastebin.com/4BQ4q3bq |
| 11:45 | FunctionalDog | (line number is accurate on pastebin also) |
| 11:45 | FunctionalDog | as for why line 12 has an anonymous function, I couldn't tell you |
| 11:45 | justin_smith | FunctionalDog: well, to work where you call it, it would need to return a function |
| 11:45 | justin_smith | FunctionalDog: and you definitely don't want contains |
| 11:45 | justin_smith | that's the same problem as before |
| 11:46 | justin_smith | you want to do an = check with the first element of the collection |
| 11:46 | FunctionalDog | oh, I see what you mean |
| 11:46 | justin_smith | do you know about let yet? |
| 11:46 | justin_smith | let would be helpful there |
| 11:47 | FunctionalDog | why would I want to return a function, though? |
| 11:47 | FunctionalDog | remove just removes based on a boolean predicate |
| 11:47 | justin_smith | FunctionalDog: because teh first arg to remove must be a function |
| 11:47 | FunctionalDog | oh, it has to be? |
| 11:47 | justin_smith | yes, has to be |
| 11:47 | justin_smith | I mean, how else would findMatches know what to compare to? |
| 11:47 | justin_smith | it needs to have an arg |
| 11:48 | justin_smith | so you need a function that returns a comparator function when given a coll and an element |
| 11:48 | justin_smith | err - not quite that, sorry |
| 11:49 | justin_smith | one way to do it would be to make findMatches take a coll and return a function to test an element |
| 11:49 | justin_smith | another way would be to make an anonymous function (like you had before) that constructs the function you need each loop iteration |
| 11:49 | FunctionalDog | I'll keep it separated for now, for clarity |
| 11:52 | justin_smith | (defn match-finder [coll] (fn [ele] (loop [[x & xs] coll] (cond (> x ele) false (= x ele) true (recur xs)))) something like this I think |
| 11:52 | FunctionalDog | but that's using loop |
| 11:52 | justin_smith | sure, it has a loop, it could be rewritten not to |
| 11:54 | justin_smith | (defn find-match [[x & xs] ele] (cond (> x ele) false (= x ele) true (recur xs ele)) then you would pass (partial find-matches coll) in the remove |
| 11:54 | FunctionalDog | what's this business? [[x & xs] ele] |
| 11:54 | justin_smith | ,((fn [[x & xs]] x) [:a :b :c]) |
| 11:55 | clojurebot | :a |
| 11:55 | justin_smith | ,((fn [[x & xs]] xs) [:a :b :c]) |
| 11:55 | clojurebot | (:b :c) |
| 11:55 | justin_smith | it's argument destructuring, a crucial code-golf technique in clojure |
| 11:55 | justin_smith | it replaces usage of first / rest in this case |
| 11:55 | FunctionalDog | ah okay, I saw that on 4clojure earlier but forgot about it |
| 11:56 | justin_smith | I use it in one liners here out of habit |
| 11:58 | FunctionalDog | so it's just grabbing first and calling it x, and rest is xs |
| 12:03 | justin_smith | right |
| 12:04 | justin_smith | in a concise way |
| 12:04 | justin_smith | the names are of course arbitrary |
| 12:04 | justin_smith | ,(let [[tree & trees] (range)] tree) |
| 12:04 | clojurebot | 0 |
| 12:06 | FunctionalDog | would this work? http://pastebin.com/wd2C8j7a |
| 12:07 | FunctionalDog | I guess I don't actually do anything in it yet |
| 12:09 | justin_smith | FunctionalDog: well, that mixes up two different approaches |
| 12:09 | FunctionalDog | I realized I never used the coll in the inner function |
| 12:09 | FunctionalDog | so I'm rethinking |
| 12:09 | justin_smith | either you want to use partial, in which case you don't have nested functions any more, or you need a loop inside the fn and it doesn't take the collection arg |
| 12:10 | justin_smith | but it's a couple small changes from being either of those things that would work :) |
| 12:10 | FunctionalDog | I haven't quite wrapped my head around everything the program is supposed to do here |
| 12:11 | justin_smith | big picture, what both versions do is walk the collection, returning false if any element is larger than e, or returning true if any element is equal to e |
| 12:12 | FunctionalDog | in terms of golfing, using a loop is probably faster than writing partial twice |
| 12:12 | justin_smith | no, partial would only be there once |
| 12:12 | justin_smith | partial would be at the call site, in the arg to remove |
| 12:12 | FunctionalDog | oh, I thought your example had 2. maybe I misread |
| 12:13 | justin_smith | (defn find-match [[x & xs] ele] (cond (> x ele) false (= x ele) true (recur xs ele)) then you would pass (partial find-matches coll) in the remove ;; <- quoting me - of course I left the :else out of that cond |
| 12:14 | justin_smith | but for code golf I would use 1 instead of :lse |
| 12:14 | justin_smith | does the same thing |
| 12:14 | FunctionalDog | use 1? |
| 12:14 | justin_smith | ,(cond nil :a false :b 1 :OK) |
| 12:14 | clojurebot | :OK |
| 12:15 | justin_smith | :else is just a convention |
| 12:15 | justin_smith | and 1 is shorter |
| 12:17 | justin_smith | to put it another way: a single digit number is the smallest truthy thing I can think of to replace :else with |
| 12:18 | FunctionalDog | ohh, okay. you just mean, anything to fill in the conditional spot |
| 12:18 | justin_smith | right |
| 12:18 | justin_smith | but whatever, feel free to use :else first, golfing can come later |
| 12:21 | FunctionalDog | I have this now, but it still seems to be hanging on iterator=26 http://pastebin.com/AMvTHQG7 |
| 12:21 | FunctionalDog | oh wait, I still have concat going on |
| 12:21 | FunctionalDog | I forgot what I was even doing |
| 12:22 | justin_smith | I don't think the concat is an issue here |
| 12:22 | justin_smith | one thing - define findMatches before lucky |
| 12:23 | justin_smith | because on the first pass through the file the compiler will fail otherwise |
| 12:23 | FunctionalDog | i'm using light table's instarepl |
| 12:23 | justin_smith | OK, I'm talking about what will happen if this code is in a namespace |
| 12:25 | FunctionalDog | http://i.imgur.com/GlWzBaM.png |
| 12:25 | justin_smith | yeah, findMatches still isn't getting called |
| 12:26 | FunctionalDog | how are you sure? |
| 12:26 | justin_smith | I added a print statement to it |
| 12:26 | FunctionalDog | ah |
| 12:28 | justin_smith | so I think it is time for our lazy version! |
| 12:28 | FunctionalDog | yeah, same result. so we need to do something differently |
| 12:29 | FunctionalDog | does that mean that .contains wasn't the issue after all? |
| 12:29 | FunctionalDog | if so, it was much more compact so I should use it |
| 12:29 | justin_smith | no, contains would definitely have had that problem |
| 12:29 | FunctionalDog | ah okay |
| 12:29 | justin_smith | but we can double check later if you really want to see that for yourself |
| 12:29 | justin_smith | let's get a version that works first |
| 12:30 | FunctionalDog | what do you think is the problem, then? |
| 12:30 | FunctionalDog | or... the second problem |
| 12:32 | justin_smith | checking that out now, doing a translation to a lazy version - if nothing else that might expose the issue |
| 12:33 | FunctionalDog | alright. thanks for your help so far, also |
| 12:33 | FunctionalDog | I would have given up permanently if not for you :p |
| 12:40 | FunctionalDog | brb, laundry |
| 12:47 | FunctionalDog | back |
| 12:48 | justin_smith | FunctionalDog: my sloppy lazy version https://www.refheap.com/97681 - find-matches runs now |
| 12:48 | justin_smith | it is running on values it shouldn't be! |
| 12:48 | justin_smith | but it is running |
| 12:49 | justin_smith | FunctionalDog: the trick was the doall on the take |
| 12:49 | justin_smith | that reduces the stack accumulation |
| 12:49 | justin_smith | (when the whole nest of laziness is finally forced) |
| 12:49 | justin_smith | there are folks here that are better with lazy-seqs than I am who may be able to point out what I am still doing wrong there |
| 12:50 | FunctionalDog | hm, alright |
| 12:50 | Glenjamin | you probably need lazy-seq in there somewhere to avoid blowing the stack? |
| 12:50 | justin_smith | FunctionalDog: the one tricky thing is that I put println calls inside the concat |
| 12:50 | justin_smith | Glenjamin: concat is lazy |
| 12:50 | justin_smith | the issue is the stack usage once the laziness is forced |
| 12:51 | justin_smith | concat-bomb I guess |
| 12:51 | Glenjamin | oh, i see |
| 12:51 | justin_smith | or would lazy-seq help fix that? |
| 12:51 | Glenjamin | i think so? |
| 12:51 | Glenjamin | not really sure |
| 12:51 | justin_smith | or maybe lazy-cat |
| 12:51 | justin_smith | (doc lazy-cat) |
| 12:51 | clojurebot | "([& colls]); Expands to code which yields a lazy sequence of the concatenation of the supplied colls. Each coll expr is not evaluated until it is needed. (lazy-cat xs ys zs) === (concat (lazy-seq xs) (lazy-seq ys) (lazy-seq zs))" |
| 12:52 | Glenjamin | sounds like the right sort of thing |
| 12:52 | justin_smith | I should really write a hyper-dog function |
| 12:52 | justin_smith | for balance and all |
| 12:53 | FunctionalDog | definitely don't search google for 'hyper dog' |
| 12:53 | justin_smith | haha |
| 12:53 | justin_smith | why, the results are too amusing? |
| 12:53 | FunctionalDog | oh okay, I was expecting worse. furry stuff. |
| 12:53 | FunctionalDog | pretty tame actually |
| 12:54 | justin_smith | ok, same issue with lazy-cat |
| 12:54 | justin_smith | I don't get why find-matches is getting called with such large arguments |
| 12:55 | Glenjamin | you're calling lucky inside lucky |
| 12:55 | justin_smith | sure, but it's inside a lazy-cat |
| 12:55 | Glenjamin | oh right, i'm still looking at the old one |
| 12:55 | justin_smith | so the thunk keeps it from being eager I would think |
| 12:55 | justin_smith | the new version is just s/concat/lazy-cat |
| 12:56 | justin_smith | hrm... |
| 12:57 | FunctionalDog | It's okay if it's too much of a headache. I don't need to be able to do this for any actually good reason :p |
| 12:57 | justin_smith | now it's more like "I thought I knew clojure better than this, why the hell is this not working..." |
| 12:57 | justin_smith | so it's as much for my own edification as yours :) |
| 12:57 | FunctionalDog | therein lies the challenge of the golf prompt, I guess :p |
| 12:58 | justin_smith | it' |
| 12:58 | justin_smith | s not even golf yet |
| 12:58 | justin_smith | I'd settle for correct |
| 12:58 | FunctionalDog | of course it's impossible to even win codegolf anymore unless you know those stupidly compact languages made specifically for it |
| 12:58 | FunctionalDog | like Pyth |
| 12:59 | FunctionalDog | not that winning is the main reason anyone plays. that would be silly. |
| 12:59 | FunctionalDog | if you want a REAL challenge, I think this program could be written in Chef |
| 13:00 | justin_smith | I'd settle for a working clojure version |
| 13:00 | ystael | FunctionalDog: http://www.jsoftware.com/help/dictionary/vocabul.htm except these people are serious |
| 13:00 | justin_smith | ystael: there's also golfscript |
| 13:01 | FunctionalDog | I wrote a chef program once. never again. https://github.com/culmor30/chef-moon-pie/blob/master/moon-pie-commented.chef |
| 13:01 | justin_smith | http://www.golfscript.com/golfscript/ |
| 13:02 | ystael | FunctionalDog: ha, i thought you meant chef the infrastructure management tool |
| 13:03 | FunctionalDog | heh, no. The chef I meant is the opposite of usable or efficient. You can't even do float math |
| 13:04 | dah | hmm, sounds like the infra tool except the float math part |
| 13:04 | ystael | one could also argue that the chef i was thinking of is the opposite of usable or efficient :p ... but that's off topic and perhaps my experiences have just been bad |
| 13:04 | dah | haha |
| 13:08 | justin_smith | FunctionalDog: so looking at the output of find-matches, it's doing a lot of comparisons it really shouldn't need to do |
| 13:08 | FunctionalDog | Yeah, I let it run for a while and it started getting pretty crazy |
| 13:09 | FunctionalDog | especially since there are only 2 lucky numbers when n=5... 1 and 3 |
| 13:09 | alexyakushev | Does anyone know how can one "unmerge" some dependency in Leiningen in a certain profile? |
| 13:09 | justin_smith | in that case, the whole (take i ...) thing is way wrong |
| 13:09 | justin_smith | it's more like (take-while (< i x)) |
| 13:10 | FunctionalDog | why's that? |
| 13:10 | justin_smith | FunctionalDog: because (take n coll) returns n elements |
| 13:10 | justin_smith | and i is monotonically increasing |
| 13:11 | FunctionalDog | oh yeah... |
| 13:12 | FunctionalDog | but what's x? |
| 13:13 | justin_smith | (take-while #(< i %) coll) |
| 13:13 | justin_smith | or something like that |
| 13:13 | justin_smith | and the drop should similarly be a drop-while... |
| 13:13 | justin_smith | if I am thinking about this clearly |
| 13:13 | FunctionalDog | This stuff is way over my head for having no experience :p |
| 13:14 | justin_smith | yeah |
| 13:14 | FunctionalDog | Maybe I could write it in java. but not this. |
| 13:15 | FunctionalDog | may be time for me to give up on this challenge. but I wish you the best in conquering it, haha |
| 13:15 | FunctionalDog | the best of luck, rather |
| 13:16 | justin_smith | FunctionalDog: I just had an aha momemt - since we want results less than n, we can replace (next (range)) with (range 1 n) |
| 13:16 | justin_smith | that eliminates the silly looping, now working on correct output... |
| 13:16 | FunctionalDog | you can't though |
| 13:16 | justin_smith | why not? |
| 13:16 | FunctionalDog | you need to start with all real numbers 1 through (n*n)+1 |
| 13:17 | justin_smith | ahh |
| 13:17 | justin_smith | so it isn't up to n |
| 13:17 | justin_smith | it is up to limit |
| 13:17 | justin_smith | easy enough! |
| 13:17 | FunctionalDog | the goal is to produce n lucky numbers, but that requires going further than n in real numbers |
| 13:17 | FunctionalDog | *the first n lucky numbers |
| 13:22 | justin_smith | FunctionalDog: another potential problem: in the first iteration, it appears we are eliminating all multiples of 1 |
| 13:22 | justin_smith | FunctionalDog: this means it won't find anything |
| 13:22 | AimHere | Someone doing Eratosthenes with 1 as a prime? |
| 13:22 | justin_smith | AimHere: not quite, it's a very similar algo though |
| 13:23 | justin_smith | AimHere: there's still no excuse that I didn't catch that immediately... |
| 13:24 | justin_smith | FunctionalDog: basically that (remove ...) returns an empty list because every input is a multiple of 1 |
| 13:25 | FunctionalDog | ah, there's another thing I used to have logic for, but deleted in a refactoring frenzy at 4am |
| 13:25 | justin_smith | haha |
| 13:25 | justin_smith | I'm going to have to step away from this, I must pay rent and have paying work to do :P |
| 13:25 | justin_smith | but I'll check in later |
| 13:25 | FunctionalDog | I think I'll work my way through 4clojure stuff instead. That's at least realistic. |
| 13:25 | FunctionalDog | alright, well it was fun at least. |
| 13:26 | FunctionalDog | Hopefully I'll also have paying work soon, haha |
| 13:26 | FunctionalDog | (graduated not too long ago) |
| 13:28 | FunctionalDog | I'm sure I'll be back with questions from 4clojure later. Gonna slack off for a while though. |
| 13:34 | TimMc | Has anyone used as-> with nontrivial binding forms? And not just to demonstrate that it's weird, but actually for practical purposes. |
| 13:34 | TimMc | ,(as-> "hi" [x] (list \a x) (list \b x) (list \c x)) |
| 13:34 | clojurebot | [\c] |
| 13:35 | justin_smith | OK, that is weird |
| 13:40 | pppppaul | what do you guys think of wish? |
| 13:41 | pppppaul | https://github.com/Gozala/wisp |
| 13:41 | pppppaul | wisp, sorry |
| 13:44 | SegFaultAX | pppppaul: I don't understand the reason for it to exist, even after reading the intro paragraph. |
| 13:48 | dah | wow gorilla is really nice |
| 13:49 | pppppaul | wisp has no clojure runtime needed for compiling, right? |
| 13:50 | pppppaul | if this is true, then one can compile to JS on a web browser... |
| 13:50 | justin_smith | pppppaul: do you mean it is a self hosting compiler that targets js? |
| 13:50 | pppppaul | i think so |
| 13:51 | justin_smith | pppppaul: a big difference is that cljs has clojure semantics, and it seems this only offers clojure syntax |
| 13:51 | pppppaul | seems like a reimplementation of CLJS |
| 13:52 | justin_smith | not really, because it lacks persistent data structures |
| 13:52 | noonian | right |
| 13:52 | noonian | its more like coffeescript imo but as a lisp so you get lispy benefits |
| 13:52 | dnolen | Wisp is really nowhere even close to being a reimplementation of CLJS. Give it 3 more years ... maybe. |
| 13:54 | pppppaul | after reading through the github page i did feel that is was reminding me of coffee script as well |
| 13:54 | pppppaul | just trying to have the same syntax as clojure, but not use the data structures of clojure |
| 13:55 | noncom | hi! |
| 13:55 | vas_ | Ello noncom |
| 13:55 | noncom | i am running "lein clean" in my project, and get this error: https://www.refheap.com/97682 |
| 13:55 | noncom | does anyone have any idea? |
| 13:55 | noncom | what that means |
| 13:55 | dah | weird. wisp sounds like pyrex or coffeescript or something |
| 13:57 | noonian | noncom: hard to tell from that stacktrace but if I had to guess your project might have non-standard directory structure (like file paths not corresponding to namespaces) since its dying in leiningen sanity_check and protected_paths functions. |
| 13:58 | noncom | noonian: what's strange is that it worked a day ago.. and i did not change anything except for reimporting all my projects into eclipse luna from eclipse kepler.. and reinterlinking them (having 3 linked projects) |
| 13:59 | SegFaultAX | pppppaul: That seems like going in the opposite direction of where you'd want to be. |
| 13:59 | SegFaultAX | If anything, I'd give up Lisp syntax but maintain immutable data structures. |
| 13:59 | noncom | this error comes up even in the bottom line project that is not linked to the other 2. (the other two are linked to it).. |
| 13:59 | noonian | noncom: what do you mean inter-linking? I wouldn't be suprised if eclipse stuck some files somewhere for bookkeeping and that is what is tripping lein up |
| 14:00 | noonian | SegFaultAX: well, when you start with JS you don't have the data structures or the syntax and if you need something self hosted or that compiles to readable JS then cljs is currently out |
| 14:00 | noncom | noonian: yeah, probably.. eclipse (and ofcourse, ccw) have a notion of "dependant projects" - while you can make other projects internals visible from another project... like a source dependancy |
| 14:01 | noncom | ok, will look into more what happens there with eclipse and stuff, i guess... |
| 14:02 | noonian | does lein work well with symlinks? not much experience with that myself |
| 14:02 | SegFaultAX | noonian: I'm saying I care about CLJ[S] semantics a whole hell of a lot more than I care about the syntax. |
| 14:03 | SegFaultAX | And adding mori.js or similar to the mix at least gives me a part of that. |
| 14:03 | noncom | noonian: yeah, having symlinks in the checkout dir too - you know, that leiningens method of depending on another project - putting a symlink for it in the "checkouts" directory.. |
| 14:03 | noonian | SegFaultAX: Yeah I agree the data structures are one of my favorite aspects of Clojure |
| 14:03 | SegFaultAX | noonian: So I don't really get the point of wisp if it only has the syntax part. |
| 14:04 | SegFaultAX | If it was syntax + mori, that might be cool. |
| 14:04 | noncom | yeah, i am fond of clojure datastructs too. miss them so much when have to work with other languages.. |
| 14:04 | noncom | what is wisp anyway? |
| 14:04 | noonian | I'm sure you could use it with mori but from the readme the literal map syntax compiles to java objects |
| 14:05 | SegFaultAX | noonian: Right. |
| 14:05 | noncom | dound it: https://github.com/Gozala/wisp |
| 14:05 | noncom | *found |
| 14:05 | noonian | but if you're going to use it with mori might as well use cljs :P |
| 14:12 | pppppaul | maybe it's easy to add mori to wisp |
| 14:12 | pppppaul | i haven't looked into it |
| 14:21 | SegFaultAX | pppppaul: I mean it should be as simple as including another library, right? |
| 14:22 | pppppaul | syntax may be a problem |
| 14:23 | pppppaul | would need to have the compiler know about mori, i guess |
| 14:23 | pppppaul | the collection functions depend on seqs, i don't know what wisp wants, and mori doesn't make seqs |
| 14:33 | TimMc | Is there a tool for discovering unused :import, :use, and :require forms? |
| 14:38 | Bronsa | TimMc: eastwood has an unused-namespaces linter |
| 14:39 | Bronsa | TimMc: also I believe cursive can do that but I'll let cfleming confirm that |
| 14:41 | sveri | TimMc: cursive supports this now too for most forms |
| 14:41 | TimMc | Bronsa: Hmm, I don't remember that being on the eastwood feature list. |
| 14:44 | TimMc | Aha, it is disabled by default. |
| 14:46 | Razzeeyy | Hi all, is there a way to trap a value returned by a function so it won't be displayed back in a REPL? |
| 14:46 | Razzeeyy | doing (time BIG_ARRAY) and getting annoyed by automatic printing of that array by REPL :( |
| 14:47 | TimMc | (do ... nil) |
| 14:47 | amalloy | although if the thing you're timing the printing of is a lazy seq, TimMc's fix may create some other exciting issues |
| 14:47 | TimMc | although remember that if your return valueis a lazy seq and you want it to get realized, you'll need to throw a dorun inside the time expr. |
| 14:48 | Razzeeyy | TimMc: thanks! |
| 14:49 | Razzeeyy | TimMc: yeah I'm fine with lazies, just looking at whether sorting it first and then taking max will bring me a speed boost vs just taking max right away |
| 14:49 | TimMc | ,(time (do (range) nil)) ;; wow! |
| 14:49 | clojurebot | "Elapsed time: 0.047078 msecs"\n |
| 14:49 | TimMc | Razzeeyy: You'll want to use criterium, by the way. |
| 14:50 | Razzeeyy | dunno why I bother with that tho, solving projecteuler in clojure |
| 14:50 | TimMc | clojure.core/time isn't great for perf tests |
| 14:50 | Razzeeyy | but speed freak is living inside of me xD |
| 14:50 | Razzeeyy | TimMc: criterium is some profiling lib I guess? |
| 14:50 | TimMc | ~benchmark |
| 14:50 | clojurebot | criterium or gtfo |
| 14:50 | TimMc | haha |
| 14:50 | TimMc | Correct, but not helpful. |
| 14:50 | TimMc | ~benchmark |
| 14:50 | clojurebot | criterium or gtfo |
| 14:51 | TEttinger | heh |
| 14:51 | TEttinger | $google clojure criterium benchmark |
| 14:51 | lazybot | [hugoduncan/criterium · GitHub] https://github.com/hugoduncan/criterium |
| 14:51 | TimMc | clojurebot, forget benchmark |is| criterium or gtfo |
| 14:51 | clojurebot | I forgot that benchmark is criterium or gtfo |
| 14:52 | TimMc | clojurebot, benchmark is <reply>criterium or gtfo https://github.com/hugoduncan/criterium |
| 14:52 | clojurebot | You don't have to tell me twice. |
| 14:52 | Razzeeyy | hm is (max) a lazy function? :o |
| 14:52 | TimMc | clojurebot, forget benchmark |is| <reply>criterium or gtfo |
| 14:52 | clojurebot | I forgot that benchmark is <reply>criterium or gtfo |
| 14:52 | amalloy | Razzeeyy: kinda |
| 14:52 | amalloy | well actually no |
| 14:52 | TimMc | my eyebrows went up |
| 14:53 | TimMc | Razzeeyy: max can't compute lazily, since there could always be a higher value it hasn't seen yet |
| 14:54 | TimMc | And since it returns a plain number, not a seq, it can't defer part of the computation. |
| 14:54 | amalloy | TimMc: i mean, it consumes its arglist lazily, which is what i was thinking of. like, (apply max (range)) doesn't use up all memory. but that's a pretty silly definition of lazy, since it never returns either |
| 14:54 | TimMc | (I am at least 25% sure I did not just repeat myself.) |
| 14:55 | TimMc | dorun isn't lazy either :-P |
| 15:02 | Razzeeyy | let me try it :D |
| 15:02 | Razzeeyy | ,(do (time (sort (for [a (range 100 1000) b (range 100 1000)] (* a b)))) nil) |
| 15:02 | clojurebot | eval service is offline |
| 15:02 | Razzeeyy | hope the bot won't shot me for long run time |
| 15:02 | Razzeeyy | err |
| 15:03 | Razzeeyy | ,(do (time (sort (for [a (range 100) b (range 100)] (* a b)))) nil) |
| 15:03 | clojurebot | "Elapsed time: 297.143697 msecs"\n |
| 15:03 | AeroNotix | ,123 |
| 15:03 | clojurebot | 123 |
| 15:04 | hiredman | ~clojurebot |
| 15:04 | Razzeeyy | ,(do (time (max (for [a (range 100) b (range 100)] (* a b)))) nil) |
| 15:04 | clojurebot | "Elapsed time: 0.2984 msecs"\n |
| 15:04 | clojurebot | clojurebot will become skynet |
| 15:04 | hiredman | ~clojurebot |
| 15:04 | clojurebot | clojurebot exploits differences in network latency to appear to violate causality |
| 15:04 | hiredman | ~clojurebot |
| 15:04 | clojurebot | clojurebot is everyone else |
| 15:04 | Razzeeyy | TimMc: the max isn't run in the example above, right? |
| 15:05 | amalloy | hiredman: is clojurebot not a benchmarking platform? |
| 15:05 | hiredman | amalloy: I think so |
| 15:06 | amalloy | from context Razzeeyy isn't actually trying to time this specific thing, but experimenting with the idea of (do (time (f)) nil) to get timing info without printing the resulting expression |
| 15:12 | Razzeeyy | amalloy: I'm experimenting with (sort) and (max) |
| 15:12 | Razzeeyy | looks like that (max) won't evaluate untill value is requested or something so makes it lazy or something |
| 15:12 | Razzeeyy | or.... |
| 15:12 | Razzeeyy | sort takes to many operations in comparison to just (max) |
| 15:12 | hiredman | ,(doc max) |
| 15:12 | clojurebot | "([x] [x y] [x y & more]); Returns the greatest of the nums." |
| 15:13 | hiredman | ,(max 1) |
| 15:13 | clojurebot | 1 |
| 15:13 | SegFaultAX | The variadic form just reduces over the collection |
| 15:13 | hiredman | ,(max [1 2]) |
| 15:13 | clojurebot | [1 2] |
| 15:13 | hiredman | ,(apply max [1 2]) |
| 15:13 | clojurebot | 2 |
| 15:14 | SegFaultAX | Razzeeyy: Reduce is strict. |
| 15:17 | Razzeeyy | hiredman: yeah figured it out it just returns the seq itself :c |
| 15:17 | Razzeeyy | and thx |
| 15:17 | Razzeeyy | ,(do (time (apply max (for [a (range 100) b (range 100)] (* a b)))) nil) |
| 15:17 | clojurebot | "Elapsed time: 199.517518 msecs"\n |
| 15:18 | Razzeeyy | ,(do (time (sort (for [a (range 100) b (range 100)] (* a b)))) nil) |
| 15:18 | clojurebot | "Elapsed time: 193.319982 msecs"\n |
| 15:18 | Razzeeyy | hm |
| 15:18 | Razzeeyy | sorting seems faster :o |
| 15:18 | Razzeeyy | and what if I sort then max... |
| 15:18 | Razzeeyy | ,(do (time (apply max (sort (for [a (range 100) b (range 100)] (* a b))))) nil) |
| 15:18 | clojurebot | "Elapsed time: 104.481787 msecs"\n |
| 15:18 | Razzeeyy | WHAT |
| 15:18 | Razzeeyy | how come it being so faster :o |
| 15:19 | amalloy | Razzeeyy: clojurebot is not a benchmarking platform, and neither is (time) |
| 15:19 | amalloy | they are both very rough estimates |
| 15:19 | SegFaultAX | ,(let [n (dorun (for [a (range 100) b (range 100)] (* a b)))] (time (max n))) |
| 15:19 | clojurebot | "Elapsed time: 0.013101 msecs"\n |
| 15:20 | SegFaultAX | ,(let [n (dorun (for [a (range 100) b (range 100)] (* a b)))] (time (sort n))) |
| 15:20 | clojurebot | "Elapsed time: 0.020855 msecs"\n() |
| 15:20 | SegFaultAX | ,(let [n (dorun (for [a (range 100) b (range 100)] (* a b)))] (time (apply max n))) |
| 15:20 | clojurebot | #<ArityException clojure.lang.ArityException: Wrong number of args (0) passed to: core/max> |
| 15:20 | ztellman | amalloy: add criterium to clojurebot plz |
| 15:20 | SegFaultAX | :) |
| 15:21 | SegFaultAX | ,(let [n (doall (for [a (range 100) b (range 100)] (* a b)))] (time (apply max n))) |
| 15:21 | clojurebot | "Elapsed time: 4.397644 msecs"\n9801 |
| 15:21 | SegFaultAX | ,(let [n (doall (for [a (range 100) b (range 100)] (* a b)))] (time (sort n))) |
| 15:21 | clojurebot | "Elapsed time: 1.942586 msecs"\n(0 0 0 0 0 ...) |
| 15:21 | Razzeeyy | amalloy: oh you meant that by "not a benchmarking platform" I thought you was discouraging me from spamming time in a public chat :) |
| 15:21 | SegFaultAX | Razzeeyy: Well that, and the results you're going to get from clojurebot are going to vary wildly |
| 15:22 | SegFaultAX | You need to run it on a controlled platform many many time with a tool like criterium for precision measurement. |
| 15:22 | SegFaultAX | Clojurebot is none of those things. |
| 15:22 | amalloy | Razzeeyy: you can also /msg clojurebot if you're going to be noisy |
| 15:22 | amalloy | but i was indeed saying you will not get good results |
| 15:23 | Razzeeyy | SegFaultAX: will I get somewhat better results if ran time on a larger collections? |
| 15:23 | SegFaultAX | Razzeeyy: I don't think I said that. |
| 15:24 | TimMc | Razzeeyy: Add criterium to a project, open a REPL, and use it to conduct your experiments. |
| 15:26 | SegFaultAX | Razzeeyy: But if you're trying to gain some intuition about the asymptotic performance of your process, that might help. |
| 15:27 | Razzeeyy | k thx :3 |
| 16:17 | Razzeeyy | any built in opposite of (some)? or I guess the best way to go is (not (some))? |
| 16:19 | Razzeeyy | hm (not-any?) looks like the opposite of (some) am I right? :) |
| 16:20 | SegFaultAX | Razzeeyy: Kinda. some is not a predicate. |
| 16:33 | Razzeeyy | btw here is the thing I can't figure out how to do I need something like (range 1 +infitiy) but can't find a way to indicate that to range :O |
| 16:33 | amalloy | (rest (range)) |
| 16:34 | amalloy | also (range 1 Double/POSITIVE_INFINITY) but that's kinda silly |
| 16:34 | Razzeeyy | amalloy: oh yeah thanks |
| 16:35 | Razzeeyy | also found a solution like (drop 1 (range)) |
| 16:35 | Razzeeyy | but you solution with (rest) is most beautiful |
| 16:37 | Razzeeyy | oh man I love clojure |
| 16:37 | Razzeeyy | even tho coding is uncomfortable in the beginning but the final code looks so neat |
| 16:37 | Razzeeyy | like a story in the book |
| 16:41 | erik`` | given something like |
| 16:41 | slipset | ,(def l '(+ 1 2)) |
| 16:41 | clojurebot | #'sandbox/l |
| 16:42 | slipset | how do I evaluate l as a function? |
| 16:42 | slipset | There should obviously be someting obvious I'm missing... |
| 16:42 | amalloy | slipset: don't do that |
| 16:43 | slipset | amalloy: I promise, I won't :( |
| 16:43 | justin_smith | slipset: you can evaluate it as a list |
| 16:43 | slipset | but please, do tell me anyhow |
| 16:43 | justin_smith | but it doesn't take arguments |
| 16:43 | amalloy | i mean, anytime you def a source-code form and then later plan to eval it, there is something better you should be doing instead |
| 16:43 | justin_smith | yeah, exactly |
| 16:45 | slipset | amalloy: justin_smith: I'm sure you're both right, and right now I'm just playing around with some stuff which is far away from production. I guess I could eval it... |
| 16:45 | slipset | How does clojurebot do this? |
| 16:46 | justin_smith | slipset: the same way the repl does, eval |
| 16:46 | justin_smith | but why not just use #(+ 1 2) instead of '(+ 1 2) |
| 16:46 | justin_smith | assuming your actual list is something more interesting than + of course |
| 16:46 | clojurebot | In Ordnung |
| 16:46 | slipset | justin_smith: why not indeed :) |
| 16:46 | slipset | You just asked the correct question, thanks! |
| 16:47 | justin_smith | eg. I could see doing that if you had #(get-state place) - and you would call that to get an updated state |
| 17:01 | kgarrison343 | hello |
| 17:09 | AeroNotix | kgarrison343: hi |
| 17:17 | crazydiamond | Hi. How to read JSON file form Clojure? |
| 17:19 | AeroNotix | crazydiamond: (-> "path/to/file/" slurp clojure.data.json/read-str) |
| 17:20 | AeroNotix | you will need to have clojure.data.json as a dependency |
| 17:20 | AeroNotix | https://github.com/clojure/data.json/ |
| 17:20 | crazydiamond | AeroNotix, thanks, but what to add to project.clj ? |
| 17:20 | AeroNotix | look in the link I sent you |
| 17:20 | crazydiamond | I see now, thanks! |
| 17:20 | AeroNotix | nw |
| 17:23 | Razzeeyy | amalloy: and still bullying around with (range) how to make an infinite range but with a step? :D |
| 17:25 | amalloy | i'd probably use (range 1 n Double/POSITIVE_INFINITY), but you can do it with like take-nth if you prefer the elegance of that. ##(take 5 (take-nth 2 (rest (range)))) |
| 17:25 | lazybot | ⇒ (1 3 5 7 9) |
| 17:29 | TimMc | amalloy: Infinite step? :-) |
| 17:29 | amalloy | TimMc: i can never remember whether step comes before or after end |
| 17:29 | amalloy | i just guess at random and hope for the best, which must be a more efficient solution than reading the docstring |
| 17:29 | TimMc | The optional end, start, and step params (in that order!) mess with me too. |
| 17:30 | amalloy | TimMc: wait what? start comes before end |
| 17:31 | dnolen | cfleming: ping |
| 17:32 | TimMc | amalloy: I meant that the second parameter is the least optional. |
| 17:42 | Razzeeyy | amalloy: wow take-nth is cool thx |
| 17:42 | Razzeeyy | and sleeptime for me, bye all! :) |
| 18:09 | bloop_ | context: I've played with clojure but not used it professionally before now. I've developed db servers but never set one up on my own before. Using sqlingvo. |
| 18:10 | bloop_ | anyone know of any step by step tutorials on getting a db on disc and adding tables and whatnot to it using sligvo/postgresql? |
| 18:10 | dah | bloop_: there's also honeysql |
| 18:11 | bloop_ | dah: yeah I looked at both. they seemed very similar. is there a reason to prefer one or the other? |
| 18:11 | dah | bloop_: looks like that's only for queries though |
| 18:12 | dah | bloop_: honeysql seems to have a map format which could be nicer for composition |
| 18:13 | bloop_ | dah: oh, I could see that |
| 18:15 | dah | bloop_: i haven't used an sql db with clojure much -- been using datomic instead |
| 18:16 | dah | bloop_: if that's an option for you i recommend it highly =) |
| 18:16 | dah | bloop_: it can use postgres as a backend, which is what i've been doing |
| 18:18 | om | bloop_: if you're not after some fancy object relational mapping, check yesql |
| 18:20 | dah | ah yesql looks nice |
| 18:20 | om | bloop_: I've been using it very successfully with java.jdbc |
| 18:21 | om | very easy to maintain the code dealing with the db |
| 18:21 | dah | still no help for schema management, but otherwise nice |
| 18:22 | om | dah: it's bare bone sql |
| 18:23 | om | pretty good if you want separation of concerns (which was my case :)) |
| 18:24 | Lewix | where could I learn more about servers. load balancers etc...I would like to improve my knowledge in that area but there' isn't a structured resource out there |
| 18:24 | Lewix | like a book about servers, devops tools etc |
| 18:28 | bloop_ | om: yesql struck me as annoying. I don't see having a homoiconic DSL on top of SQL to be the same thing as ORM anyway. |
| 18:29 | bloop_ | om: wouldn't ORM be if you had hash maps that represented rows that you could mutate to create mutations in the DB? That seems actually impossible with Clojure :p |
| 18:29 | bloop_ | om: at least not idiomatic clojure / not the clojure way |
| 18:30 | om | bloop_: in my case the dsl was getting in my way... I used honeysql for the ORM-like features a little but hadn't any use case for it |
| 18:31 | om | bloop_: for the rest I have been pretty happy with managing the sql separetly from the rest of the code |
| 18:32 | SegFaultAX | bloop_: Yesql is awesome. |
| 18:33 | SegFaultAX | bloop_: What strikes you as annoying? |
| 18:33 | om | bloop_: I like the separation of concerns whe dealing with SQL databases but yes, your mileage may vary |
| 18:34 | hiredman | docs on yesql seem pretty lacking, regarding keyword arguments and the like, and docs about passing arguments to the underlying clojure.java.jdbc functions |
| 18:34 | om | bloop_: I don't really need s-expressions to mimic SQL |
| 18:34 | hiredman | (I say this because I happen to be looking for those docs) |
| 18:35 | om | hiredman: yesql is just string parsing |
| 18:35 | om | I had a couple of functions doing basically the same thing when the library came out |
| 18:35 | hiredman | om: I was more responding to "Yesql is awesome" |
| 18:36 | hiredman | it is ok, I guess? we just sort of started using it at work and I am already finding it something of a hinderance |
| 18:37 | tbaldridge | (any library on top of SQL will be a hinderence) |
| 18:37 | tbaldridge | so the less the better |
| 18:37 | hiredman | https://github.com/krisajenkins/yesql/blob/master/src/yesql/core.clj#L27 this is just terrible |
| 18:37 | hiredman | ~@ in to a vector, then calling doall on the vector? |
| 18:37 | clojurebot | excusez-moi |
| 18:39 | bloop_ | I think the thing that strikes me as annoying with yesql is being separated from me precious clojure and the fear that I'd be doing string manipulation to describe patterns. That might be ignorant of me though, please correct. |
| 18:39 | hyPiRion | hiredman: `(do ~@(map emit-def queries)) does the same thing, is that the problem you got with it? |
| 18:39 | hiredman | I have been reconbobulating some of our queries to return reducers that do the query when reduced to avoid both pulling everything in to memory (as query does by default) and avoid dynamic scoping |
| 18:39 | amalloy | hyPiRion: well, the same thing except it returns something different. not clear whether that matters |
| 18:40 | tbaldridge | (inc hiredman) |
| 18:40 | lazybot | ⇒ 71 |
| 18:40 | hiredman | you can do it with clojure.java.jdbc's query function, but I am not sure you can with yesql |
| 18:40 | hiredman | hyPiRion: basically |
| 18:40 | hiredman | hyPiRion: the really annoying thing is eastwood sees a vector not being used and warns about it |
| 18:42 | hiredman | even in that formulation, the doall does nothing |
| 18:43 | hyPiRion | Well. I guess the library isn't *that* bad if that's one of your problems with it. :p |
| 18:44 | hiredman | I am trying to avoid reading the code |
| 18:45 | m1dnight_ | guys, I'm trying to use postgresql but i'm having issues with connecting. I have tried pgadmin and I can't supply as pass or it fails. |
| 18:45 | hiredman | blackboxes are precious, I don't have enough of them |
| 18:45 | m1dnight_ | how do I define this in clojure? |
| 18:45 | m1dnight_ | I tried ":password """, or ":password <linux pass>" or remove it from the map, nothing works |
| 18:47 | m1dnight_ | https://www.refheap.com/97690 |
| 18:47 | m1dnight_ | this is what i'm trying |
| 18:48 | bloop_ | btw are there any open source projects inspired by datomic? |
| 18:49 | bloop_ | it seems like rich's lunch could get eaten if enough nerds put their minds to it |
| 18:49 | AeroNotix | bloop_: I think the problem is that no-one really knows what datomic does |
| 18:50 | AeroNotix | At first glance and the very few resources about it, it's quite enigmatic about what problem it solves. |
| 18:53 | m1dnight_ | I solved my problem by simply putting a pass on my postgresql account :> |
| 19:04 | jwm | bloop_: eventstore |
| 19:05 | jwm | immutable data store.. the concept behind datomic is great and needs to be behind every db honestly |
| 19:06 | jwm | though revision control and data has been around for decades |
| 19:06 | jwm | storage is just catching up to provide it |
| 19:10 | bloop_ | jwm: right. the way I describe it to people is "you know how useful the log is? what if the DB *was* the log?" |
| 19:10 | cddr | What's the max size for very-big-collection in `(apply foo very-big-collection)`? |
| 19:11 | amalloy | cddr: how much ram do you have? |
| 19:11 | amalloy | (it's more than that) |
| 19:11 | cddr | how is it more? |
| 19:11 | amalloy | laziness |
| 19:12 | amalloy | consider, eg, (defn f [& args] (count args)) |
| 19:12 | amalloy | (apply f (range)) will run forever, consuming no memory |
| 19:12 | cddr | orly |
| 19:13 | bloop_ | yep, and (first (range)) is 0, no infinite memory required :) |
| 19:14 | TEttinger | ,(apply max (repeat 10000000 100)) |
| 19:14 | clojurebot | 100 |
| 19:15 | cddr | So there would be no point in writing a manual equivalent of `(apply merge-with + ...)` that looped over the ... and summed the values itself? |
| 19:16 | amalloy | cddr: indeed i can't imagine why you would do that. if you did, the implementation would just be (reduce (partial merge-with +) {} xs) |
| 20:15 | om | what is the best practice when catching exceptions and ensuring a value is always returned? simply returning nil? wrapping the return value and exception in a maybe-like thing? |
| 20:21 | dnolen | http://swannodette.github.io/2015/02/23/hello-google-closure-modules/ |
| 20:22 | nuwanda_ | dnolen: you have a link on that blog post to http://localhost:4000/2015/01/06/the-false-promise-of-javascript-microlibs/ |
| 20:23 | dnolen | nuwanda_: thanks |
| 20:53 | amalloy | ,(nth (java.util.ArrayList. (range 5)) 2) |
| 20:53 | clojurebot | 2 |
| 20:53 | amalloy | ,(let [[a b c d e] (java.util.ArrayList. (range 5))] c) |
| 20:53 | clojurebot | 2 |
| 20:53 | amalloy | oh |
| 20:54 | amalloy | ,(let [[a b c d e] (java.util.LinkedList. (range 5))] c) |
| 20:54 | clojurebot | #<UnsupportedOperationException java.lang.UnsupportedOperationException: nth not supported on this type: LinkedList> |
| 20:54 | amalloy | i was surprised to discover that nth doesn't work on LinkedList but i guess it makes sense |
| 20:54 | cddr | om: I'd wrap the exception if the layer above could sensible use it to display an informative error |
| 21:03 | om | cddr: thanks. I made a couple of macros to this end (with all sort of wrapping, returning) |
| 21:05 | om | I was wondering if I am missing a common idiom |
| 21:05 | amalloy | actually why doesn't nth work on linkedlists? from the code it's clear that it's because LinkedList doesn't implement RandomAccess, but like...nth works on LazySeq, so we're clearly not super-concerned about performance. why make it illegal for LinkedList? |
| 21:07 | amalloy | also, here is everyone's official reminder that someone thought ≇ NEITHER APPROXIMATELY NOR ACTUALLY EQUAL TO was a character important enough to get into unicode |
| 21:15 | om | cddr: looks like this: https://www.refheap.com/97691 |
| 22:42 | cddr | om: Looks good |
| 22:44 | om | cddr: cool |
| 22:46 | cddr | dnolen: Could you spell out for someone who hasn't written a large clojurescript app why closure modules are a game changer? |
| 22:46 | dnolen | cddr: for the same reasons it works for Google for the past 5 years at least |
| 22:50 | ddellacosta | dnolen: why didn't you just give him your link? ;-) cddr: http://swannodette.github.io/2015/02/23/hello-google-closure-modules/ |
| 22:51 | cddr | I read that which is what prompted the question |
| 22:51 | ddellacosta | cddr: d'oh, sorry! |
| 22:51 | ddellacosta | (or her, shouldn't assume gender, sorry) |
| 22:51 | cddr | I can confirm that I'm a man |
| 22:52 | ddellacosta | yeah, I just don't like to assume |
| 22:52 | ddellacosta | trying to shake that out of my habits |
| 22:52 | cddr | That seems wise :-) |
| 22:55 | cddr | I guess I thought clojurescript apps were already pretty competetive on size with other frameworks. I'm just trying to make sure I understand why it's a game changer |
| 23:02 | dnolen | cddr: yes but eventually your app gets big enough that you need to split it |
| 23:02 | dnolen | cddr: for small-ish apps doesn't matter much, but medium & larger apps (which are starting to appear) will benefit a lot |
| 23:05 | cddr | dnolen: OK thanks. I love reading your blog. I just miss the context for some of it |
| 23:19 | michaler` | . |
| 23:20 | dnolen | anybody ever encounter this in an interop scenario "deftype/record/reify cannot access its superinterface" ? |
| 23:20 | dnolen | trying to port this http://slieb.org/blog/parseJavaScriptWithGoogleClosure/ |
| 23:21 | dnolen | trying to implement NodeUtil$Visitor interface in a reify results in that error |
| 23:40 | hiredman | never seen, my guess would be the interface has a super interface that is private or package private |
| 23:41 | hiredman | oh, it looks like NodeUtil$Visitor is package private |
| 23:41 | hiredman | (I may be looking at an old version in grepcode) |
| 23:42 | fellipebrito | Is there any place I can find a kick off for TDD using clojure? I mean, right now I have my env completely set and useful for rspec + ruby. VIM's scripts, and all this stuff that would make the "write test + fail + code + green" very friendly (with tons of aliases)... |
| 23:43 | fellipebrito | I'd love to understand how people write tests, what is the best library, as well the best practices, and if it is not ask that much, how VIM guys use it in order to optimize their "fun@coding" |
| 23:44 | tbaldridge | fellipebrito: I've found that when it comes to testing, simple is almost always best. So I use clojure.test (comes with clojure), and I simply open a repl, move to the namespace with the tests and call (run-tests) |
| 23:44 | tbaldridge | fellipebrito: https://clojure.github.io/clojure/clojure.test-api.html |
| 23:48 | fellipebrito | tbaldridge: Thank you dude! |