2011-09-09
| 00:25 | nickmbailey | so I have a function in namespaceA that gets a string that represents a function in namespaceB, how do I convert that to the var representing the function in namespaceB so I can call it? |
| 00:30 | brehaut | (resolve (symbol "prn")) |
| 00:31 | nickmbailey | yeah i'm having trouble with prefixing the symbol with namespaceB |
| 00:31 | nickmbailey | and then resolving |
| 00:32 | brehaut | ,(symbol "hello" "world") |
| 00:32 | clojurebot | hello/world |
| 00:32 | nickmbailey | aha |
| 00:32 | brehaut | what are you trying to achieve? |
| 00:33 | nickmbailey | one compojure route to call any of the functions in a specific namespace |
| 00:34 | brehaut | hiredman has a thing you want to look at. give me a moment |
| 00:36 | brehaut | nickmbailey: unfortunately hiredmans github is giant and i cant remember what its called |
| 00:37 | nickmbailey | hehe, well that worked, i'll look around on his github |
| 00:37 | nickmbailey | thanks :) |
| 00:38 | brehaut | yeah. i wouldnt be surprised if theres a some security concerns about taking a string from the wide web and resolving it on a NS |
| 00:39 | brehaut | nickmbailey: https://github.com/hiredman/graft |
| 00:39 | nickmbailey | yeah i'm sure that sentence makes someone cringe |
| 00:42 | nickmbailey | although it could only be resolved on that specific namespace, and anything in there is fine to call |
| 00:42 | nickmbailey | maybe there are other concerns though |
| 00:42 | brehaut | i dont know enough about the mechanics of resolution and namespaces to be not afraid |
| 00:44 | nickmbailey | perhaps I should ask on the mailing list |
| 00:44 | brehaut | have a look at graft |
| 00:45 | brehaut | you might glean some tricks out of there too |
| 00:47 | nickmbailey | yeah i'm merging the body of the request and the url params to pass as the function args so I don't think I can use it directly but good to learn from |
| 00:49 | brehaut | personally i prefer just making a map of strings to fns |
| 00:49 | nickmbailey | yeah this is kind of a "wouldn't it be cool if ..." |
| 00:50 | brehaut | (or clojure.lang.Named if you wish) |
| 00:50 | brehaut | go nuts then ;) |
| 00:50 | lrenn | nickmbailey: also https://github.com/flatland/wakeful |
| 00:51 | nickmbailey | lrenn: cool |
| 00:51 | nickmbailey | have some code browsing to do |
| 03:30 | pyr | is repl-utils available in new contrib ? |
| 05:28 | simonj | I think something is misconfigured with my slime setup - probably something noobish. |
| 05:28 | simonj | I can never see any locals in sldb |
| 05:28 | simonj | https://gist.github.com/1205835 |
| 05:31 | raek | simonj: unfortunately, this is the way it is with "valilla" slime in clojure. you need to hook up a debugger like swank-cdt to get the locals. |
| 05:31 | raek | when swank catches the exception, the stack is already unwound and the locals are gone |
| 05:32 | simonj | raek: ah ok. Do you think swank-cdt or swank-clojure 1.4.0 snapshot is the way to go? I seem to remember reading that it's included in that. |
| 05:33 | raek | simonj: you can also use swank.core/break to pause the program at a certain point. there you can access the locals of the lexical scope of the break form |
| 05:34 | raek | simonj: sorry, I don't know about which version is recommended nowadays |
| 05:34 | simonj | raek: fair enough. Thanks for your help. |
| 05:35 | cees_ | Currently I'm also trying to hook up a debugger to clojure. |
| 05:36 | cees_ | In the past swank/break worked fine for me. But now it fails. |
| 05:37 | cees_ | For some reason it prints the prompt and then falls through te reader (does not stop) |
| 05:37 | cees_ | Now using the debugger-code from "Joy of clojure". Similar approach and similar failure. |
| 05:38 | cees_ | Anyone having any similar experience (or even better: a solution?) |
| 05:39 | simonj | cees_: sorry, I just tried it and it works here and I'm far too |
| 05:39 | simonj | new at all of this to be of much help. swank-clojure version maybe? |
| 05:40 | cees_ | I skipped swank and started to work at the clojure repl. The hot-swapping of swank sometimes hides your failures/errors. |
| 05:41 | cees_ | Starting at a clean repl (lein test) gives a better test. |
| 05:41 | tsdh | amalloy_: Hi |
| 05:41 | cees_ | In my experience at least. |
| 06:05 | tsdh | Does anyone have a deeper understanding of clojure persistence using *print-dup* and can tell me why I gat the error shown at http://pastebin.com/H64WH8gU ? |
| 06:07 | tsdh | Hm, doing manually what the reader should do works fine: http://pastebin.com/x5MU1Q0S |
| 06:17 | ZabaQ1 | I'm trying to wrap my head round the use of ^ |
| 06:18 | ZabaQ | It's suppsed to be (with-meta ..) right? |
| 06:18 | raek | ZabaQ: which clojure version? |
| 06:18 | ZabaQ | 1.2.1 |
| 06:18 | raek | ZabaQ: well, not exactly. it attaches metadata to the source code data structure. with-meta attaches metadata to a runtime value |
| 06:19 | raek | so only things that can see the code data structures can see the ^ metadata, e.g. the clojure compiler and macros |
| 06:20 | raek | or ordinary functions, if the piece of code was quoted |
| 06:21 | raek | also, metadata on vector and map literals is evaluated with the usual evaluation rules. |
| 06:22 | raek | ,(set *print-meta* true) |
| 06:22 | clojurebot | #<ArityException clojure.lang.ArityException: Wrong number of args (2) passed to: core$set> |
| 06:22 | raek | ,(set! *print-meta* true) |
| 06:22 | clojurebot | #<IllegalStateException java.lang.IllegalStateException: Can't change/establish root binding of: *print-meta* with set> |
| 06:26 | ZabaQ | Hmm. So I need to be careful what I'm actually setting the metadata of.. |
| 06:27 | ZabaQ | ^ tends to end up with metadata bound to a symbol at readtime. |
| 06:28 | clgv | cees_: maybe they also changed something in their repl. in CCW the debug-repl/break macro stopped working similarily when they switched their architecture to a client-server-approach with nrepl |
| 06:51 | tsdh | Why does #=(java.util.Date. 1 2 3) work, but #=(new java.util.Date 1 2 3) errors with "Can't resolve new"? |
| 06:55 | manutter | ,(doc new) |
| 06:55 | clojurebot | Excuse me? |
| 06:55 | manutter | *snap* |
| 06:56 | manutter | ,(new 'java.util.Date 1 2 3) |
| 06:56 | clojurebot | #<CompilerException java.lang.IllegalArgumentException: Unable to resolve classname: (quote java.util.Date), compiling:(NO_SOURCE_PATH:0)> |
| 06:56 | manutter | ah well my guess was wrong anyway |
| 06:56 | tsdh | :-) |
| 06:56 | manutter | maybe the parameter list is ambiguous? |
| 06:57 | manutter | Clojure will say "can't resolve" if there are two or more possible constructors |
| 06:57 | manutter | like if there were a Date(int, int, int) and a Date(long, long, long) |
| 06:58 | tsdh | manutter: But #=(new java.util.Date) errors in the same way. |
| 06:59 | manutter | hm, yeah, if it were ambiguous constructors I'd expect (java.util.Date. 1 2 3) to fail in the same way |
| 06:59 | tsdh | Maybe it's some security thing, so that one isn't able to create arbitrary objects when reading strings? |
| 06:59 | manutter | that one seems less likely to me |
| 06:59 | tsdh | Me, too... |
| 07:01 | tsdh | Argh. That's what you get when trying to fiddle together some stand-alone, minimal example for another error... |
| 07:02 | manutter | ,(new java.util.Date 1 2 3) |
| 07:02 | clojurebot | #<Date Sun Mar 03 00:00:00 PST 1901> |
| 07:02 | manutter | oh |
| 07:02 | manutter | lol |
| 07:07 | Cozey | Hello. I have a function named 'send', which replaces the built in send function; i get a warning about this. What should be done here? Disable the warning somehow (with metadata), or change my function to some other name? What's the better approach in a methodological sense? |
| 07:08 | tsdh | ,(new (Class/forName "java.util.Date") 1 2 3) |
| 07:08 | clojurebot | #<CompilerException java.lang.IllegalArgumentException: Unable to resolve classname: (Class/forName "java.util.Date"), compiling:(NO_SOURCE_PATH:0)> |
| 07:08 | clgv | manutter: you only have to quote if you want to provide just the symbol and not the resolved value |
| 07:09 | clgv | in your case you want to provide the Class and not the Symbol |
| 07:09 | manutter | indeed |
| 07:09 | manutter | in tsdh's case, actually :) |
| 07:09 | manutter | I was just testing whether new took a quoted symbol instead of a class |
| 07:10 | tsdh | manutter, clgv: Class/forName doesn't return the class? |
| 07:10 | manutter | ,(new ( . Class/forName "java.util.Date") 1 2 3) |
| 07:10 | clojurebot | #<CompilerException java.lang.IllegalArgumentException: Unable to resolve classname: (. Class/forName "java.util.Date"), compiling:(NO_SOURCE_PATH:0)> |
| 07:10 | manutter | interesting |
| 07:10 | manutter | ,(Class/forName "java.util.Date") |
| 07:10 | clojurebot | java.util.Date |
| 07:11 | clgv | Cozey: you can use (refer-clojure :exclude [send]) then the warning is gone for that file. but you will get it again if you want to include it in another file wwith use. refer will avoid this |
| 07:11 | manutter | tsdh, ##(new java.util.Date 1 2 3) works as is, did you see that? |
| 07:11 | lazybot | ⇒ #<Date Sun Mar 03 00:00:00 PST 1901> |
| 07:11 | clgv | ,(type (Class/forName "java.util.Date")) |
| 07:11 | clojurebot | java.lang.Class |
| 07:11 | Cozey | clgv: i will require it anyway, the solution is good, thanks! |
| 07:12 | clgv | tsdh: the problem is that you actually get an instance of the class Class. you cant call new with it. but it has a createInstance method |
| 07:12 | manutter | I really shouldn't try to debug before my first coffee.... |
| 07:13 | clgv | &(use '[clojure.contrib.repl-utils :only [show]]) |
| 07:13 | lazybot | java.io.FileNotFoundException: Could not locate clojure/contrib/repl_utils__init.class or clojure/contrib/repl_utils.clj on classpath: |
| 07:13 | clgv | ,(use '[clojure.contrib.repl-utils :only [show]]) |
| 07:13 | clojurebot | #<RuntimeException java.lang.RuntimeException: java.io.FileNotFoundException: Could not locate clojure/contrib/repl_utils__init.class or clojure/contrib/repl_utils.clj on classpath: > |
| 07:13 | manutter | ,(.createInstance (Class/forName "java.util.Date") 1 2 3) |
| 07:13 | clojurebot | #<IllegalArgumentException java.lang.IllegalArgumentException: No matching method found: createInstance for class java.lang.Class> |
| 07:13 | manutter | ,(-> (Class/forName "java.util.date) (.createInstance 1 2 3)) |
| 07:13 | clojurebot | #<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EOF while reading string> |
| 07:13 | clgv | manutter: newInstance it is |
| 07:14 | manutter | ah |
| 07:14 | clgv | &(.newInstance (Class/forName "java.util.Date")) |
| 07:14 | lazybot | ⇒ #<Date Fri Sep 09 04:15:30 PDT 2011> |
| 07:14 | manutter | &(.newInstance (Class/forName "java.util.Date") 1 2 3) |
| 07:14 | lazybot | java.lang.IllegalArgumentException: No matching method found: newInstance for class java.lang.Class |
| 07:14 | clgv | manutter: if you want to pass parameters you have to get the appropriate constructor in advance |
| 07:14 | manutter | oh, that's interesting |
| 07:15 | clgv | via getConstructor |
| 07:15 | manutter | I haven't played with interop stuff that much before |
| 07:15 | clgv | thats not interop, thats reflection ;) |
| 07:15 | manutter | personally I'd just stick with ##(new java.util.Date 1 2 3) |
| 07:15 | lazybot | ⇒ #<Date Sun Mar 03 00:00:00 PST 1901> |
| 07:15 | manutter | well, I mean calling Java constructs from clj |
| 07:15 | clgv | indeed. stick to that^^ |
| 07:16 | clgv | you are not just calling java stuff - you are doin java reflection with the above. |
| 07:16 | clgv | in most cases you wont need java reflection for java interop |
| 07:17 | clgv | (new java.util.Date 1 2 3) or in short (java.util.Date. 1 2 3) is fine |
| 07:17 | manutter | yeah, I'm just messing around to see what I can find out about tsdh's situation anyway. |
| 07:17 | clgv | even shorter if you use (:import java.util.Date) in your ns-statement |
| 07:17 | manutter | he said he was getting an error when he tried to call (new java.util.Date 1 2 3) |
| 07:18 | tsdh | clgv, manutter: I'm just trying to create some self-contained example for some other error when trying to read my own objects, so don't expect that code to make any sense. ;-) |
| 07:19 | tsdh | clgv: .newInstance has the same problem with the reader |
| 07:19 | manutter | I haven't had my coffee yet, I EXPECT stuff not to make sense. |
| 07:19 | tsdh | ,(.newInstance (Class/forName "java.util.Date")) |
| 07:19 | clojurebot | #<Date Fri Sep 09 04:20:28 PDT 2011> |
| 07:19 | tsdh | ,#=(.newInstance (Class/forName "java.util.Date")) |
| 07:19 | clojurebot | #<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EvalReader not allowed when *read-eval* is false.> |
| 07:19 | clgv | reading own deftypes/defrecords back in via read-string does not work with clojure 1.2.1 |
| 07:19 | tsdh | ,(binding [*read-eval*] #=(.newInstance (Class/forName "java.util.Date"))) |
| 07:19 | clojurebot | #<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EvalReader not allowed when *read-eval* is false.> |
| 07:19 | clgv | there are posts about that afaik |
| 07:19 | tsdh | ,(binding [*read-eval* true] #=(.newInstance (Class/forName "java.util.Date"))) |
| 07:19 | clojurebot | #<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EvalReader not allowed when *read-eval* is false.> |
| 07:20 | tsdh | clgv: I use 1.3 with plain Java objects. |
| 07:20 | clgv | hummm well. maybe you found a bug - it's called beta for a reason ;) |
| 07:20 | tsdh | clgv: And *print-dup* magick as amalloy_ demonstrates in one of his posts. |
| 07:21 | tsdh | I'll ask on the list... |
| 07:22 | clgv | can I somehow typehint int[][] for deftype? |
| 07:32 | ilyak | clgv: ^objects? |
| 07:32 | ilyak | and inside of that ^ints? |
| 07:32 | ilyak | or how is that |
| 07:33 | clgv | no that wont work. it's pretty different. there should be literally "int[][]" in deftype class. |
| 07:37 | tsdh | Shouldn't (.foo o) be the same as (. o foo)? |
| 07:38 | tsdh | Hm, actually it's (. (identity o) foo)... |
| 07:39 | raek | ,(binding [*read-eval* true] (read-string "#=(.newInstance (Class/forName \"java.util.Date\"))")) |
| 07:39 | clojurebot | #<RuntimeException java.lang.RuntimeException: Can't resolve .newInstance> |
| 07:40 | tsdh | ,(. java.util.Date newInstance) |
| 07:40 | clojurebot | #<CompilerException java.lang.RuntimeException: java.lang.NoSuchFieldException: newInstance, compiling:(NO_SOURCE_PATH:0)> |
| 07:40 | clgv | ,(binding [*read-eval* true] (read-string "#=(.newInstance ^Class (Class/forName \"java.util.Date\"))")) |
| 07:40 | clojurebot | #<RuntimeException java.lang.RuntimeException: Can't resolve .newInstance> |
| 07:40 | tsdh | ,(. (identity java.util.Date) newInstance) |
| 07:40 | clojurebot | #<Date Fri Sep 09 04:41:47 PDT 2011> |
| 07:40 | raek | clgv: IIRC, you can use raw descriptors as type hints in the form of strings. the descriptor of int[][] is "[[I". could you try ^"[[I" ? |
| 07:40 | clgv | raek: I'll try. |
| 07:42 | tsdh | ,#=(identical? java.util.Date (identity java.util.Date)) |
| 07:42 | clojurebot | #<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EvalReader not allowed when *read-eval* is false.> |
| 07:42 | tsdh | Hm, ok. Here it's actually false... |
| 07:47 | clgv | raek: no, ^"[[I" did not work within deftype to get int[][] |
| 08:30 | mattmitchell | Anyone know of a good example showing how to use catch/throw/finally in clojure? |
| 08:30 | pyr | ,(try (Exception. "foo") (catch (Exception e (println "caught: " e)))) |
| 08:30 | clojurebot | pyr: I don't understand. |
| 08:31 | pyr | sorry |
| 08:31 | pyr | ,(try (throw (Exception. "foo")) (catch Exception e (println "caught: " e))) |
| 08:31 | clojurebot | pyr: Gabh mo leithscéal? |
| 08:31 | clgv | mattmitchell: analoguous to java with the following template: (try (do-something-that-might-throw) (catch Exception e (print-stack-trace e) (throw e))) |
| 08:32 | mattmitchell | OK great, how about custom error classes? |
| 08:33 | clgv | mattmitchell: if you need them you probably have to create them via gen-class or write them in java directly |
| 08:33 | mattmitchell | I see. So is there a better way to catch specific kinds of errors other than create new classes? |
| 08:35 | JulioBarros | 340 484 2300 |
| 08:35 | clgv | mattmitchell: depends on what exactly you do |
| 08:35 | Fossi | there's a lispier condition handling somewhere |
| 08:35 | raek | mattmitchell: https://github.com/scgilardi/slingshot |
| 08:35 | clgv | I used plain Exception in the cases where I could not easily avoid using an Exception |
| 08:36 | raek | you can catch java exceptions with catch, but there is no convenient way of creating new exception classes in clojure |
| 08:36 | Fossi | is slingshot the new contrib/condition? |
| 08:37 | Fossi | or are they seperate concepts? |
| 08:37 | raek | I think they are separate |
| 08:37 | raek | and slingshot is maintained |
| 08:37 | raek | I really hope something like this gets into the core of clojure |
| 08:38 | clgv | raek: +1. it would be great if there was an agreement on one standard error-handling for most of the cases |
| 08:39 | raek | the classical lisp problem: things like these are not technical problems in lisps, but social problems |
| 09:44 | bartj | I am using clojure.contrib.prxml to print xml |
| 09:44 | bartj | but it is not pretty |
| 09:44 | bartj | ie. it is not formatted properly |
| 09:44 | bartj | <a>blah</a><a>xyz</a> |
| 09:45 | bartj | am unable to find any option to pretty print it |
| 09:53 | bartj | anyone ? |
| 09:56 | megaloman | bartj: I wrote an xml printer that tabs things out. |
| 09:57 | megaloman | Let me try and dig it up. |
| 10:00 | cees_ | It is easy to pretty-print (indent) with prxml. |
| 10:02 | cees_ | bartj and megloman : use (binding [*prxml-indent* 5] (prxml .... ) ) |
| 10:02 | megaloman | cees_: Cool |
| 10:03 | megaloman | bartj: You could also try this. http://pastebin.com/f8ghWakr I wrote it when I was just starting clojure, so it's not very lazy, but it might work for you. :) |
| 10:04 | cees_ | Does anyone know a good method to check the type of an object? I currently use (= (str (type x)) "class xyz") |
| 10:04 | cees_ | This, works but there should be a shorter way to write my preconditions :-) |
| 10:09 | megaloman | Would this be a good place for a macro: (defmacro classis [x classstring] `(= (str (type ~x) !classstring) |
| 10:10 | megaloman | Would this be a good place for a macro: (defmacro classis [x classstring] `(= (str (type ~x)) ~classstring)) |
| 10:10 | megaloman | I screwed up the parens earlier :) |
| 10:11 | raek | megaloman: you don't need a macro here |
| 10:11 | joegallo | cees_: is there a reason you can't just use the literal class there? |
| 10:11 | joegallo | ,(= (type "foo") String) |
| 10:11 | clojurebot | true |
| 10:11 | raek | (defn classis [x classstring] (= (str (class x)) classstring)) |
| 10:11 | joegallo | ,(= (type (java.util.Date.) java.util.Date) |
| 10:11 | clojurebot | #<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EOF while reading> |
| 10:11 | joegallo | ,(= (type (java.util.Date.)) java.util.Date) |
| 10:11 | clojurebot | true |
| 10:12 | joegallo | also, a problem with using = and type there is that you aren't accounting for subclasses, which might be something you'd like to do. |
| 10:13 | raek | ,(instance? (java.util.Date.) java.util.Date) |
| 10:13 | clojurebot | #<ClassCastException java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.Class> |
| 10:13 | raek | ,(instance? java.util.Date (java.util.Date.)) |
| 10:13 | clojurebot | true |
| 10:13 | megaloman | (= (type (java.util.Date.)) java.lang.Object) |
| 10:13 | raek | I always get the ordering of that wrong... |
| 10:13 | megaloman | ,(= (type (java.util.Date.)) java.lang.Object) |
| 10:13 | clojurebot | false |
| 10:15 | cees_ | joegallo. This works for java-classes. However, if I do a defrecord in clojure this trick does not work anymore. |
| 10:15 | bhenry | ,(instance? java.lang.Object (java.util.Date.)) |
| 10:15 | clojurebot | true |
| 10:15 | megaloman | beat me to it bhenry. |
| 10:15 | megaloman | That's useful. |
| 10:16 | cees_ | joegallo, sorry for the confusion. It works fine. |
| 10:16 | megaloman | Is there a function like (implements? Comparable (...)) |
| 10:17 | cees_ | joegallo, thanks. |
| 10:19 | bartj | cees_: that worked! thanks! |
| 10:19 | bartj | megaloman: thanks as well |
| 10:20 | joegallo | np |
| 10:20 | megaloman | ,(implements? java.lang.Comparable (java.math.BigDecimal.)) |
| 10:20 | clojurebot | #<CompilerException java.lang.RuntimeException: Unable to resolve symbol: implements? in this context, compiling:(NO_SOURCE_PATH:0)> |
| 10:20 | megaloman | ,(instance? java.lang.Comparable (java.math.BigDecimal.)) |
| 10:20 | clojurebot | #<CompilerException java.lang.IllegalArgumentException: No matching ctor found for class java.math.BigDecimal, compiling:(NO_SOURCE_PATH:0)> |
| 10:21 | megaloman | ,(instance? java.lang.Comparable (java.math.BigInteger.)) |
| 10:21 | clojurebot | #<CompilerException java.lang.IllegalArgumentException: No matching ctor found for class java.math.BigInteger, compiling:(NO_SOURCE_PATH:0)> |
| 10:21 | megaloman | ,(instance? java.lang.Comparable (java.lang.String.)) |
| 10:21 | clojurebot | true |
| 10:22 | megaloman | :bartj, good luck. |
| 10:25 | TimMc | $findfn java.lang.Comparable (java.lang.String.) |
| 10:25 | lazybot | [clojure.core/with-out-str] |
| 10:25 | TimMc | Ha! Oh, lazybot... |
| 10:26 | TimMc | ,(doc with-out-str) |
| 10:26 | clojurebot | "([& body]); Evaluates exprs in a context in which *out* is bound to a fresh StringWriter. Returns the string created by any nested printing calls." |
| 10:26 | TimMc | Oh, I invoked it wrong. |
| 10:26 | TimMc | $findfn java.lang.Comparable (java.lang.String.) true |
| 10:27 | lazybot | [clojure.core/instance? clojure.core/not= clojure.core/distinct? clojure.core/not-any? clojure.core/every?] |
| 12:11 | Bronsa | http://sprunge.us/DiRF |
| 12:11 | Bronsa | why isn't this working? |
| 12:12 | Bronsa | if i am doing it wrong, how to access namespaces of a project within lein repl or from slime? |
| 12:15 | hiredman | Bronsa: you need to load the namespace before you can use it, via use or require |
| 12:16 | Vinzent | Bronsa, from slime: compile ns with C-c C-k, then C-c M-p RET |
| 12:16 | Bronsa | thanks both |
| 12:54 | mindbender1 | Please I need a recommendation of the most logical introduction to clojure. Something straight to the point. I already have a number of them which tend to drool on certain topics |
| 12:55 | mindbender1 | I figured some are just better at teaching things than others so I'll like to reap from your experiences |
| 12:56 | mindbender1 | :) |
| 12:56 | dnolen | mindbender1: are you familiar with another functional programming language? |
| 12:57 | mindbender1 | no |
| 12:58 | mindbender1 | but I introduced myself to lisp some years ago so it wouldn't be hard to grasp advanced concepts |
| 12:58 | mindbender1 | really I need something straight to the point not for beginners |
| 12:59 | chouser | mindbender1: Have you considered 4clojure or koans? |
| 12:59 | dnolen | mindbender1: have you looked at The Joy of Clojure? |
| 13:01 | mindbender1 | dnolen: I once did but that was when I was still trying to evaluate which resource to followlet me give it another look |
| 13:06 | chouser | mindbender1: If you skip the first 3 or 4 chapters of JoC, I would be surprised if you found the rest to proceed too slowly. |
| 13:07 | chouser | that said, choosing problems from 4clojure.com that you find intersting can be a great way to drive learning at whatever pace you desire. |
| 13:12 | mindbender1 | chouser: thanks I'm loking at it now and hope it will soon start telling me how to solve real world problems with clojure |
| 13:13 | mindbender1 | I also considering looking at noir tutorials cos that's basically what I want to do with clojure... web development |
| 13:13 | mwillhite | I haven't seen 4clojure, pretty cool…going through the koans was quite helpful at first as well… |
| 13:14 | chouser | mindbender1: JoC will not move you directly toward the goal of creating a web app |
| 13:14 | mindbender1 | you know.. |
| 13:15 | mindbender1 | it's more fundamental |
| 13:15 | chouser | I would hope it would help you do a better job once you get there, but for more direct movement toward a web app, perhaps Clojure in Action or yes some web tutorial. |
| 13:16 | mindbender1 | then as you solving the web tutorial and some concept seem hard to grasp then we can fallback on |
| 13:16 | mindbender1 | you know.. |
| 13:16 | mindbender1 | that's how I like to learn |
| 13:17 | mindbender1 | so if you are surfing and come across anything realistically practical it'd be nice to send them this way |
| 13:18 | dnolen | mindbender1: https://github.com/mmcgrana/ring/wiki |
| 13:18 | mindbender1 | I would even prefer an opensource project I can be looking at if you know of any |
| 13:19 | dnolen | mindbender1: most web dev stuff for Clojure is built on top of Ring. |
| 13:19 | technomancy | clojuresphere is a nice new oss clojure web app |
| 13:19 | mindbender1 | dnolen: thanks for sending that across |
| 13:20 | mindbender1 | I prefer these fields for learning something I can be looking at applying to business |
| 13:22 | mindbender1 | I'd even like if some guru can open a channel like clojure for business |
| 13:23 | mindbender1 | where they share experiences applying clojure to the trade |
| 13:23 | mindbender1 | WDYT |
| 13:24 | chouser | would that happen more in some other channel than it already does here? |
| 13:25 | hiredman | yeah, I fail to see the point |
| 13:26 | hiredman | is "clojure for business" some how not clojure? |
| 13:26 | chouser | hiredman: but you prefer point-free, right? so that's ok then. |
| 13:26 | hiredman | :) |
| 13:26 | chouser | sorry. failed to resist. |
| 13:27 | mindbender1 | I think we also have clojure for education and hobbyist |
| 13:27 | hiredman | what is the difference? |
| 13:27 | mindbender1 | you don't know? |
| 13:28 | mindbender1 | One set just want to have an understanding while the other wants to amke money |
| 13:28 | hiredman | mindbender1: do people often ask you questions that they know the answer to? |
| 13:28 | mindbender1 | *make |
| 13:28 | mindbender1 | sorry about that |
| 13:28 | mindbender1 | more like pun |
| 13:28 | dnolen | mindbender1: business is usually about solving problems. Clojure is designed for problem solving. Hobbyists and academics also like to solve problems too. No need for separate channels. |
| 13:29 | mindbender1 | dnolen: I think you are probably right maybe I was over exaggerating the diff |
| 13:30 | hiredman | right, clojure is a tool, home depot doesn't divide up tools into "tools used for hobbies/tools used to make money" |
| 13:30 | mindbender1 | :-D |
| 13:30 | hiredman | but there are tools of varying quality and power |
| 13:30 | mindbender1 | and there are application of tools |
| 13:31 | hiredman | you don't drive a nail differently for a pet project vs. for work |
| 13:31 | hiredman | it may be the case you have a higher quality tool if you are doing it for work, but not always |
| 13:32 | mindbender1 | why is the a difference between community support and professional support |
| 13:32 | mindbender1 | or a need for it |
| 13:33 | hiredman | for example I once helped a carpenter earthquake retrofit an old house, I dunno if he got paid for it, I certainly didn't so it might fall under "hobby" for me, but I used his tools (like a palm nailer) which were definitely professional |
| 13:34 | mindbender1 | but the owners of the house where certainly not holding you responsible |
| 13:34 | mindbender1 | even with your tools |
| 13:34 | hiredman | what do you mean? |
| 13:35 | chouser | mindbender1: entirely apart from IRC channels, would you be interested in hiring the services of a personal Clojure trainer? |
| 13:35 | mindbender1 | as in you were helping not in charge |
| 13:35 | hiredman | mindbender1: you want a channel for pointy haired bosses who have to mange clojure programmers? |
| 13:36 | mindbender1 | Certainly..it will ease of a lot of the burdens of learning |
| 13:36 | mindbender1 | on my own |
| 13:36 | mindbender1 | hiredman:it's still clojure discussion |
| 13:37 | hiredman | mindbender1: so that is a yes? |
| 13:37 | TimMc | I would imagine professional support to even include such things as "contribute a patch to fix this long-standing bug that is affecting our code". |
| 13:37 | jorgeb | is there something equivalent to the (time) macro that does NOT return the value of expr? |
| 13:37 | TimMc | No, wait, I take that back -- I'm conflating that opinion witha nother one. |
| 13:37 | chouser | TimMc: I think that kind of full-team consulting work is available from Clojure/core |
| 13:37 | mindbender1 | ;-) |
| 13:37 | hiredman | (time (do … nil)) |
| 13:37 | Bronsa | jorgeb: (do (time expr) nil) ? |
| 13:37 | hiredman | mindbender1: I'm just going to /ignore you then |
| 13:38 | jorgeb | Bronsa: thanks |
| 13:38 | mindbender1 | why? |
| 13:38 | clojurebot | why not? |
| 13:38 | mindbender1 | why not why? |
| 13:41 | TimMc | mindbender1: Looks like a combination of poorly explicated desires on your part and crustiness on hiredman's part. |
| 13:41 | TimMc | (Not precisely the adjective I wanted, but it will do.) |
| 13:42 | TimMc | mindbender1: I agree that there is a real distinction between different support levels, but hobbyist/professional is not quite it. |
| 13:43 | TimMc | In my mind, the proper distinction is the time investment required from the supporters. |
| 13:43 | mindbender1 | TimMc: all parties are equally essential |
| 13:43 | user317 | so i implemened an interface via reify |
| 13:43 | user317 | but when i pass it to some java code, i get a java.lang.ClassCastException |
| 13:43 | redinger | mindbender1: Can I interest you in Clojure training? :) |
| 13:43 | TimMc | heh |
| 13:43 | mindbender1 | just that I'm saying that interests differ |
| 13:44 | TimMc | user317: gist a stripped down testcase, maybe someone can spot something |
| 13:44 | user317 | i think, at least i cant tell where that exception is occuring |
| 13:44 | hiredman | user317: the exception should tell you problem, class x cannot be cast to class y |
| 13:44 | mindbender1 | redinger:And how would negotiations start |
| 13:45 | user317 | hiredman: how do i get more out of the error, right now thats the only thing thats printed in repl |
| 13:45 | mindbender1 | I'm serious |
| 13:45 | redinger | You simply sign up for the official Clojure/core training in November |
| 13:45 | saua | weird, I'm trying to install leiningen on windows, but I kept getting classpath errors unless I edited this line "set CLASSPATH="%CLASSPATH%";%LEIN_USER_PLUGINS%;%LEIN_PLUGINS%;test;src" to "set CLASSPATH="%CLASSPATH%";%LEIN_JAR%;%LEIN_USER_PLUGINS%;%LEIN_PLUGINS%;test;src" any idea why it's not including the jar? |
| 13:45 | saua | (difference being, i added %LEIN_JAR%) |
| 13:45 | mindbender1 | A detail of objectives would be a selling point |
| 13:46 | hiredman | user317: (.printStackTrace *e) ; and get a better repl |
| 13:47 | chouser | redinger: Is that training for hobbiests or professionals? |
| 13:47 | redinger | chouser: Yes |
| 13:47 | mindbender1 | redinger: what's the location of the training.. any web info? |
| 13:47 | redinger | mindbender1: http://clojure-conj.org/training |
| 13:48 | hiredman | I have clojurebot sitting in our work irc channel (different instance of clojurebot) does that make clojurebot professional clojure code? |
| 13:49 | user317 | here is my implementation https://gist.github.com/1206861 |
| 13:50 | hiredman | you have two interfaces there, maybe you need a third |
| 13:51 | hiredman | the other possiblity is one of your methods is returning an object that cannot be cast to the correct return type |
| 13:52 | hiredman | ^- professional opinion |
| 13:54 | user317 | hiredman: well, here is their sample implemetnation https://gist.github.com/1206876 it only implements the two, but one extends the other |
| 13:55 | hiredman | user317: so either the return type thing I mentioned, or the java code you hand it off to is trying to cast it to something else |
| 13:56 | `fogus | Hi all. |
| 13:59 | user317 | hiredman: all the methods return void |
| 14:00 | hiredman | user317: well? |
| 14:01 | user317 | hiredman: total java newb, so i may be missing something obvious, could returning something when the return type is void cause a crash? |
| 14:01 | hiredman | user317: have you looked at the stacktrace? |
| 14:02 | jli | hiredman: he said the exception was all that was printed at the repl. user317: try throwing it in a file for a better error |
| 14:03 | user317 | hiredman, jli, https://gist.github.com/1206899 |
| 14:03 | jli | oh ho |
| 14:03 | user317 | the last chunk is the one that actually caused it, right? |
| 14:04 | jli | user317: are you hooking into the interactive brokers api? |
| 14:04 | jli | just curious :) |
| 14:05 | user317 | jli, yea, it sucks :), i have a half baked haskell wrapper for their posix api's, i thought i might use what they recommend and learn clojure |
| 14:06 | jli | a couple of years ago I used the Erlang java interop stuff - it was actually pretty smooth |
| 14:09 | hiredman | at ibclj.core$get_hist_data.invoke(core.clj:105) |
| 14:09 | hiredman | is the function and line number |
| 14:10 | user317 | hiredman: yea, that one is pretty simple |
| 14:11 | user317 | hiredman: https://gist.github.com/1206924 |
| 14:13 | choffstein | Anyone use clj-doc-test? |
| 14:14 | user317 | well, i've got an idea that kind of sucks, i can use their sample implementation as a proxy |
| 14:15 | upwardindex | What is missing in 4clojure is a way to sort problems by the difference with the best code golf score |
| 14:31 | kzar | I'm really stuck on this problem http://4clojure.com/problem/79 , didn't want to ask for help but I'm fully bamboozled. Anyway don't tell me the answer but could anyone show me how to make a list of the paths? I can see how to make a tree structure of the paths something like [3 [[2 [[1 nil] [2 nil]]] [4 [[9 nil] [3 nil]]]]] but I can't figure out how to make a flat one like [[3 2 1] [3 2 2] [3 4 9] [3 4 3]]. Getting |
| 14:31 | kzar | the recursion right is warping my brain, keeping it as tail recursion even more so. |
| 14:38 | gfrlog | kzar: I can't really tell what your "flat tree" example is supposed to be. It looks rather rectangular. |
| 14:41 | kzar | gfrlog: I probably messed it up, in the puzzle you need to find the shortest path through the triangle. I figured the first step is listing all the paths and that's where I'm stuck. I'm able to get a tree structure of the paths but not a list of each path as a flat vector |
| 14:41 | gfrlog | ah ha |
| 14:41 | gfrlog | welp |
| 14:42 | kzar | gfrlog: I can't figure out the recursion because for each iteration you need to cons the current value on to a growing number of lists, but you can't know how many until afterwards let alone what they contain. |
| 14:42 | kzar | I get the feeling I'm thinking about it backwards somehow but I'm stuck |
| 14:43 | gfrlog | that should be a simple recursive definition: |
| 14:43 | gfrlog | say you have an arbitrary triangle |
| 14:43 | gfrlog | you don't know how deep it is |
| 14:44 | gfrlog | all you can get is its first element, a list of paths down the left side, and a list of paths down the right side |
| 14:44 | gfrlog | given those three things it should be pretty easy to combine them together appropriately, right? |
| 14:45 | donperignon | Hello, everybody i am starting with clojure, and i have a very basic question, i have some data structure in this way: |
| 14:45 | donperignon | (("a" "b")("c" "d")("e" "f")) |
| 14:45 | donperignon | in python i used to call zip funciotn to turn into this: |
| 14:45 | donperignon | (("a" "c" "e")("b" "d" "f")) |
| 14:45 | donperignon | |
| 14:45 | donperignon | how can i make this in clojure? |
| 14:45 | donperignon | thanks in advance and sorry for the silly question. |
| 14:46 | chouser | ,(apply map list '((a b) (c d) (e f))) |
| 14:46 | clojurebot | ((a c e) (b d f)) |
| 14:47 | chouser | ,(apply map vector '((a b) (c d) (e f))) |
| 14:47 | clojurebot | ([a c e] [b d f]) |
| 14:47 | donperignon | thanks chouser, i will try right now |
| 14:47 | chouser | ,(map set '(a b) '(c d) '(e f)) |
| 14:47 | clojurebot | #<ExecutionException java.util.concurrent.ExecutionException: clojure.lang.ArityException: Wrong number of args (3) passed to: core$set> |
| 14:47 | chouser | ,(map hash-set '(a b) '(c d) '(e f)) |
| 14:47 | clojurebot | (#{a c e} #{b f d}) |
| 14:47 | chouser | etc. |
| 14:48 | kzar | gfrlog: Not sure I follow you |
| 14:49 | gfrlog | kzar: lemme put it another way |
| 14:49 | gfrlog | if you had a function that could return the left "subtree" and the right "subtree" |
| 14:49 | gfrlog | maybe "subtriangle" is clearer |
| 14:49 | donperignon | chouser, that whats perfect |
| 14:49 | gfrlog | and so you could call your function recursively on each side |
| 14:49 | donperignon | you save a lot of work, thanks |
| 14:49 | chouser | donperignon: np |
| 14:49 | gfrlog | then you could combine the two lists |
| 14:50 | donperignon | i still dont get the magic behind some functional tricks |
| 14:50 | gfrlog | kzar: I'm trying not to be TOO explicit since you said "don't tell me the answer" |
| 14:51 | kzar | gfrlog: Still don't see how it helps, say we start with that first example on the page. I have 1, left sub tree nad right subtree. I can do [1 [left-subtree right-subtree]], follow it down recursively to get a tree of the paths. But that's what I can already see how to do. |
| 14:52 | kzar | When you don't know what's in left-subtree how can you cons 1 on to each path within it? |
| 14:52 | gfrlog | kzar: your left subtree would look like [[2] [5 1] [2 3 4]], right? |
| 14:58 | kzar | gfrlog: Oh right, I was thinking more [[2 [[5 [[2 nil] [3 nil]]] [[1 [[3 nil] [[4 nil]]]]]]]] again I might have messed that up |
| 14:58 | gfrlog | kzar: of course if you care about the efficiency of the algorithm, this isn't the way to go |
| 14:59 | gfrlog | but it will certainly work for the sake of passing the exercise |
| 15:01 | upwardindex | Why can't I (apply do [1 2 3])? |
| 15:01 | upwardindex | However I can (do 1 2 3) |
| 15:01 | kzar | gfrlog: Hmm OK that's a good hint anyway cheers. I'll have more of a think over it |
| 15:02 | joly | upwardindex: do is a special form, so it can't be treated like a normal function |
| 15:03 | upwardindex | joly: So I have to (defn mydo [& rest] (apply do rest)) and then do what I want? |
| 15:04 | upwardindex | lol |
| 15:04 | upwardindex | nvm |
| 15:04 | joly | upwardindex: it means you can't pass do to apply like you could a normal function |
| 15:04 | upwardindex | I'm thinking in circles |
| 15:04 | gfrlog | upwardindex: what're you trying to accomplish? |
| 15:05 | upwardindex | gfrlog: Trying to beat 4clojure 19 in 7 characters ;) |
| 15:05 | upwardindex | "apply do" |
| 15:09 | chouser | upwardindex: what's the record? |
| 15:09 | chouser | I just did it in 15 chars |
| 15:10 | upwardindex | chouser: I find it really hard to see the record for problems where the spread is more than 25 because of the histograms implementation |
| 15:10 | chouser | 14 |
| 15:11 | chouser | there are histograms? |
| 15:11 | chouser | ah, found it. |
| 15:11 | upwardindex | it seems to be around 10 |
| 15:11 | upwardindex | but could be 9 or 11 |
| 15:12 | gfrlog | &(count "(comp first reverse)") |
| 15:12 | lazybot | ⇒ 20 |
| 15:22 | mindbender1 | please someone advice me on this error when slime-connect to vagrant: |
| 15:23 | mindbender1 | Connecting to Swank on port 2222.. [2 times] |
| 15:23 | mindbender1 | Entering debugger... [2 times] |
| 15:23 | mindbender1 | Lisp connection closed unexpectedly: connection broken by remote peer |
| 15:23 | user317 | java.lang.reflect.InvocationTargetException, what does that mean? |
| 15:24 | dnolen | mindbender1: are you just trying to play around w/ Clojure? If so I recommend this, https://github.com/arthuredelstein/clooj |
| 15:25 | mindbender1 | no serious work |
| 15:25 | dnolen | mindbender1: double-click |
| 15:25 | gfrlog | user317: what are you doing when it happens? |
| 15:25 | dnolen | mindbender1: just click the downloads button and you'll see the latest executable. |
| 15:26 | mindbender1 | ok I'll try that out |
| 15:26 | user317 | gfrlog: trying to create a java class, but i pass a reifyied implementation of an interface to it |
| 15:27 | mindbender1 | dnolen: does it work with lein |
| 15:28 | gfrlog | user317: hrm :/ I don't know much about that, sorry. I'd just fiddle with it to try to figure out what part is killing it. You can also implement an interface using deftype, if that helps with fiddling. |
| 15:29 | dnolen | mindbender1: yes |
| 15:30 | upwardindex | Is #(do %2) the shortest way to return the second argument? |
| 15:31 | gfrlog | upwardindex: only works if there are exactly two args |
| 15:32 | hiredman | ,(comp second list) |
| 15:32 | clojurebot | #<core$comp$fn__3786 clojure.core$comp$fn__3786@240de4> |
| 15:32 | hiredman | #(second %&) |
| 15:32 | gfrlog | I doubt there's anything shorter though |
| 15:33 | hiredman | ,#((vec %&) 0) |
| 15:33 | clojurebot | #<sandbox$eval6514$fn__6515 sandbox$eval6514$fn__6515@5e66cc> |
| 15:33 | hiredman | ,(#((vec %&) 0) (range 10)) |
| 15:33 | clojurebot | (0 1 2 3 4 ...) |
| 15:33 | hiredman | hmmm |
| 15:33 | hiredman | ,(#((vec %&) 1) (range 10)) |
| 15:33 | clojurebot | #<IndexOutOfBoundsException java.lang.IndexOutOfBoundsException> |
| 15:34 | hiredman | ,(apply #((vec %&) 1) (range 10)) |
| 15:34 | clojurebot | 1 |
| 15:34 | hiredman | ,(count "#((vec %&) 1)") |
| 15:34 | clojurebot | 13 |
| 15:34 | hiredman | ,(count "(comp second list)") |
| 15:34 | clojurebot | 18 |
| 15:34 | hiredman | ,(count "#(second %&)") |
| 15:34 | clojurebot | 12 |
| 15:35 | gfrlog | ,(count "(fn[&[a b]]b)") |
| 15:35 | clojurebot | 13 |
| 15:35 | hiredman | ,(count "#((vec %&)1)") |
| 15:35 | clojurebot | 12 |
| 15:35 | chouser | ooh, #(second %&) is nice |
| 15:36 | chouser | #(peek(vec %)) was my closest |
| 15:36 | chouser | oh, that's something else. nm. |
| 15:37 | hiredman | I've used (comp type first list) a lot as a dispatch for multimethods |
| 15:39 | sjl | Does 4clojure's code golf counter strip whitespace automatically or something? |
| 15:39 | sjl | Ah, apparently so. Neat. |
| 15:39 | user317 | :e# |
| 15:40 | tufflax | ,(count "#(fnext %&)") |
| 15:40 | clojurebot | 11 |
| 15:45 | upwardindex | How can I apply and to a sequence? |
| 15:46 | dakrone | ,(reduce 'and [true true 0 1 false]) |
| 15:46 | clojurebot | false |
| 15:46 | dakrone | like that |
| 15:48 | chouser | nope |
| 15:48 | chouser | ,(reduce 'and [true true true true]) |
| 15:48 | clojurebot | true |
| 15:48 | chouser | ha! |
| 15:48 | user317 | ha, i was passing an integer where a String was expected |
| 15:48 | chouser | what? |
| 15:48 | clojurebot | what is moustache |
| 15:49 | chouser | ,(reduce 'and [false true true true]) |
| 15:49 | clojurebot | true |
| 15:49 | TimMc | WHAT |
| 15:49 | chouser | there we go |
| 15:49 | TimMc | Ah, much better. |
| 15:50 | upwardindex | Respect to the black wizard that did 4clojure 19 in 10 chars! |
| 15:50 | TimMc | For a bit there I thought there was some magic there I didn't know about. |
| 15:50 | upwardindex | I can't seem to go under 13 chars |
| 15:51 | chouser | upwardindex: (reduce #(and %1 %2) ...) or (every? identity ...) |
| 15:51 | chouser | (reduce 'and ...) doesn't do what you want |
| 15:51 | dakrone | chouser: you are correct, my mistake |
| 15:52 | tufflax | upwardindex it can be done in 8 ;) |
| 15:52 | upwardindex | tufflax: WHAAAAAAT *bows down* |
| 15:52 | tufflax | as amalloy_ told us someone did |
| 15:54 | hiredman | it just takes a lot of tries to do it in 8 |
| 15:54 | TimMc | I can get the first two tests in just 5. :-P |
| 15:54 | upwardindex | tufflax: Ah sweet just did it in 9 |
| 15:55 | tufflax | upwardindex really? it's pretty good if it works every time |
| 15:55 | upwardindex | tufflax: yup i can pm the solution if you want to verify |
| 15:55 | tufflax | hm, hold on a bit |
| 15:55 | tufflax | ill try myself |
| 15:57 | joly | how many characters for a program that outputs all 8-character Clojure snippets? ;) |
| 15:58 | gfrlog | ,(count "(comp {1 5 5 3 \"b\" \"d\"} first)") |
| 15:58 | clojurebot | 30 |
| 15:58 | gfrlog | I beat all of you |
| 16:02 | upwardindex | I want a list of clojure.core functions sorted by length :P |
| 16:02 | tufflax | easy to do i think |
| 16:02 | TimMc | hiredman: Oh no... I got it. That's terrible. |
| 16:03 | dpritchett | i did the first 20something problems on 4clojure today |
| 16:04 | dpritchett | and then i got to the one where i was supposed to return the first N fibonacci numbers with an inline function (no defs!) and my stack overflowed and i had to take a break |
| 16:04 | upwardindex | hiredman, TimMc: Is it tailored to the test set or would it work with a more thorough test bench? |
| 16:04 | dpritchett | is it really helping me to do all of this within a single set of parens? |
| 16:05 | TimMc | upwardindex: I don't think I can answer your question as stated. What I can say is that it's not a good solution. |
| 16:05 | upwardindex | TimMc: Would it work with more tests that are different from the 3 that are there? |
| 16:06 | TimMc | maybe? |
| 16:07 | TimMc | OK, so I got an honest solution in 13 chars. |
| 16:07 | upwardindex | lol, can't wait to find that nasty solution |
| 16:07 | upwardindex | TimMc: honestly, the 9 char solution is pretty legit |
| 16:07 | TimMc | I cheated (in a way) to find the nasty one. |
| 16:09 | hiredman | dpritchett: letfn |
| 16:09 | dpritchett | thanks hiredman |
| 16:09 | dpritchett | now i can get back to it without feeling like i need to write entire solutions in a single sexp |
| 16:10 | hiredman | letfn is a sexp |
| 16:10 | hiredman | as is let |
| 16:11 | dpritchett | i like a REPL where i submit more than once while building a solution |
| 16:11 | dpritchett | not to say i won't wind up with a tiny golfed solution eventually |
| 16:11 | dpritchett | but it'd be nice to be able to define helper functions and compose them as i go along |
| 16:11 | dpritchett | rather than doing it all in a big bang |
| 16:11 | hiredman | ,((fn x [i] (lazy-seq (when-not (zero? i) (cons i (x (dec i)))))) 10) |
| 16:11 | clojurebot | (10 9 8 7 6 ...) |
| 16:12 | hiredman | ,(((fn [x] (partial x x)) (fn [x i] (lazy-seq (when-not (zero? i) (cons i (x x (dec i))))))) 10) ; if you want to get classical |
| 16:12 | clojurebot | (10 9 8 7 6 ...) |
| 16:12 | joly | I went the helper function and composition route. It made piecing together solutions for some of the graph problems a lot easier |
| 16:14 | gfrlog | if the expression doesn't start with three opening parens it's not real lisp. |
| 16:14 | dpritchett | so how do you define your helpers? a bunch of letfns at the beginning of your expression? |
| 16:14 | joly | yes, I used letfn to define a number of functions |
| 16:14 | joly | it's definitely not a winning approach for code golf, but it allowed some interesting solutions |
| 16:14 | hiredman | letfn is nice, I'd really like to get the compiler to lift letfn's that qualify out into static methods |
| 16:15 | hiredman | hint hint if anyone is interested in a compiler project |
| 16:28 | dpritchett | how can i replace the values in a seq via map? |
| 16:29 | dpritchett | say i was reimplementing count and i tried to map everything to a 1 and then reduce with + |
| 16:29 | dpritchett | for some reason i couldnt figure out how to directly replace with a literal one so i made a helper function (fn [n] 1) instead |
| 16:29 | joegallo | (map (constantly 1) values) |
| 16:30 | dpritchett | thanks |
| 16:30 | hiredman | (for [x y] 1) |
| 16:30 | TimMc | nice |
| 16:31 | TimMc | hiredman: (for[x y]1) :-P |
| 16:31 | TimMc | If spaces count... |
| 16:32 | dpritchett | can you show me an example of (for [x y] 1)? |
| 16:32 | dpritchett | doesnt do anything for me |
| 16:32 | joegallo | ,(for [x [1 2 3]) 1) |
| 16:32 | clojurebot | #<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: Unmatched delimiter: )> |
| 16:32 | TimMc | dpritchett: bind y |
| 16:32 | joegallo | ,(for [x [1 2 3] 1) |
| 16:32 | clojurebot | #<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: Unmatched delimiter: )> |
| 16:33 | joegallo | third time's the charm |
| 16:33 | joegallo | ,(for [x [1 2 3]] 1) |
| 16:33 | clojurebot | (1 1 1) |
| 16:33 | joegallo | wahoo! |
| 16:33 | dpritchett | thanks |
| 16:34 | saua | If I have a sequence like this: [1 2 3 4 5] how would I best be able to permutate it to this [[1 2] [2 3] [3 4][4 5]] ? |
| 16:35 | TimMc | ,(map (fn [x] (*)) [1 2 3 4]) |
| 16:35 | clojurebot | (1 1 1 1) |
| 16:35 | TimMc | saua: partition-all |
| 16:35 | TimMc | or maybe just partition |
| 16:35 | hiredman | ,(doc partition-all) |
| 16:35 | clojurebot | "([n coll] [n step coll]); Returns a lazy sequence of lists like partition, but may include partitions with fewer than n items at the end." |
| 16:35 | saua | ty |
| 16:36 | TimMc | Yeah, you don't want -all here. |
| 17:25 | Bronsa | http://sprunge.us/dWUR |
| 17:25 | Bronsa | why isnt this working? |
| 17:28 | Bronsa | but if i write it manually without using a macro it works |
| 17:29 | Bronsa | perharps there is something wrong with the evaluation time |
| 17:31 | tufflax | which one tarcieri |
| 17:31 | tarcieri | 28 |
| 17:31 | tarcieri | I'd like to do it with arity overloading |
| 17:31 | tarcieri | maybe that's because I haven't yet purged all the Erlang out of my system |
| 17:33 | joegallo | Bronsa: if you type those forms at the repl in exactly the order you gave in your paste, it doesn't compile. you are referring to x before x was defined. |
| 17:33 | tarcieri | if I were writing Erlang, each time I encountered a nested seq I'd make a recursive call to the flatten function, but one that took the flattened-list-in-progress in addition to the one I was trying to flatten |
| 17:33 | tarcieri | I don't know how to do that in Clojure |
| 17:33 | tarcieri | well I do |
| 17:33 | tarcieri | but not without a named function |
| 17:34 | tufflax | you can name an fn (fn name [] ...) |
| 17:34 | tarcieri | ohai nathanmarz |
| 17:34 | tarcieri | yeah so |
| 17:34 | tarcieri | I can actually call it that way? |
| 17:34 | tufflax | yes |
| 17:34 | tarcieri | I thought I tried that and it didn't work |
| 17:35 | Bronsa | joegallo: you're right, i had x defined before |
| 17:35 | Bronsa | anyway, i just found out the problem |
| 17:35 | Bronsa | what i want is (str x ~y) not ~(str x y) |
| 17:36 | tarcieri | if I'm iterating and want to build an in-order list, what's more idiomatic: build the list in reverse order then reverse it at the end, or build a vector in-order then convert it to a list when I'm done? |
| 17:37 | hiredman | tarcieri: vector |
| 17:37 | tarcieri | ok |
| 17:48 | tarcieri | ugh, well I solved it |
| 17:48 | tarcieri | this is ooglaaay |
| 17:48 | tarcieri | lol |
| 17:48 | tarcieri | http://4clojure.com/share/code |
| 17:48 | tarcieri | blah |
| 17:48 | tarcieri | https://gist.github.com/1207424 |
| 17:49 | tarcieri | that was the first one I really struggled with |
| 17:49 | tufflax | wow that's a lot of code |
| 17:49 | tarcieri | yeah |
| 17:49 | tarcieri | I suppose the loop is unnecessary |
| 17:51 | tarcieri | https://gist.github.com/1207431 |
| 17:52 | tufflax | yeah that's a little better ;) |
| 17:52 | tarcieri | marginally |
| 17:52 | tarcieri | still ooglaay |
| 17:56 | tufflax | tarcieri I think you should try to use higher-level functions; try to avoid let, first and rest. |
| 17:57 | tarcieri | I've still got Erlang on the brain |
| 17:57 | tufflax | (in this case) |
| 17:58 | tarcieri | tufflax: about all I can think to use there is a fold |
| 17:58 | tarcieri | haven't even tried to use one in Clojure yet |
| 18:00 | tufflax | So try that :p |
| 18:01 | tarcieri | heh, k |
| 18:02 | tufflax | I'll also try. fold (reduce right?) is not my first pick for this |
| 18:02 | tarcieri | yes |
| 18:02 | tarcieri | reduce |
| 18:02 | tarcieri | is what I'm trying |
| 18:06 | tarcieri | https://gist.github.com/1207458 |
| 18:06 | tarcieri | there we go |
| 18:06 | tarcieri | that's marginally better |
| 18:07 | tufflax | btw sequential? is what you want for the test |
| 18:07 | tarcieri | aha |
| 18:07 | tarcieri | was gonna ask about that |
| 18:08 | tarcieri | https://gist.github.com/1207462 |
| 18:09 | tufflax | try to do it with map now :p |
| 18:09 | tarcieri | with map? |
| 18:09 | tufflax | yes, imo that's simpler |
| 18:09 | tarcieri | I'm confused as to how |
| 18:09 | tarcieri | each iteration can add N elements to the output list |
| 18:10 | tufflax | at every level you want to do the same thing to every element in the list, right? you want to flatten it. so that's where map comes in |
| 18:11 | tarcieri | but you want to flatten the whole list, not just every element inside of it |
| 18:12 | tufflax | yes, but if you have a list of flattened lists, what do you do then to make 1 flattened list? |
| 18:12 | tarcieri | reduce? :) |
| 18:13 | tufflax | no |
| 18:13 | tufflax | concat |
| 18:13 | tarcieri | orly |
| 18:13 | TimMc | apply concat |
| 18:13 | tarcieri | I was looking for something like that |
| 18:13 | tarcieri | I see |
| 18:14 | tufflax | I don't know if map is "best" but it's short and simple imo. (the flatten in core is a bit funny, not something i would have come up with) |
| 18:18 | solussd | bronsa: because a macro doesn't evaluate its arguments |
| 18:21 | tarcieri | so |
| 18:22 | tarcieri | map produces a list I want to pass as arguments to concat |
| 18:22 | tarcieri | how do I do that exactly? |
| 18:22 | tufflax | (apply concat (map ...)) |
| 18:22 | tarcieri | aha |
| 18:22 | tufflax | (or mapcat) |
| 18:22 | tarcieri | :O |
| 18:22 | tufflax | mapcat is a shortcut for that |
| 18:24 | tufflax | btw in your version with reduce, the vararg thing is totally unnecessary :P |
| 18:24 | tufflax | or, no, sorry |
| 18:24 | tufflax | the way you did it it's not |
| 18:25 | tarcieri | it's kind of how I would do it in Erlang, ported to Clojure |
| 18:26 | tufflax | doesn't erlang have map? :p |
| 18:26 | tarcieri | yes, however, I probably wouldn't use map in Erlang for this problem |
| 18:26 | tarcieri | you don't end up using map in Erlang much |
| 18:26 | tarcieri | because it has list comprehensions |
| 18:26 | tufflax | clojure has that too |
| 18:26 | tufflax | but map is often useful anyway |
| 18:27 | tarcieri | I wouldn't use list comprehensions in the Erlang version either |
| 18:27 | tufflax | how's your map version coming along? :p |
| 18:27 | tarcieri | I'm kinda roadblocked on it |
| 18:27 | tarcieri | I was gonna bust the Erlang version really quick for the lulz |
| 18:28 | tufflax | this is what i ended up with when trying to use reduce: http://pastebin.com/38vC2KvZ |
| 18:29 | tufflax | forgot a paren in the end there :P |
| 18:30 | tufflax | and forgot to change the call from "flatt" :P |
| 18:32 | TimMc | I feel kind of bad leaving my debugger paused in the middle of execution overnight. |
| 18:33 | tufflax | hah, you made me think of this http://steve-yegge.blogspot.com/2007/01/pinocchio-problem.html |
| 18:33 | tufflax | TimMc |
| 18:36 | tarcieri | later |
| 20:26 | user317 | how come i dont always see the prints |
| 20:29 | Beta-83 | Hello! :) |
| 22:09 | chewbranca | blist |
| 22:10 | chewbranca | bah wrong window :/ |
| 23:38 | srid | is anyone hosting apps on heroku with cron/background-tasks and yet manage to keep the costs low? (for just cron, 24x7 workers seem silly) |