2011-05-28
| 00:01 | scottj | anyone know with swt do you have to make 6 versions of your app (win/mac/lin/32/64) or include all 6 of those in one jar? |
| 05:11 | Vinzent | is there something for dealing with zip archives? |
| 05:12 | Kneferilis | Hello! |
| 05:13 | Kneferilis | is clojure for .NET stable? |
| 05:29 | bpr | why would (:use [ring.middleware.params :only [wrap-params]]) cause this compile error: error: java.lang.Exception: lib names inside prefix lists must not contain periods |
| 05:42 | Kneferilis | I was wondering how Common Lisp compares to clojure, some input please? |
| 05:45 | bpr | I am still quite new to clojure, but so far I've found clojure to be much better. This is mainly due to the massive number of libraries that are available, and how easy it is to make use of them via lieningen and sites like clojars.org |
| 05:45 | bpr | I don't have hard numbers like performance difference for various algorithms etc. |
| 05:46 | bpr | you may want to take a look at: http://blip.tv/clojure/clojure-for-lisp-programmers-part-1-1319721 |
| 05:47 | bpr | and http://blip.tv/clojure/clojure-for-lisp-programmers-part-2-1319826 |
| 05:49 | Vinzent | Kneferilis, clojure definitely has a better infrastructure than CL. Also, I think it's much more clear and consistent. |
| 05:50 | bpr | the immutable data structures and concurrency constructs are a *huge* win imo |
| 05:50 | Kneferilis | Vinzent: clojure for .net can use clojars? |
| 05:51 | Vinzent | Kneferilis, never tried .net, but anyway, i think jar files is specific for java |
| 05:52 | Kneferilis | Vinzent: you can convert them with IKVM to .NE Dlls |
| 05:54 | Kneferilis | Vinzent: ok, thanks for the information |
| 07:14 | bpr | why might i be getting "Could not locate clj_facebook_graph/auth__init.class or clj_facebook_graph/auth.clj on classpath" when I try to compile my app? |
| 07:14 | bpr | I do have clj-facebook-graph-0.2.0.jar in my lib directory |
| 07:15 | bpr | and my project.clj has [clj-facebook-graph "0.2.0"] in the :dependencies |
| 07:16 | bpr | this is my ns: (ns mungo.core (use: [ring.util.response :only [redirect]] |
| 07:16 | bpr | [ring.middleware.stacktrace :only [wrap-stacktrace-web]] |
| 07:16 | bpr | [ring.middleware.params :only [wrap-params]] |
| 07:16 | bpr | [ring.middleware.session :only [wrap-session]] |
| 07:16 | bpr | [ring.middleware.session.memory :only [memory-store]] |
| 07:16 | bpr | [ring.handler.dump :only [handle-dump]] |
| 07:16 | bpr | |
| 07:16 | bpr | [clj-facebook-graph.auth :only [facebook-auth-url with-facebook-auth]]) |
| 07:16 | fliebel | bpr: And the file auth.clj file is there? |
| 07:16 | bpr | I'm done spamming now :-p |
| 07:16 | bpr | yeah |
| 07:16 | bpr | i unzipped the jar to be sure |
| 07:17 | fliebel | hm, that's weird. |
| 07:17 | fliebel | have you tried turning it off an on again? |
| 07:17 | bpr | you mean the clojure instance? yes |
| 07:17 | fliebel | or, (System/getProperty "java.class.path")? |
| 07:18 | bpr | interesting, let me check that |
| 07:18 | bpr | yeah the jar is listed in there |
| 07:19 | bpr | let me unzip it again and be sure there's nothing subtle that i missed |
| 07:19 | fliebel | hm, does importing another file work? |
| 07:19 | fliebel | Sometimes it's just a silly type on the ns.... |
| 07:19 | bpr | inflating: fbg/clj_facebook_graph/auth.clj (where fbg is the directory i unzipped it to) |
| 07:20 | bpr | let me try importing a diff file from the jar |
| 07:20 | bpr | wow, that worked... |
| 07:21 | bpr | fliebel: thanks for the tip |
| 07:23 | bpr | hrm, it seems the with-facebook-auth symbol was the problem... i don't know what was wrong with it |
| 09:44 | bpr | how can i check if a namespace exists at runtime? |
| 09:45 | bpr | I want to do this because I'm writing code that may be executed in Google App Engine and it does not have javax.net.ssl.HttpsURLConnection |
| 09:46 | bpr | I'd like to be able to detect that case and use the code provided by Google to get an https connection |
| 09:48 | opqdonut | bpr: ns-resolve ? |
| 09:49 | opqdonut | or find-ns, rather |
| 09:50 | bpr | i've tried find-ns, it doesn't seem to be it |
| 09:51 | bpr | because even (find-ns 'java.lang) ==> nil |
| 09:52 | bpr | so i think maybe the best way is to try to do (require 'javax.net.ssl.HttpsURLConnection) and catch the exception if it's thrown |
| 09:56 | opqdonut | ah, so you're not looking for a clojure namespace but a java package/class |
| 09:57 | bpr | yeah |
| 09:57 | bpr | sorry for the mangled terminology there |
| 09:57 | opqdonut | you could maybe ask the ClassLoader |
| 09:58 | opqdonut | but, of course, all the nice methods are protected... |
| 09:58 | bpr | interresting |
| 09:59 | opqdonut | the only public one that's of interest seems to be loadClass, which then throws a ClassNotFoundException if it doesn't find the class |
| 09:59 | opqdonut | so that's not any better than using import from clojure |
| 09:59 | bpr | that could work |
| 10:00 | opqdonut | import + catch is probably good enough |
| 10:00 | bpr | ok |
| 10:00 | bpr | i'll give that a shot |
| 10:12 | fliebel | My father got 2 robotic arms from a school. They have LPT ports. Does nyone have any idea how to control these? |
| 10:37 | raek | ,(resolve 'java.lang.Integer) |
| 10:37 | clojurebot | java.lang.Integer |
| 10:37 | raek | ,(resolve 'java.lang.DoesNotExist) |
| 10:37 | clojurebot | java.lang.ClassNotFoundException: java.lang.DoesNotExist |
| 10:38 | raek | bpr: you could also try java.lang.Class/forName and catch ClassNotFoundException http://download.oracle.com/javase/6/docs/api/java/lang/Class.html#forName(java.lang.String) |
| 10:40 | gfrlog | Clojure doesn't have a *var* I can set for a (Math/random) instance to use with (rand-nth), does it? |
| 10:40 | gfrlog | I have some randomized code that I would like to be able to test deterministically |
| 10:41 | gfrlog | without mucking up the non-test code |
| 10:41 | gfrlog | I guess I could rebind (rand-nth) in the tests, if nothing else :-/ |
| 10:42 | bpr | raek: thanks |
| 12:14 | mrBliss | Oh yeah, I'm no. 1 on 4clojure.com! |
| 12:25 | robonobo | Is there any documentation on how to include and use resources in a leiningen uberjar? |
| 12:48 | raek | robonobo: well, everything in the resources/ directory is inlcuded in the jar. you can use (def r (clojure.java.io/resource "foo/bar.txt")) to get a special URL to the file, which you can then use to open it, like this (clojure.java.io/reader r) or this (slurp r) |
| 12:53 | robonobo | raek: that works, thanks. |
| 12:53 | raek | unfortunately, I'm not aware of any pages that explains this scenario, but the concepts involved are basically putting things on the classpath, getting a url to the thing on the classpath, and opening a stream from a url |
| 12:53 | robonobo | it's kinda confusing |
| 12:53 | robonobo | the leiningen documentation doesn't say anything about resources other than how to set the path |
| 12:53 | robonobo | but anyway |
| 12:53 | robonobo | thanks |
| 12:54 | raek | it basically just another src/ |
| 13:17 | Kneferilis | Hello. |
| 13:18 | Kneferilis | anyone with exprerience with clojure on .NET? |
| 13:25 | Kneferilis | can someone explain to me, why use clojure instead of common lisp? |
| 13:27 | Kneferilis | anyone? |
| 13:27 | clojurebot | Please do not ask if anyone uses, knows, is good with, can help you with <some program or library>. Instead, ask your real question and someone will answer if they can help. |
| 13:28 | fliebel | Kneferilis: I inly know it doesn;t work on mono. |
| 13:28 | raek | Kneferilis: well-defined concurrency semantics for things that can mutate, persistent data structures, and interop with the jvm are some arguments |
| 13:28 | fliebel | ... what raek said |
| 13:29 | Kneferilis | raek: but why someone use clojure instead of common lisp or the opposite? |
| 13:29 | Kneferilis | sorry, I just noticed I asked that |
| 13:29 | raek | if your app will (eventually) need both states and multiple threads, then Clojure rules |
| 13:29 | raek | *changing state |
| 13:29 | Kneferilis | and where is common lisp better than closure? |
| 13:32 | rlb | Kneferilis: I imagine that some common lisp's may be faster, and they may provide better built-in support for lower-level operations on a particular platform. Though the jvm has gotten better in that respect (i.e. symlinks). |
| 13:32 | raek | Kneferilis: ... oh, and to the clojure over cl arguments, add The Sequence Abstraction |
| 13:33 | raek | the fact that CL has a standard could be an argument fo CL too |
| 13:33 | Kneferilis | I see. |
| 13:34 | rlb | Kneferilis: also for better and worse, common lisp has a giant library, though for many modern (especially web-oriented) bits, when you include the jvm, I'd imagine clojure has the upper hand. |
| 13:35 | rlb | Though it's been quite a while since I worked in common lisp heavily, so I'm not up on the current state of the world. |
| 13:36 | raek | I guess the condition system and debugging is more simpler in CL, but it's getting better in Clojure |
| 13:36 | raek | probably a lot simpler |
| 13:37 | Kneferilis | how does clojure compare to F#? |
| 13:37 | rlb | I imagine the decision would often be clear, given the particular project, and the particular target platform. |
| 13:37 | rlb | i.e. if you need to deploy somewhere the jvm doesn't exist, but one of the common lisps does... |
| 13:37 | rlb | etc. |
| 13:38 | rlb | Don't know anything about F#. |
| 13:39 | Kneferilis | ok |
| 13:42 | churib | which version of swank should i use with the current version of clojure-slime? |
| 13:43 | churib | swank <--> slime |
| 13:45 | amalloy | bpr: http://download.oracle.com/javase/1.3/docs/api/java/lang/Package.html#getPackage(java.lang.String) |
| 13:49 | amalloy | churib: it's hard to nail down versions, because apparently the slime devs think releases are lame |
| 13:50 | raek | churib: if you follow this approach, you get a slime version that works for the swank version you are using: http://technomancy.us/149 |
| 13:50 | carllerche | Does anybody know of a resumable json parser for clojure? As far as I can tell, the one in contrib blocks for input. |
| 13:51 | churib | raek: thanks - i will try that one |
| 13:52 | amalloy | carllerche: huh? how could it not block? |
| 13:52 | raek | carllerche: could you explain how you would like to use such a parser? |
| 13:52 | carllerche | amalloy: returns a state |
| 13:52 | amalloy | oh, resumable |
| 13:52 | carllerche | or tracks state somehow |
| 13:52 | amalloy | i read that as reasonable |
| 13:52 | carllerche | hehe :) |
| 13:53 | raek | one hackish way to use the contrib one could be to pass data to a PipedInputStream that the parser can read from |
| 13:55 | carllerche | yeah... but it seems to be a reasonable thing to have. I'm not sure if it would be better to try to write a resumable parser for clojure or try to use a java one since the java ones would parse to some java structure and then it would have to be converted to clojure data structures |
| 13:55 | carllerche | i should see if aleph has anything |
| 13:55 | amalloy | i'm still not really clear how it would be useful to you. you want to get out the partial results and work with them somehow? |
| 13:56 | raek | carllerche: so you want to feed it data that might not make a complete json object, and get back as many object as could be parsed? |
| 13:57 | carllerche | I'm dealing w/ large json objects & netty. It seems better to stream the chunks into the parser as opposed to buffer all the chunks then parse all at once |
| 13:57 | carllerche | but, it could probably go either way |
| 13:57 | raek | carllerche: fn-parse is a functional parsing library that has a json parser as an example. it will return its state. |
| 13:58 | carllerche | raek: huh, looks interesting. I'll look into it. Either way, worst case is buffer all the chunks before parsing which isn't _terrible_ in this case |
| 14:09 | amalloy | haha congrats mrBliss |
| 14:20 | mrBliss | amalloy: How can I see the code golf histograms without resubmitting my solutions? |
| 14:20 | amalloy | mrBliss: fork the github repo and add the feature :P |
| 14:21 | amalloy | not strictly true, i guess |
| 14:22 | amalloy | https://4clojure.com/leagues/golf/2 will show you all the scores but with no marker for where you stand |
| 14:23 | mrBliss | amalloy: nice. Are the solutions stored or just the scores? |
| 14:23 | amalloy | mrBliss: we started storing solutions after we started storing scores |
| 14:23 | amalloy | and we don't actually store your *best* scoring solution, but rather the one you entered most recently |
| 14:24 | mrBliss | amalloy: it'd be nice to compare solutions like on projecteuler :-) |
| 14:25 | amalloy | mrBliss: well you seem to be better at clojure than dbyrne or me, so make it happen! |
| 14:26 | mrBliss | amalloy: I should be studying for my exams though ;-) When I find some time, I'll see what I can do. |
| 14:55 | dnolen | fliebel: did you sae my comment about your core.logic patch? |
| 14:55 | dnolen | s/sae/see |
| 14:55 | sexpbot | <dnolen> fliebel: did you see my comment about your core.logic patch? |
| 15:26 | fliebel | dnolen: no? |
| 15:26 | dnolen | fliebel: check it out, you should bring the args bit back, I explain in the comment on your patch. |
| 15:26 | fliebel | I'm looking at it now. |
| 15:27 | fliebel | So they should just be no-ops now? sure... I'll have another patch in a few secs. |
| 15:27 | dnolen | simple type inference for the simply typed lambda calc in core.logic, port of stack overflow Prolog solution, https://gist.github.com/997140 |
| 15:27 | dnolen | fliebel: thx. |
| 15:28 | fliebel | dnolen: stu said that for a patch to core clojure, I had to use a different format, should I do this for you as well? |
| 15:29 | dnolen | fliebel: yeah, to get attribution info. |
| 15:29 | fliebel | ok |
| 15:29 | fliebel | dnolen: How do I run the tests? |
| 15:29 | dnolen | fliebel: mvn test |
| 15:33 | fliebel | dnolen: Still some failures... |
| 15:33 | dnolen | fliebel: related to what? |
| 15:34 | fliebel | dnolen: It's because the new fact takes a vector and now & args I think. |
| 15:34 | fliebel | *bot |
| 15:34 | fliebel | *not |
| 15:35 | hugod | my first logic code https://gist.github.com/996901 - any critique appreciated |
| 15:35 | dnolen | fliebel: I don't see an immediate advantage in taking a vector, we have apply. |
| 15:35 | fliebel | dnolen: It's just that protocols dont support varargs |
| 15:36 | dnolen | fliebel: protocol fact -> fact*, then define fact which calls it. |
| 15:37 | fliebel | dnolen: hm, could do that... not all to hapy with it, but I guess it's better that way. |
| 15:38 | dnolen | hugod: interesting! what advantage do you see for using core.logic here ? :) |
| 15:39 | hugod | dnolen: it is a simplified at the moment - I want to be able to match multiple rules to build the final map |
| 15:40 | hugod | and ideally spec2 would be built from a plain data structure, that can be built from data in config files |
| 15:41 | dnolen | hugod: for complex rules, core.logic is useful. One thing I don't like is that core.logic is closed, I wonder if a robust pattern matching would work better for your usage ? |
| 15:42 | dnolen | hugod: so you're planning on introduction conditionals of some sort that make multimethods a poor fit? |
| 15:42 | dnolen | introduction -> introducing |
| 15:43 | dnolen | fliebel: yeah, I don't really see any other way, and it's not so bad IMO. |
| 15:44 | fliebel | dnolen: What about invoke? I can't go around implementing all 16 versions of it, I hope? |
| 15:45 | dnolen | fliebel: ? fact* takes a seq, fact will create that seq via rest arg. |
| 15:45 | fliebel | dnolen: I mean, rel implements ifn. If I want that to work with varargs, I need to implement all 20 versions. |
| 15:46 | fliebel | (likes x y) |
| 15:47 | fliebel | But possibly also (likes t u v w x y z) |
| 15:48 | hugod | dnolen: multimethods won't work - need to be able to specify default os-family for a provider, default image-id for a specific os-family for a provider, and :image-id's for :os-family :os-version combinations, image-id's for :os-family :os-version :hardware-id combinations, translations from :cpu-count and :min-ram to hardware size, network topology, etc |
| 15:49 | dnolen | hugod: I see, this is cool. Love to hear feedback as this evolves. |
| 15:50 | hugod | dnolen: sure - I'm also thinking about using it for exception filtering in swank-clj |
| 15:50 | fliebel | Is there any way to implement IFn with varargs without implementing all 20? |
| 15:51 | dnolen | fliebel: hmm ... yeah I agree lets avoid the invoke limits. Can you fix the tests as well in your patch? |
| 15:51 | dnolen | (fact name [a b c]) is OK w/ me. |
| 15:51 | fliebel | dnolen: Okay, so I just fix the tests rather than my code? |
| 15:51 | dnolen | fliebel: yes. |
| 15:53 | fliebel | dnolen: So should I make it (defrel man ['p]) as well? |
| 15:54 | dnolen | fliebel: actually I think we should think about this some more ... |
| 15:54 | dnolen | fliebel: it would be useful to describe relations that dispatch on arity ... |
| 15:55 | fliebel | dnolen: I can't think anymore now. Timezones, you know. I'll just upload this patch and think about it later, or in my sleep probably. |
| 15:55 | dnolen | fliebel: np, I'll ponder it as well. |
| 15:57 | fliebel | ??? git made me 2 patch files. |
| 16:00 | amalloy | fliebel: one per commit, no? |
| 16:00 | fliebel | amalloy: Yea, but why would it do that? Not very useful... |
| 16:00 | amalloy | uh. that seems a lot more useful than the alternative |
| 16:01 | amalloy | if you want just one patch file, rebase it down to one commit |
| 16:01 | fliebel | $google git rebase |
| 16:01 | sexpbot | First out of 7420 results is: git-rebase(1) |
| 16:01 | sexpbot | http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html |
| 16:03 | arohner | anyone have a clever way to stick an 'if' test into a ->> expression? |
| 16:04 | arohner | like (->> foo (bar) (if x (baz) (bogus)), but have it do what I mean? |
| 16:05 | arohner | I already have apply-if, I supposed I could make an arrow version |
| 16:05 | amalloy | fliebel: $ git rebase -i dnolen/master (or whatever you call his branch) |
| 16:06 | amalloy | then in the editor that appears, replace "pick" with "squash" in any commits you want to fold into earlier commits |
| 16:07 | fliebel | amalloy: I did that, but at first I failed :( Now I did it I think. |
| 16:07 | amalloy | fliebel: yeah, i can never find the right args to supply to a rebase :P |
| 16:08 | fliebel | dnolen: http://dev.clojure.org/jira/browse/LOGIC-2 |
| 16:08 | imade | zipmap is kinda evil ,(vals (zipmap (range 1 6) [1 2 3 4 5])) |
| 16:09 | imade | wait, how do I invoke the clojure evaluator here? |
| 16:09 | fliebel | dnolen: What do you mean with dispatch based on arity? |
| 16:09 | imade | ,(vals (zipmap (range 1 6) [1 2 3 4 5])) |
| 16:09 | clojurebot | (5 4 3 2 1) |
| 16:09 | imade | ah there we go |
| 16:09 | imade | it returns in reverse order |
| 16:09 | fliebel | imade: ampersand, comma, or double hash. |
| 16:10 | fliebel | where ##(+1 1) cal also be used in the middle of a sentence. comma is for clojurebot, and ampersand is for sexpbot. |
| 16:10 | sexpbot | java.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn |
| 16:13 | gfrlog | imade: a map doesn't have a defined order, so you shouldn't expect any particular behavior from (vals) |
| 16:13 | fliebel | dnolen: You mean you want to be able to do ((rel [[2 2] [1 2 3]]) [q 2 3]) -> (1) |
| 16:13 | fliebel | *questionmark* |
| 16:16 | imade | so is there another way to zip together indexes and values without loosing order? [[1 :a] [2 :b] [3 :c]] |
| 16:17 | imade | I guess I could use map-indexed |
| 16:17 | imade | ,(map-indexed #(vector %1 %2) [1 2 3 4 5]) |
| 16:17 | clojurebot | ([0 1] [1 2] [2 3] [3 4] [4 5]) |
| 16:17 | gfrlog | imade: I believe a sorted map would accomplish that. Personally I've never had to use one, so I'm curious what you're doing. |
| 16:18 | fliebel | $findfn [[1 :a] [2 :b] [3 :c]] {1 :a 2 :b 3 :c} |
| 16:18 | sexpbot | [] |
| 16:18 | imade | I am solving the 99 prolog problems, nr 16 in particular |
| 16:18 | gfrlog | oh. I'm not familiar with them. |
| 16:18 | fliebel | $findfn {} [[1 :a] [2 :b] [3 :c]] {1 :a 2 :b 3 :c} |
| 16:18 | sexpbot | [clojure.core/into] |
| 16:19 | gfrlog | I guess if you're doing exercizes then you probably wouldn't want too much high-level advice anyhow. |
| 16:19 | imade | :) |
| 16:19 | amalloy | imade: yeah, just map vector |
| 16:19 | imade | I think I had a lightbulb just now above my head |
| 16:19 | amalloy | &(map vector [1 2 3] [:a :b :c]) |
| 16:19 | sexpbot | ⟹ ([1 :a] [2 :b] [3 :c]) |
| 16:19 | gfrlog | imade: that's kind of awkward lighting |
| 16:20 | imade | :D |
| 16:20 | amalloy | imade: shameless plug here: have you tried www.4clojure.com? interactive tutorials, some of them pulled from 99 lisp problems |
| 16:20 | gfrlog | imade: I guess the summary is that there are a handful of ways to represent pairs, depending on what you need to do with them |
| 16:21 | gfrlog | amalloy: have you no shame? |
| 16:21 | imade | I looked that no-one has solved the 99 prolog problems in clojure all the way to 99, so I try to accomplish that |
| 16:21 | fliebel | imade: How far are you? |
| 16:22 | imade | 16 |
| 16:23 | imade | I think it would be good if newcomers like me have as many resources as possible to practice |
| 16:23 | imade | currently it's a private repo, but if anyone is interested to help along then I could make it public |
| 16:27 | imade | I noticed that there have been other attempts, but no one has finished it all the way to 99, so I am commited to do that |
| 16:28 | dnolen | fliebel: Prolog supports the notion of like/1, like/2, like/3 etc. It would be nice to be able to do the same in core.logic. The more I think about it, the more I think that's the direction to go. |
| 16:28 | imade | I made it public https://github.com/imade/clojure-99 |
| 16:29 | imade | so if anyone wants to contribute let me know, I can give commit rights, besides it would be really helpful if I get feedback also, I am a lisp newbie |
| 16:29 | fliebel | dnolen: What would that do in Prolog? I've only encountered it while importing stuff in Erlang. |
| 16:30 | imade | haskell, scala prolog and CL have been solved all the way to 99, so Clojure deserves it too, cause it's a fun and awesome language |
| 16:30 | dnolen | fliebel: it just means that the like relation supports multiple arity is all. right now defrel doesn't, even though goals support it because of multiple arity support. |
| 16:31 | dnolen | fliebel: I'm heading out, will ruminate on this and get back to you. |
| 16:59 | imade | can anyone review my solution to problem 16 or maybe come up with more concise solution? here's the link https://github.com/imade/clojure-99/blob/master/src/clojure_99/problem16.clj and test https://github.com/imade/clojure-99/blob/master/test/clojure_99/test/problem16.clj |
| 17:07 | amalloy | imade: sent a pull request just now |
| 17:07 | imade | k I check it out |
| 17:09 | imade | whoa, nice concise solution! I will run it through the unit test too just in case |
| 17:09 | amalloy | it won't behave the same way as yours when n=1 |
| 17:09 | amalloy | but that's because yours is imo wrong :P |
| 17:11 | amalloy | oh, yes it will. i read your zero-check as a one-check, sorry |
| 17:12 | imade | I get an exception with (drop-nth4 [1 2 3 4 5 6 7 8 9 10] 3) |
| 17:13 | amalloy | oh, i wrote it as n coll, not coll n |
| 17:13 | amalloy | &(doc drop-nth) |
| 17:13 | sexpbot | java.lang.Exception: Unable to resolve var: drop-nth in this context |
| 17:13 | amalloy | &(doc take-nth) |
| 17:13 | sexpbot | ⟹ "([n coll]); Returns a lazy seq of every nth item in coll." |
| 17:13 | amalloy | since that's the way clojure arguments are ordered usually :P |
| 17:15 | imade | yep I need to read some coding conventions then I will do a code review for myself |
| 17:17 | imade | (drop-nth4 [1 2 3] 0) creates neverending loop |
| 17:17 | amalloy | mhm. as you can see i didn't do a zero check. feel free if you want |
| 17:17 | imade | yep |
| 17:18 | amalloy | but "drop every zeroth element" doesn't really have a clear meaning |
| 17:18 | imade | you're right, it's a fine line how error resilient these solutions should be, maybe I should ease it up a bit, like expect valid input |
| 17:53 | imade | amalloy: I'm studying your solution, you're using recursion, but in this form it will consume stack as it goes deeper, right? |
| 17:54 | amalloy | no, because i wrapped it with lazy-seq |
| 17:55 | amalloy | piling concat on top of concat can be problematic sometimes though, so you might try it out for, say, 10k elements |
| 17:58 | imade | seems to be very fast with 10k elements |
| 18:00 | imade | I'm trying to wrap my head around how come this solution doesn't consume stack, lazy-seq source doesn't use recur or smth like that |
| 18:03 | raek | when (lazy-seq ...) is evaluated, the inner code is not evaluated, but put into a LazySeq object, which is returned |
| 18:03 | raek | so one level of the stack is popped right there |
| 18:04 | raek | when you call seq on the LazySeq object, it will return (cons some-element (lazy-seq ...)) and the process is repeated |
| 18:04 | imade | ah ok, so it's solved in deep level, in bear guts |
| 18:04 | raek | you could say that 'seq' and 'lazy-seq' works as a trampoline |
| 18:06 | imade | I am looking clojure.lang.LazySeq source now, it's all java :) |
| 18:11 | imade | I guess I need more experience to know when certain algorithm is consuming stack or not, so far I thought the only way to to recursion is with recur, but as it turns out amalloy's solution also uses recursive definition but without consuming stack |
| 18:12 | raek | yes, lazy-seqs have this property too |
| 19:22 | Kneferilis | Hello! |
| 19:22 | Kneferilis | Is there anything wrong with this code: (ns user) (defn foo [a b] (str a \" \" b)) ? |
| 19:22 | amalloy | Kneferilis: looks fine to me |
| 19:23 | Kneferilis | I see. |
| 19:24 | amalloy | &(let [foo (fn [a b] (str a \" \" b))] (foo 1 2)) |
| 19:24 | sexpbot | ⟹ "1\"\"2" |
| 19:24 | amalloy | assuming that's the output you want |
| 19:27 | Kneferilis | anything wrong with this? |
| 19:27 | Kneferilis | http://pastebin.com/BtP11JWy |
| 19:31 | amalloy | yes |
| 19:32 | Kneferilis | what is wrong? |
| 19:32 | amalloy | it doesn't do the same thing as your clojure example because the escaping of the "s isn't the same |
| 19:33 | amalloy | i don't really write clj/java interop from the java side, but doesn't RT.var want symbols, not strings? |
| 19:33 | amalloy | no, i guess it wants strings |
| 19:34 | Kneferilis | ok |
| 19:35 | amalloy | but you'd probably get more useful help if you said "here's some code that i think should do X but isn't; it's doing Y instead" |
| 19:36 | amalloy | rather than asking someone to guess whether it "works" |
| 19:39 | gfrlog | here's some code that I think should throw an out-of-memory error, but isn't; it's serving a complex and lucrative web application instead. |
| 19:45 | Kneferilis | I have a file foo.cjlit only has the text: (ns user) (defn foo [a b] (str a \" \" b)) in it, is it correct? |
| 19:45 | Kneferilis | I have a file foo.cjl it only has the text: (ns user) (defn foo [a b] (str a \" \" b)) in it, is it correct? |
| 19:49 | Kneferilis | does clojure has eval? |
| 19:49 | imade | ,(doc eval) |
| 19:50 | clojurebot | DENIED |
| 19:50 | imade | hmm |
| 19:50 | imade | http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/eval |
| 19:50 | Kneferilis | well, can it use eval if it is called from java? |
| 19:53 | Kneferilis | thanks for the information |
| 19:53 | Kneferilis | I tried to install clojure on .net, by converting the jar file to dll |
| 19:53 | Kneferilis | with ikvm |
| 19:54 | Kneferilis | but it didn't work |
| 19:54 | Kneferilis | it seems that clojure compiles everything instead of interpreting |
| 19:54 | Kneferilis | so, it compiles its script to java bytecodes and that crashes my app, that expects il |
| 19:56 | imade | I wish I could help you more, did you look at https://github.com/richhickey/clojure-clr/wiki? it seems to have info how to get clojure running on clr |
| 19:58 | imade | ,(-> 2 (+ 2)) |
| 19:58 | clojurebot | 4 |
| 19:58 | imade | ,(-> [1 2 3] (split-at 2)) |
| 19:58 | clojurebot | java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to java.lang.Number |
| 19:59 | gfrlog | ,(->> [1 2 3] (split-at 2)) |
| 19:59 | clojurebot | [(1 2) (3)] |
| 20:00 | imade | aah, cause with -> it would be like (split-at [...] 2) |
| 20:00 | gfrlog | exactly |
| 20:15 | Kneferilis | imade: thanks for the information |
| 20:28 | Kneferilis | goodnight |
| 20:51 | imade | I am searching for a function thrown?, what's the best way to find which namespace it belongs to? |
| 20:51 | gfrlog | maybe clojuredocs.org |
| 20:51 | gfrlog | I bet there is something better though, which I am too lazy to ever figure out exists |
| 20:52 | amalloy | imade: it's not a real function |
| 20:52 | amalloy | it's something that clojure.test treats specially in macroexpansions |
| 20:52 | imade | k, so I can use thrown when I use clojure.test |
| 20:53 | amalloy | yes |
| 20:53 | gfrlog | man that's like one step eviler than a macro |
| 20:53 | amalloy | srsly |
| 20:53 | gfrlog | couldn't it have been done with a (defmacro thrown? ...)? |
| 20:53 | amalloy | gfrlog: thrown? probably needs access to information that the outer macro has |
| 20:54 | gfrlog | I can't think of why...wouldn't it just need to create a try-catch and a couple (is)es? |
| 20:54 | amalloy | i'm not in favor of the choice that was made, but i don't know the background of how clojure.test is implemented so i can't really judge |
| 20:56 | gfrlog | I only make judgments prior to reviewing the code |
| 21:05 | imade | k, it's 4 a.m here, enough of coding for today, good night |
| 21:07 | offby1 | wuss |
| 21:07 | amalloy | *chuckle* |
| 21:07 | amalloy | #clojure is not for the weak! |
| 21:09 | gfrlog | he didn't say for the week, he said for today |
| 21:09 | gfrlog | ....I'm so sorry |
| 21:13 | gfrlog | ,(doc keep) |
| 21:13 | clojurebot | "([f coll]); Returns a lazy sequence of the non-nil results of (f item). Note, this means false return values will be included. f must be free of side-effects." |
| 21:13 | gfrlog | I think that last sentence is strange. |
| 21:26 | amalloy | agreed, i suppose |
| 21:29 | gfrlog | I didn't see anything in the source that looked suspicious, unless I don't understand how chunked seqs work |
| 23:12 | offby1 | presumably clojure reserves the right to call f more or fewer times than you might expect |
| 23:14 | amalloy | offby1: yes. but that's true for a lot of things (eg map) and they don't all mention it; it's sorta implied that if you have side-effectful functions you deserve what you get |
| 23:15 | offby1 | hmph |
| 23:15 | amalloy | (futher, neither keep nor map *actually* call it more than you expect) |