2011-02-22
| 00:00 | brehaut | aha |
| 00:05 | brehaut | amalloy: huh i had something terrible in my scrollback buffer in the (use…) in my repl |
| 01:48 | rhebus | I'd like to get the first item in a sequence which matches a predicate. (some pred coll) almost does this, but it returns (pred x) where I just want x. Is there a neat way to do this? |
| 01:50 | talios | (first (filter ..)) maybe> |
| 01:50 | talios | ? |
| 01:51 | rhebus | yeah that makes sense |
| 01:51 | brehaut | talios: that looks right |
| 01:52 | brehaut | ,(first (filter even? [1 3 4 5 6 8])) |
| 01:52 | clojurebot | 4 |
| 01:52 | rhebus | works a treat |
| 01:52 | rhebus | thanks very much |
| 01:52 | rhebus | not used to thinking in terms of lazy yet |
| 01:52 | rhebus | i had ruled out filter because it filters an entire sequence when i just want the first bit |
| 01:54 | talios | there may be a better way but that works ;) I really need to get myself back into some clojure myself |
| 01:59 | rhebus | can't see how it could be improved much |
| 02:09 | clizzin | how does nth interact with java classes that implement the List interface? it looks like first and second work just fine, but nth doesn't for some reason. |
| 02:11 | talios | from memory - try (nth (seq your-list) 5) |
| 02:12 | talios | or are those params the other way around. use (seq) to turn your list into a seq |
| 02:14 | clizzin | talios: hmm okay, so i guess nth only works on ISeq, but not on lists? |
| 02:14 | clizzin | Lists* as in the java interface |
| 02:17 | talios | ,(nth (Arrays/asList 4) 1) |
| 02:17 | clojurebot | java.lang.Exception: No such namespace: Arrays |
| 02:17 | talios | ,(nth (java.util.Arrays/asList 4) 1) |
| 02:17 | clojurebot | java.lang.ClassCastException: java.lang.Integer cannot be cast to [Ljava.lang.Object; |
| 02:17 | talios | ,(nth 1 (java.util.Arrays/asList 4)) |
| 02:17 | clojurebot | java.lang.ClassCastException: java.lang.Integer cannot be cast to [Ljava.lang.Object; |
| 02:17 | talios | ,(nth 1 (java.util.Arrays/asList "4")) |
| 02:17 | clojurebot | java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Object; |
| 02:18 | talios | ,(nth (java.util.Arrays/asList "4") 1) |
| 02:18 | clojurebot | java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Object; |
| 02:18 | talios | bah |
| 02:18 | talios | ,(nth (java.util.Arrays/asList ["4"]) 1) |
| 02:18 | clojurebot | java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to [Ljava.lang.Object; |
| 02:19 | talios | I *think* nth should work on lists mm |
| 02:19 | brehaut | ,(nth 2 (java.util.Arrays/asList (object-array 4))) |
| 02:19 | clojurebot | java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.lang.Number |
| 02:19 | brehaut | ,(nth 2 (seq (java.util.Arrays/asList (object-array 4))) |
| 02:19 | clojurebot | EOF while reading |
| 02:20 | brehaut | ,(nth 2 (seq (java.util.Arrays/asList (object-array 4)))) |
| 02:20 | clojurebot | java.lang.ClassCastException: clojure.lang.IteratorSeq cannot be cast to java.lang.Number |
| 02:20 | talios | ,(nth (java.util.Arrays/asList (object-array 4)) 2) |
| 02:20 | clojurebot | nil |
| 02:20 | brehaut | thats correct |
| 02:20 | brehaut | though difficult to tell if its meaningful ;) |
| 02:21 | talios | heh |
| 02:22 | brehaut | ,((juxt #(nth % 2) type) (into-array [1 2 3 4])) |
| 02:22 | clojurebot | [3 [Ljava.lang.Integer;] |
| 02:22 | brehaut | there you go |
| 02:23 | brehaut | hah almost |
| 02:24 | brehaut | ,((juxt #(nth % 2) type) (java.util.Arrays/asList (into-array [1 2 3 4]))) |
| 02:24 | clojurebot | [3 java.util.Arrays$ArrayList] |
| 02:25 | brehaut | so yes, nth does work on an arraylist |
| 02:50 | clizzin | talios, brehaut: oh i see, it only works on arraylists. that makes sense. |
| 02:50 | clizzin | thanks for the info |
| 02:50 | ossareh | (inc brehaut) |
| 02:50 | sexpbot | ⟹ 3 |
| 02:50 | brehaut | what was that for? |
| 02:50 | talios | does it? I would assume it works on all lists - creating an ArrayList was just easier |
| 02:50 | ossareh | brehaut: you got a thanks :) |
| 02:51 | brehaut | oh right. thanks ;) |
| 02:51 | brehaut | whats another list type/ |
| 02:51 | ossareh | also.. they're free. |
| 02:51 | brehaut | heh they are |
| 02:56 | brehaut | does doc metadata preceed or follow the symbol name in a def ? |
| 02:59 | ossareh | (doc def) |
| 02:59 | clojurebot | DENIED |
| 02:59 | brehaut | before |
| 02:59 | brehaut | http://clojure.org/special_forms |
| 03:00 | brehaut | ive written some extremely ugly code today. i think ive used 200% more loop / recur's that ive used in a few years of clojure |
| 03:57 | clizzin | anyone with experience with incanter know how i can make a histogram of string values? it seems like the histogram function only takes a seq of values as an argument |
| 04:04 | clizzin | well, i achieved what i wanted with the bar-chart, but i'm still not sure why histogram doesn't allow one to count non-number values, unless i'm somehow missing the meaning of a histogram |
| 05:37 | clgv | is there some way to include external information into leiningen? I want to add the name of my git branch automatically to the name of the uberjar if that is possible |
| 05:56 | fliebel | clgv: Found an answer yet? I think it is possible in Cake, using a custom uberjar task. |
| 05:57 | fliebel | Hm, I see room for a nice git integration in Cake :) That would give it a definite edge over Leiningen. |
| 06:21 | clgv | fliebel: no answer yet. but one insight maybe: project.clj seems to be "normal" clojure code. so maybe I can put a query in there |
| 06:24 | fliebel | clgv: That is certainly true. I always wondered why one does not need to (require 'lein) |
| 06:24 | fliebel | So it might be that it is parsed, but not executed. |
| 06:25 | clgv | humm that would be bad for me ;) |
| 06:27 | fliebel | http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/read |
| 06:28 | fliebel | clgv: Is cake an option for you? I'm sure it's possible with custom tasks. |
| 06:28 | clgv | fliebel: I don't know cake at all |
| 06:29 | fliebel | clgv: For the basics, you can substitute lein for cake. Only in things like plugins and tasks, they differ. |
| 06:30 | clgv | I just tried. lein evaluates the statements in the project.clj |
| 06:31 | fliebel | good for you :) |
| 06:38 | clgv | almost there. now I just need a clojure api function to allow me a system call^^ |
| 06:42 | fliebel | clgv: You mean like c.c.sh-utils? |
| 06:42 | clgv | maybe. I have to check that one |
| 06:43 | fliebel | clgv: http://clojure.github.com/clojure-contrib/shell-out-api.html |
| 06:59 | clgv | fliebel: found a way to display the git branch on command prompt :D |
| 06:59 | fliebel | yay |
| 07:02 | clgv | you can define a function like that: function parse_git_branch { git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' } in your .bash_profile or .bashrc and add a call to it to your PS1 string with \$(parse_git_branch) |
| 07:41 | edoloughlin | ,(clojure.contrib.prxml/prxml [:email_addr nil "x@x.x"]) |
| 07:41 | clojurebot | java.lang.ClassNotFoundException: clojure.contrib.prxml |
| 07:41 | edoloughlin | [sorry] |
| 07:41 | edoloughlin | Can I rely on clojure.contrib.prxml ignoring nils? |
| 07:42 | clgv | &(doc clojure.contrib.prxml/prxml) |
| 07:42 | sexpbot | java.lang.Exception: Unable to resolve var: clojure.contrib.prxml/prxml in this context |
| 07:44 | edoloughlin | The docs don't say explicitly what it should to. It suits me at the moment that they are ignored, but if this changes... |
| 07:44 | edoloughlin | s/should to/should do/ |
| 07:44 | sexpbot | <edoloughlin> The docs don't say explicitly what it should do. It suits me at the moment that they are ignored, but if this changes... |
| 07:45 | simard | can someone explain to me how this can be so fast ? http://pastebin.com/UfjWpmnY |
| 07:45 | simard | what part of it makes it lazy ? |
| 07:46 | DespiteItAll | isn't that just a single calculation? |
| 07:46 | opqdonut | err it's just some arithmetic |
| 07:47 | ejackson | yup |
| 07:47 | DespiteItAll | To explain it, we'll have to start with the and gate ... |
| 07:48 | simard | really, try to execute the (inc ) part |
| 07:48 | simard | without the mod |
| 07:48 | simard | err.. |
| 07:49 | opqdonut | oh, the arguments are _that_ way around |
| 07:49 | simard | ? |
| 07:49 | clgv | bit-shift-left seems to be lazy |
| 07:50 | clgv | ,(doc bit-shift-left) |
| 07:50 | clojurebot | "([x n]); Bitwise shift left" |
| 07:50 | simard | lol |
| 07:51 | simard | DespiteItAll: a single calculation that takes more than 2,357,207 digits |
| 07:51 | simard | in decimal notation.. |
| 07:51 | clgv | ,(let [res (time (bit-shift-left 2 7830))] (time (println res))) |
| 07:51 | clojurebot | "Elapsed time: 0.152 msecs" |
| 07:51 | clojurebot | 2322180878515618467227753412562314309284874158963514658990419680703090047433767329645678945457651316808130685891008617227656964655976736171725333342949155665795039199339390... |
| 07:52 | DespiteItAll | Ah, I made the same mistake as opqdonut, I thought you were shifting 7830456 2 places, rather than vice versa |
| 07:52 | simard | ,(let [res (time (bit-shift-left 2 7830))] (println res)) |
| 07:52 | clojurebot | "Elapsed time: 0.121 msecs" |
| 07:52 | clojurebot | 2322180878515618467227753412562314309284874158963514658990419680703090047433767329645678945457651316808130685891008617227656964655976736171725333342949155665795039199339390... |
| 07:52 | simard | ,(let [res (time (bit-shift-left 2 7830456))] (println res)) |
| 07:52 | simard | muhahahahaha |
| 07:52 | clgv | ,(let [res (time (bit-shift-left 2 7830)) s (time (str res))] res)) |
| 07:52 | clojurebot | "Elapsed time: 0.121 msecs" |
| 07:52 | clojurebot | "Elapsed time: 5.13 msecs" |
| 07:52 | clojurebot | 232218087851561846722775341256231430928487415896351465899041968070309004743376732964567894545765131680813068589100861722765696465597673617172533... |
| 07:53 | clojurebot | Execution Timed Out |
| 07:53 | simard | :) |
| 07:53 | simard | there you go |
| 07:53 | simard | clojurebot: I know, I know |
| 07:53 | clgv | ,(let [res (time (bit-shift-left 2 78300)) s (time (str res))] res)) |
| 07:53 | clojurebot | Pardon? |
| 07:53 | clojurebot | "Elapsed time: 0.125 msecs" |
| 07:53 | clojurebot | "Elapsed time: 521.3 msecs" |
| 07:53 | opqdonut | printing the number takes time |
| 07:53 | clojurebot | 89061598438411090916318627017045455133984151351210558738733007166540398817989858004057107529611021945023100752825293692502273699551641224071379... |
| 07:53 | clgv | nope evaluating the number takes the time as my example shows |
| 07:53 | Chousuke | what are you doing :P |
| 07:53 | opqdonut | "(do (inc (* 28433 (bit-shift-left 2 7830456))) 1)" is fast |
| 07:54 | opqdonut | and that shouldn't be lazy |
| 07:54 | simard | indeed |
| 07:54 | clgv | you care to look at the source? ;) |
| 07:55 | opqdonut | hmm? |
| 07:56 | clgv | hmm it's just an adapter for the java implementation in Numbers |
| 07:56 | opqdonut | hmm, weird |
| 07:56 | simard | opqdonut: there you go |
| 07:56 | simard | :) |
| 07:56 | opqdonut | anyway, (def a (atom nil)) (do (swap! a (constantly (inc (* 28433 (bit-shift-left 2 7830456))))) 1) is also fast |
| 07:56 | opqdonut | no chance of laziness there |
| 07:56 | opqdonut | it's just the printing. |
| 07:57 | simard | opqdonut: sounds correct |
| 07:57 | clgv | hm well its getting pretty long indeed ;) |
| 07:59 | simard | it makes sense because after the mod is applied, there is only 10 digits to output, not 2,300,000. well I was pretty impressed at the speed of this calculation, and I thought perhaps that mod function could have a deeper meaning, but it doesn'T |
| 08:00 | simard | the first way I did the calculation was by applying modulo at each step, and I was considering perhaps mod was some clever macro that did a similar trick |
| 08:00 | clgv | but you should consider if your formula does allow to apply the mod earlier to speed up calculation |
| 08:00 | simard | clgv: I did that |
| 08:00 | jcromartie | hey LauJensen looks like on http://clojureql.org/examples.html the "Distinct" example code is wrong |
| 08:00 | jcromartie | should be (defn distinct [table] (modify table :distinct)) no? |
| 08:00 | clgv | simard: you can provide both timings? |
| 08:01 | simard | clgv: gimme a moment, I recall it was slower though.. perhaps I shouldn't apply mod at EVERY step |
| 08:02 | simard | (I was doing it by hand, let me try with modPow from bigint) |
| 08:09 | clgv | fliebel: got leining to use git branch and date in the name of the jars :D |
| 08:09 | fliebel | nice :) |
| 08:10 | simard | clgv: http://pastebin.com/z4y4KwBS |
| 08:10 | simard | there you go |
| 08:10 | simard | much faster with a modPow |
| 08:11 | clgv | definitely^^ |
| 08:11 | simard | :) |
| 08:11 | simard | as one would expect.. |
| 08:11 | clgv | well I guess you could be faster without using bigint at all ;) |
| 08:12 | clgv | but the question is if it is worth the effort |
| 08:14 | simard | well I'm doing this for fun anyway |
| 08:14 | simard | so.. maybe ;) |
| 08:15 | simard | what I would find interesting is a mod macro that takes normal math operations and makes the mod automatically |
| 08:16 | clgv | sounds fun. ;) |
| 09:34 | TimMc | devn: I am successfully using emacs! |
| 09:52 | dmiles_afk | ,(def (mod a b) (- a (* (/ a b) b))) |
| 09:52 | clojurebot | DENIED |
| 09:52 | dmiles_afk | thats correct syntax though right? |
| 09:53 | dmiles_afk | ,(def (mymod a b) (- a (* (/ a b) b))) |
| 09:53 | clojurebot | DENIED |
| 09:53 | opqdonut | no |
| 09:53 | opqdonut | (defn mymod [a b] (- a (* (/ a b) b))) |
| 09:53 | opqdonut | if you want a function |
| 09:56 | Kjellski | ping? |
| 09:56 | clojurebot | PONG! |
| 09:57 | jonkratz | pastie: hi! |
| 09:57 | jonkratz | ping? |
| 09:57 | clojurebot | PONG! |
| 10:01 | Sgeo | I'm not bothering to learn Clojure, but I do have a quick question |
| 10:01 | Sgeo | In Racket, I can do (send* someobject (onemethod) (anothermethod) (yetanothermethod)) |
| 10:01 | Sgeo | I think |
| 10:02 | Sgeo | Is there something similar in Clojure> |
| 10:05 | joly | maybe doto would fit? |
| 10:05 | joly | ,(doc doto) |
| 10:05 | clojurebot | "([x & forms]); Evaluates x then calls all of the methods and functions with the value of x supplied at the front of the given arguments. The forms are evaluated in order. Returns x. (doto (new java.... |
| 10:05 | cemerick | or ->, depending on the semantics of send* |
| 10:05 | clgv | or -> |
| 10:08 | shanmu | Hi, is there any example on using ring jetty adapter with a custom jetty xml file? |
| 10:09 | shanmu | or is it meant to be passed in via :configurator? |
| 10:12 | clgv | fliebel: as a resultat of exchanging the hash-map I used with the double array, I got a speedup of 0.2 seconds thats approx. 25% |
| 10:12 | fliebel | clgv: ? |
| 10:12 | clgv | fliebel: the performance tuning I was talking about here the last weeks ;) |
| 10:13 | fliebel | ah :) |
| 10:20 | shanmu | I think I got the answer to my q. http://communitymapbuilder.org/display/JETTY/Embedding+Jetty gives a java example of how to do it - and it needs to be passed in as the configuration to run-jetty |
| 10:57 | sritchie_ | hey all -- does any notion exist in clojure, or some other language, of an invertible function? |
| 10:57 | sritchie_ | meaning -- could I define (defn add5 [x] (+ 5 x)), and run it backwards, without having to explicitly define the inverse? |
| 11:00 | spewn | sritchie_: J has this: http://jsoftware.com/help/dictionary/intro11.htm |
| 11:00 | spewn | I imagine the entire APL/J/K family does; not sure of any other languages that do. |
| 11:01 | sritchie_ | spewn: hey, very cool |
| 11:11 | jcromartie | so can I use ClojureQL as a "data store?" |
| 11:12 | jcromartie | like, say, (def *users* (table :users)) |
| 11:12 | jcromartie | then I can conj! and disj! |
| 11:12 | jcromartie | nice |
| 11:27 | fliebel | dnolen: I wrote a macro that lets you define full-adder-o for any base :) |
| 11:50 | shanmu | hi, this may be a basic question, but how would I get to use a java instance mehtod as a clojure function (to pass as an argument to a another clojure function)? |
| 11:50 | clgv | you'll have to build a wrapper afaik |
| 11:51 | raek | shanmu: you need to make a clojure function like this: #(.method %) |
| 11:51 | shanmu | raek: ah, thanks! |
| 11:52 | raek | in java, methods are not objects so you need something like this |
| 11:52 | shanmu | yes... that's where I hit the wall |
| 11:52 | shanmu | #() ensures that it does not get evaluated |
| 11:53 | cemerick | shanmu: #() is an anonymous function literal |
| 11:53 | raek | yes, it's syntactic sugar for (fn [obj] (.method obj)) |
| 11:53 | naeu | So what's the current way of creating an executable jar with cake? I declared a :main namespace in the project.clj and inserted (:gen-class) in the namespace declaration. I then did a cake uberjar, and when I try and run it it can't find the class I specified as my main class... |
| 11:54 | shanmu | cemerick: yes, thanks! I just thought aloud the place where I got stuck without using the anon function :) |
| 11:54 | naeu | I'm happy to be pointed to some relevant documentation.... |
| 11:54 | shanmu | this is all connected to passing a custom jetty config to ring jetty adapter |
| 12:10 | shanmu | Is there any documentation on integrating jaas with a ring webapp - I need to pass the jetty-web.xml to get access to the principal from within the webapp..is there any way to do it using ring? |
| 12:15 | fliebel | dnolen: ping |
| 12:20 | bsteuber | user> (class (int 42)) |
| 12:20 | bsteuber | java.lang.Long |
| 12:20 | bsteuber | shouldn't this be int? |
| 12:21 | Chousuke | bsteuber: it gets boxed and promoted in the process I guess. |
| 12:21 | bsteuber | seems very weird to me |
| 12:22 | fliebel | bsteuber: Which version do you use? |
| 12:22 | bsteuber | 1.3-alpha-4 |
| 12:22 | bsteuber | so if it changes before 1.3 is't ok :) |
| 12:23 | fliebel | bsteuber: In 1.3, you should use ##(class (Integer. 23)) |
| 12:23 | sexpbot | ⟹ java.lang.Integer |
| 12:23 | bsteuber | the thing is, I have an int value from java and want to give it back to java |
| 12:23 | bsteuber | and now I get problems because it's suddenly a long |
| 12:25 | fliebel | bsteuber: What are you doing to with in Clojure space? AS Chousuke said, numbers get promoted to long in 1.3. |
| 12:25 | bsteuber | basically nothing, I'm just wrapping a java library and don't want to write Label/CONTENT_XHTML etc |
| 12:26 | fliebel | weird... |
| 12:26 | bsteuber | but ok, I will write (def xhtml (Integer. Label/CONTENT_XHTML)) |
| 12:27 | bsteuber | just felt so strange to me :) |
| 12:27 | bsteuber | thanks |
| 12:27 | timvisher | hi all |
| 12:30 | timvisher | i'm looking for an hour long sales pitch for why anyone should care about Functional Programming. Something that would back up M. Halloway's assertion that Functional Decomposition is generally supperior to Object Oriented Decomposition with mutable state |
| 12:31 | Adamant | 1. parallelism |
| 12:31 | Adamant | 2. (potential) security |
| 12:31 | Adamant | 3. reliability |
| 12:32 | Adamant | 4. more mathematical tools being applicable |
| 12:32 | Adamant | (OOD with mutable state is hard to mathematically model) |
| 12:33 | Adamant | when in doubt, emphasize our multicore future |
| 12:34 | apgwoz | what's the recommended parsing tool for when sexps aren't appropriate? fnparse? |
| 12:35 | chouser | "when sexps aren't appropriate"!? heresy! |
| 12:35 | apgwoz | chouser: i know, i know. there should be no other language! |
| 12:35 | chouser | :-) |
| 12:36 | chouser | I still haven't tried anything except ANTLR (which I wouldn't generally recommend), but there's also cgrand's parsely |
| 12:38 | raek | timvisher: a purely functional progam never has problems with action-at-distance. mutable state is the new everything in global variables |
| 12:38 | apgwoz | chouser: i'll have to look more closely at parsely. thanks for the tip |
| 12:38 | timvisher | Adamant: I'm not actally trying to sell Clojure. It's for a Functional Programming Lunch Study group. Last time we basically came to the conclusion that while we all 'sense' that FP is awesome, but none of us can really articulate why |
| 12:39 | timvisher | We're all long time OO people so it's a big jump for us |
| 12:39 | Adamant | timvisher: those apply to more than just Clojure |
| 12:39 | Adamant | they're a general property of most full scale FP languages |
| 12:39 | timvisher | I know |
| 12:39 | Adamant | ah, just looking for general resources? |
| 12:39 | timvisher | But the Multicore doesn't necessarily, except that non-mutable state is freely shareable |
| 12:39 | Adamant | you could try mining The Simon's |
| 12:39 | Adamant | of Haskell fame |
| 12:39 | Adamant | lots of papers on the advantages and disadvantages there |
| 12:40 | Adamant | (Simon Marlow And Simon Peyton-Jones) |
| 12:40 | timvisher | raek: agreed, I'd just love to be able to find a paper, blog, or video where someone in a language agnostic way, defines why FP is 'better' than OO in certain (many?) contexts |
| 12:41 | timvisher | Adamant: I could look into them. Any recommendation on where to start? |
| 12:42 | Adamant | their websites and early "FP is awesome, pay attention" papers |
| 12:42 | Adamant | IIRC both of them are out of MS Research currently |
| 12:42 | bsteuber | timvisher: to me, the main point seems to be composability |
| 12:43 | bsteuber | that is similar on large and small scales |
| 12:43 | timvisher | bsteuber: That's definitely a huge point that all of us see and none of us seem to understand |
| 12:43 | raek | http://www.cse.chalmers.se/~rjmh/Papers/whyfp.pdf |
| 12:43 | raek | "Why Functional Programming Matters" |
| 12:44 | timvisher | raek: thanks, that looks very interesting |
| 12:45 | dnolen | fliebel: pong. Cool about the full-adder-o for any base! |
| 12:47 | technomancy | clojurebot: google out of the tarpit |
| 12:47 | clojurebot | First, out of 21200 results is: |
| 12:47 | clojurebot | Out of the Tar Pit |
| 12:47 | clojurebot | http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.93.8928&rep=rep1&type=pdf |
| 12:47 | technomancy | timvisher: I recommend the above |
| 12:48 | timvisher | technomancy: thought that was for me. ;) |
| 12:49 | timvisher | alright, i should start paying attention to this Ruby presentation again. Thanks for the pointers, everyone! |
| 12:52 | amalloy | sritchie_: prolog has inverse-ish stuff, iirc |
| 12:54 | sritchie_ | amalloy: interesting, I've been meaning to look at prolog. I'm using cascalog, and it'd be nice to understand the basis for some of the cascalog decisions |
| 12:58 | ejackson | the world seems to be getting in logic programming - why is this ? |
| 13:00 | fliebel | ejackson: The whole world, as in other people than you, me and dnolen? |
| 13:00 | ejackson | not me ! I just dabbled to try figure out what was going on. |
| 13:00 | ejackson | but it was too hard for me :) |
| 13:00 | fliebel | ejackson: I thought you read TRS... |
| 13:00 | amalloy | ejackson: if it makes you feel better i'm just repeating what i vaguely remember from senior year :P |
| 13:01 | Cozey | $findfn ['(:a 2) '(:b 5)] {:a 2 :b 5} |
| 13:01 | sexpbot | [] |
| 13:01 | amalloy | Cozey: ##(into {} [[:a 2] [:b 5]]) |
| 13:01 | sexpbot | ⟹ {:a 2, :b 5} |
| 13:01 | danbell | '(doc hash-map) |
| 13:01 | danbell | ,(doc hash-map) |
| 13:01 | clojurebot | "([] [& keyvals]); keyval => key val Returns a new hash map with supplied mappings." |
| 13:01 | amalloy | note that the pairs have to be vectors, not lists: vectors are special |
| 13:02 | amalloy | or do it danbell's way: ##(apply hash-map (apply concat ['(:a 2) '(:b 5)])) |
| 13:02 | sexpbot | ⟹ {:a 2, :b 5} |
| 13:03 | Cozey | mm I did apply array-map (mapcat ... |
| 13:03 | danbell | i like amalloy's way better |
| 13:03 | Cozey | into is nice |
| 13:04 | amalloy | (into {} ...) is so common it really should have its own name |
| 13:04 | Cozey | I never used it but instantly see so many places asking to change into into |
| 13:04 | fliebel | dnolen: In adder-o, they check for (== '(1) n), which is fine for binary, but doesn't work for decimal. I think I can replace 1 with a fresh variable. Does that sound correct? And, is Logos trampolining somewhere, or do I need to avoid stack overflows myself? |
| 13:05 | amalloy | heh |
| 13:10 | danbell | ,(doc into) |
| 13:10 | clojurebot | "([to from]); Returns a new coll consisting of to-coll with all of the items of from-coll conjoined." |
| 13:23 | dnolen | fliebel: I'm not sure about the arithmetic stuff, I only browsed that part of the book. And no, you don't need to worry about stack overflow w/ recursive miniKanren programs if that's what you're asking. |
| 13:24 | fliebel | okay, I'll just try and test. |
| 13:31 | fliebel | dnolen: Does a vector unify with a list? |
| 13:32 | fliebel | apparently: (run* [q] (== '() q) (== [] q)) => (()) |
| 13:34 | dnolen | fliebel: you're unifying an empty list w/ an empty vector, so you're going to get back and empty list. |
| 13:34 | dnolen | fliebel: I think order matters in this case, try the reverse unify a vector w/ an empty list |
| 13:35 | fliebel | dnolen: A list of empty lists. (run* [q] (== '(1) q) (== [1] q)) => ((1)), (run* [q] (== [1] q) (== '(1) q)) => ([1]) |
| 13:36 | dnolen | fliebel: yeah that's what I'd expect. |
| 13:36 | fliebel | so yea, the result is different, but I can use vectors in place of this ufly quoting. |
| 13:36 | fliebel | *ugly |
| 13:38 | fliebel | hm, is `(,a . ,x) the same as (lcons a x)? |
| 13:41 | dnolen | fliebel: no. Clojure doesn't support pairs. |
| 13:41 | fliebel | dnolen: So what do I do with them? |
| 13:41 | dnolen | fliebel: er, I mean yes, that is the correct translation. |
| 13:42 | fliebel | right :) *holds breath* |
| 13:42 | dnolen | fliebel: also see llist. (llist 'a 'b 'c x), where x is a logic var. |
| 13:42 | fliebel | dnolen: Is that like (a b c . d)? |
| 13:42 | dnolen | fliebel: yes. |
| 13:43 | fliebel | I did a nested lcons for that so far. will replace |
| 13:47 | fliebel | uh-oh, something isn't right… (run* [q] (adder-o 0 [1] [1 0 1] q)) => ((0 0 1) (0 1 1)) decimal is even more broken :( |
| 13:48 | LauJensen | jcromartie: Thanks for the heads up |
| 13:49 | jcromartie | yup |
| 13:49 | dnolen | fliebel: whenever you think you've found another bug, create an issue with the code and the actual output vs the expected output. |
| 13:50 | jcromartie | LauJensen: I am really "getting" ClojureQL now... treating tables and queries as something to be dereferenced |
| 13:50 | fliebel | dnolen: I'll trace my own logic first. I might have brokens something while converting. |
| 13:50 | LauJensen | jcromartie: liking it ? |
| 13:50 | jcromartie | yes |
| 13:50 | jcromartie | seems like a very pure way to interact with SQL |
| 13:50 | LauJensen | Great, thanks for the feedback |
| 13:50 | ejackson | i'll second the motion, ClojureQL rocks out. |
| 13:50 | LauJensen | :D |
| 13:50 | jcromartie | strikes me as very close to relvars from "Tar Pit" |
| 13:51 | jcromartie | but still in the "accidental" realm :P |
| 13:51 | fliebel | dnolen: I think it's the fresh var I added. I'll check that. |
| 14:06 | dmiles_afk | Can ClojureCLR register event handlers? |
| 14:08 | fliebel | Man, decimal is so much easier to reason about... |
| 14:12 | brehaut | whats the syntax to get opening and closing square bracket chacters into a regexp character class? |
| 14:15 | LauJensen | brehaut: the syntax is: dont use regex |
| 14:16 | brehaut | LauJensen: that was my solution too |
| 14:16 | brehaut | ive been asked to rewrite the code with them |
| 14:16 | mids | ,(re-find #"\[xyz\]" "abc[xyz]t") |
| 14:16 | clojurebot | "[xyz]" |
| 14:16 | mids | like that? |
| 14:16 | fliebel | dnolen: This appears to work! https://github.com/pepijndevos/logos/commit/d844d245655a14579ead376b244053b08d2d479c |
| 14:17 | brehaut | ,(re-find #"[\[\]]" "[") |
| 14:17 | clojurebot | "[" |
| 14:17 | brehaut | huh |
| 14:17 | brehaut | i was using too many \'s |
| 14:18 | dnolen | fliebel: cool! look forward to checking that out :) |
| 14:19 | fliebel | dnolen: I'll implement devision and multiplication another day, as well as a way to switch between bases, and some tests. |
| 14:19 | fliebel | dnolen: I welcome any comments :) |
| 14:21 | fliebel | My feeling is that binary is faster than decimal, because decimal has 200 cond-e clauses, but I'll have to test that. ;) |
| 14:21 | dnolen | fliebel: looks pretty good to me. I've been reading through pattern-matcher miniKanren paper, hoping to work those ideas in the next couple sweeks. miniKanren programs become much more concise . |
| 14:21 | dnolen | fliebel: ha |
| 14:22 | fliebel | dnolen: What does the pattern matcher do? |
| 14:24 | dnolen | fliebel: think Clojure destructuring - but more sophisticated, it automatically creates vars and does unification. |
| 14:24 | fliebel | oh! |
| 14:24 | dnolen | vars -> logic vars I mean. |
| 14:25 | fliebel | dnolen: Any examples yet? |
| 14:28 | dnolen | fliebel: the first part of adder-o would look something like this, https://gist.github.com/839192 |
| 14:28 | zanes | |
| 14:29 | fliebel | dnolen: That hurts, and rocks! |
| 14:30 | ounce | hi |
| 14:30 | amalloy | brehaut: java's regex engine isn't entirely perl-compatible. [][] is supposed to match open or close square brackets, but it doesn't |
| 14:31 | fliebel | dnolen: After second thought, it just rocks. |
| 14:32 | fliebel | dnolen: This is the stuff that is in prolog.clj, right? |
| 14:33 | dnolen | fliebel: that's not working code, just sketches on a reasonable Clojure syntax. |
| 14:33 | fliebel | I know |
| 14:37 | brehaut | amalloy: just another facet of the delightful world of regexp |
| 14:41 | amalloy | brehaut: c'mon, [][] is pure gold |
| 14:41 | brehaut | amalloy: no doubt |
| 14:43 | brehaut | what is the idiomatic way of testing a string for emptyness? |
| 14:43 | brehaut | (seq "") |
| 14:43 | brehaut | ? |
| 14:44 | mrBliss | brehaut: I usually use (empty? "") |
| 14:45 | brehaut | sorry, i got myself backwards. non-emptyness |
| 14:46 | amalloy | brehaut: i use seq |
| 14:46 | amalloy | eg ##(filter seq ["test" "" "empty"]) |
| 14:46 | sexpbot | ⟹ ("test" "empty") |
| 14:47 | fliebel | &(zero? (.length "")) |
| 14:47 | sexpbot | ⟹ true |
| 14:47 | dnolen | i wouldn't use seq on string unless you know you're not going to test empty-ness non-emptyness often. It's like 25X slower than just checking (.length s) |
| 14:48 | brehaut | dnolen: ok thanks |
| 14:49 | dnolen | brehaut: clojure.string/blank? |
| 14:49 | dnolen | (doc clojure.string/blank?) |
| 14:49 | amalloy | brehaut: time to go point-free with (comp pos? (memfn length))? |
| 14:49 | clojurebot | I don't understand. |
| 14:49 | dnolen | ,(doc clojure.string/blank?) |
| 14:49 | clojurebot | I don't understand. |
| 14:49 | dnolen | erg |
| 14:49 | amalloy | dnolen: clojure.string isn't loaded, so the doc macro results in a read error |
| 14:50 | amalloy | ,(require 'clojure.string) |
| 14:50 | clojurebot | nil |
| 14:50 | amalloy | (doc clojure.string/blank?) |
| 14:50 | clojurebot | "([s]); True if s is nil, empty, or contains only whitespace." |
| 14:51 | brehaut | im just going to use (> (.length s) 0) |
| 14:51 | brehaut | i need to trim the string anyway |
| 14:52 | amalloy | boo |
| 14:54 | brehaut | amalloy: ive already been asked to revise my code to make it simplier and shorter, im not going to go complicating it with point free ;) |
| 14:56 | Dranik | sorry I was disconnected |
| 14:56 | Dranik | so once again: how to compile leiningen project? |
| 14:56 | jweiss | can someone recommend a way to do list comprehension and also have access to the index of the list item you're on? |
| 14:57 | jweiss | i suppose loop with nth is one way, but that seems ugly |
| 14:58 | brehaut | (for [[x i] (map vec s (range))] [x i]) ? |
| 14:58 | noidi | or you can use clojure.contrib.seq/indexed |
| 14:58 | noidi | (for [[i x] (indexed [:a :b :c])] [i x]) |
| 15:00 | brehaut | or (for [[i x] (map-indexed vector [:a :b :c])] [i x]) |
| 15:02 | jweiss | brehaut: thanks, map-indexed is pretty handy |
| 15:08 | amac | anyone familiar with aleph know how to pull POST data out of a request? |
| 15:09 | fliebel | amac: Aleph is just Ring, right? |
| 15:10 | amac | I'm pretty sure it uses ring, yeah |
| 15:10 | fliebel | amac: It's :query-string I guess: https://github.com/mmcgrana/ring/blob/master/SPEC |
| 15:10 | amac | that pulls get data only :( |
| 15:11 | amac | post data seems to be locked in the :body as a bytebuffer... can't seem to get the data out though, nor am I even sure that's actually the post data |
| 15:13 | raek | amac: I think wrap-params handle this: http://clojuredocs.org/ring/ring.middleware.params/wrap-params |
| 15:14 | raek | if the post data is url-encoded (e.g. from a html form) then I think the data ends up in :form-params and :params |
| 15:21 | amac | raek: that looks like the ticket, specifically assoc-form-params in that middleware shows how they pull the data out. Thanks! :D |
| 15:31 | clizzin | let's say that when my program gets an http request, i want it to spawn a long-running thread and immediately send back an http response without waiting for the thread to finish. what's the most idiomatic way to do this in clojure? a future that's never dereferenced? a plain old java thread? something else? |
| 15:32 | chouser | a future that's never dereferenced is pretty common |
| 15:32 | jweiss | hrm. appears that i cannot use a macro to generate defn forms that have metadata on the symbol. will using def let me throw in (with-meta)? |
| 15:33 | jweiss | i mean, my macro will let me use the reader macro ^, but that only lets me put hardcoded metadata in there, instead of being able to pass it to my macro. |
| 15:35 | brehaut | jweiss: (with-meta value meta-dict) |
| 15:36 | brehaut | oh, you mentioend taht already; my bad |
| 15:36 | jweiss | brehaut: can't do that, try (defn (with-meta mysym {}) [] (println "hi")) |
| 15:36 | jweiss | says first arg to def must be a symbol. |
| 15:36 | raek | jweiss: (defmacro defstuff [name foo bar] `(defn ~(with-meta name ...) ...)) |
| 15:36 | brehaut | actually |
| 15:36 | brehaut | what raek said |
| 15:37 | raek | jweiss: what does your macro look like? |
| 15:37 | amalloy | why do you want meta on the symbol instead of the var? |
| 15:38 | jweiss | amalloy: um, when you use the reader macro, it goes on the symbol, no? |
| 15:39 | amalloy | jweiss: not as far as i can tell |
| 15:39 | amalloy | (defn ^{:private true} testfn []),,,,(meta #'testfn) |
| 15:40 | jweiss | amalloy: what do you think that does |
| 15:40 | jweiss | i thought it places the meta on the next symbol |
| 15:40 | jweiss | which is testfn |
| 15:40 | amalloy | jweiss: your point is that the meta is attached to testfn before the form is evaluated, and that defn copies it from the symbol to the var? |
| 15:41 | jweiss | amalloy: i guess so, hadn't really thought about that :) |
| 15:41 | amalloy | neither had i |
| 15:41 | jweiss | is there a way to put it on the var directly? |
| 15:42 | jweiss | raek, i want my generated defn's meta to include meta from another fn, which i pass in. |
| 15:42 | jweiss | i don't think i can get to that at compile time, so i have to create code that evaluates at runtime... i think :) |
| 15:43 | amalloy | jweiss: actually attaching it to the symbol seems to work too |
| 15:43 | amalloy | (defmacro def-private [name & body] `(defn ~(with-meta name {:private true}) ~@body)) |
| 15:43 | jweiss | yeah, if you use defn and the reader macro |
| 15:43 | jweiss | amalloy: but that only works with data that's available at compile time |
| 15:44 | jweiss | i don't know that the meta of my argument is available then |
| 15:44 | jweiss | i |
| 15:44 | clizzin | chouser: thanks! |
| 15:44 | jweiss | am pretty sure it isn't. |
| 15:44 | amalloy | jweiss: what is the point of defn'ing a var that you don't know about at compile time? nobody will ever access it by name then |
| 15:44 | raek | ,(doc defn) |
| 15:44 | clojurebot | "([name doc-string? attr-map? [params*] body] [name doc-string? attr-map? ([params*] body) + attr-map?]); Same as (def name (fn [params* ] exprs*)) or (def name (fn ([params* ] exprs*)+)) with any do... |
| 15:44 | jweiss | amalloy: well, it's known at compile time, i just don't know how to get it :) |
| 15:45 | raek | the map at the attr-map place will also be merged into the metadata |
| 15:45 | amalloy | i suggest that you address that issue then, instead of trying to declare functions at runtime :P |
| 15:46 | jweiss | amalloy: ok so if i pass my macro a symbol that's an existing function, how do i copy the meta of that function to the one i'm generating :) |
| 15:46 | amalloy | don't do it that way. you want to define N functions that all have the same meta, right? |
| 15:46 | jweiss | amalloy: no, the meta is different for each one. |
| 15:47 | amalloy | then...you don't want to copy meta. what do you want to do? |
| 15:48 | jweiss | amalloy: i was just trying to simplify the problem for you. i want to merge the meta with a bit more data (let's say if i'm generating 10 defns, the index of it, 0,1...10) |
| 15:49 | amalloy | so you want something like (def-indexed (^:private foo [n] body) (^{:arglists []} bar [] body)) |
| 15:50 | amalloy | essentially, instead of calling your magic macro ten times, have your macro wrap ten defns |
| 15:50 | amalloy | then it can do the counting itself |
| 15:58 | jweiss | amalloy: that's what i was doing. the problem is taking the symbol i pass in and getting the meta from it, kept getting nil |
| 15:59 | jweiss | oh... hm. i might see why that was happening |
| 15:59 | amalloy | jweiss: i just wrote it. gisting momentarily |
| 16:00 | amalloy | jweiss: https://gist.github.com/3d5d85f19505295c9a32 |
| 16:01 | raek | jweiss: do you want metadata from an already defined var? in that case, you need (meta #'foo) or (meta (resolve 'foo)) |
| 16:02 | jweiss | raek: aha, yes, i need that |
| 16:02 | jweiss | amalloy: nice hint with vary-meta |
| 16:02 | jweiss | i think between those two suggestions i'll get it |
| 16:04 | raek | the fact that 'def' copies metadata from the symbol to the new var might make the matter confusing here. the symbol 'foo and the var #'foo are not the same thing. |
| 16:05 | jweiss | raek: yeah, until amalloy mentioned it, i never thought about how it got from one place to the other. |
| 16:19 | _schulte_ | Adding slime support for common lisp, totally broke slime-connect for connecting to a lein swank session, does anyone have this working (i.e. clj and cl) who can suggest a workaround? |
| 16:35 | joegallo | If I send-off and then immediately await on an agent, and the sent-off function throws an exception, then my program appears to hang on the await. Even though the agent ends up failed after the sent-off function is executed -- my await snuck in beforehand. Am I doing it wrong? |
| 16:38 | amalloy | &(let [a (agent 0)] (send-off a #(throw (Exception. "test"))) (Thread/sleep 1000) (await a)) |
| 16:38 | sexpbot | java.lang.IllegalArgumentException: Wrong number of args (1) passed to: sandbox6385$eval13022$fn |
| 16:39 | amalloy | joegallo: hm. that is weird behavior, and i can reproduce it. i think there's an option you can set on your agent, somewhere |
| 16:41 | Despite1 | I think the await docs say that will happen |
| 16:41 | amalloy | Despite1: they do, but it doesn't seem to happen if you don't await until after the exception has been thrown |
| 16:41 | jcromartie | "Will block on failed agents." |
| 16:42 | amalloy | jcromartie: (await a), when a is an agent that has already failed, throws an exception |
| 16:43 | amalloy | if a is an agent that hasn't failed, but will, it blocks |
| 16:43 | Despite1 | oh interesting |
| 16:43 | Despite1 | Makes a bit of sense |
| 16:46 | joegallo | okay, i see. that makes lots of sense. |
| 16:47 | joegallo | at least, in terms of the docs... |
| 16:48 | technomancy | _schulte_: I don't know, but if you figure it out I would love to get a patch documenting that. |
| 17:08 | TimMc | ,^{:single}[] |
| 17:08 | clojurebot | java.lang.ArrayIndexOutOfBoundsException: 1 |
| 17:09 | TimMc | ,{:single} |
| 17:09 | clojurebot | java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: 1 |
| 17:09 | TimMc | Interesting that those throw array index exceptions. I would expect something more informative. :-/ |
| 17:11 | amalloy | ,(hash-map :a) |
| 17:11 | clojurebot | java.lang.IllegalArgumentException: No value supplied for key: :a |
| 17:12 | LauJensen | TimMc: You expected an informative error message? You must be new here, welcome to #clojure :) |
| 17:57 | dnolen | huh, anybody use dynamic binding for flow-control? like (binding [*some-continuation* (fn ...)] ...) |
| 18:00 | rata_ | hi |
| 18:01 | rata_ | how do I really force cake to recompile and install a jar of my project? |
| 18:01 | rata_ | I've tried with "cake compile force; cake install" but it doesn't work |
| 18:01 | amalloy | rata_: cake clean && cake install? |
| 18:01 | rata_ | amalloy: doesn't work |
| 18:03 | amalloy | rm -f *.jar && cake install :P |
| 18:06 | rata_ | amalloy: doesn't work either |
| 18:07 | rata_ | do I need to do something special at the project that's using this other project? |
| 18:08 | rata_ | (beside "cake kill && cake swank") |
| 18:09 | amalloy | rata_: cake deps |
| 18:10 | amalloy | possibly cake deps force; the deps stuff never made any sense to me |
| 18:11 | rata_ | ok, I'll try that |
| 18:12 | rata_ | is there a way to tell cake just refetch one dep? |
| 18:14 | rata_ | amalloy: thanks a lot! cake deps force is what I was missing |
| 18:14 | dnolen | hmm was there ever any talk around scopes concerning preserving bindings for lazy computations ? |
| 18:14 | rata_ | it'd be nice if project-local jars were just links to the maven repo |
| 18:15 | amalloy | dnolen: there was certainly talk about it |
| 18:15 | amalloy | i didn't pay much attention, but i think the general opinion was it was a bad idea |
| 18:15 | dnolen | amalloy: link to relevant irc or ML conversation? |
| 18:16 | amalloy | dnolen: fraid not. your google will be as good as mine for this one |
| 18:16 | amalloy | it was on ml though, not irc |
| 18:16 | dnolen | amalloy: any recollection on why people thought it was a bad idea? |
| 18:19 | amalloy | ummmm, not really. i'm not even sure that was the eventual decision; i might be getting it confused with keeping resources open in scopes |
| 18:20 | amalloy | dnolen: aha, i think it's http://groups.google.com/group/clojure-dev/browse_thread/thread/627b2aaa59329d04 |
| 18:24 | rata_ | amalloy: do you know if there's a way to tell cake to refetch just one dep? |
| 18:24 | amalloy | i don't think there is, but i'm not a cake dev |
| 18:27 | dnolen | amalloy: thx for the link, there's nothing there about it being a bad idea tho, in fact stuartsierra's saying scopes could possibly solve it. |
| 18:27 | stuartsierra | eh, what/ |
| 18:27 | stuartsierra | ? |
| 18:28 | dnolen | stuartsierra: http://groups.google.com/group/clojure-dev/browse_thread/thread/627b2aaa59329d04 |
| 18:31 | stuartsierra | oh, that |
| 18:46 | dnolen | hmm can only vars installed by the runtime be changed with set! ? |
| 18:47 | rata_ | dnolen: iirc just binding'ed vars |
| 18:48 | dnolen | rata_: so things like *warn-on-reflection* and *unchecked-math* are exceptions? |
| 18:48 | rata_ | dnolen: I don't know |
| 18:49 | rata_ | just something I read in clojure.org (iirc, again) |
| 18:56 | amalloy | dnolen: http://clojure.org/Vars#Vars%20and%20the%20Global%20Environment--%28set!%20var-symbol%20expr%29 |
| 18:57 | amalloy | what i get from that is that you have to give the var a root value before you can set! it thread-locally |
| 18:58 | amalloy | but that there are no "exceptions" for certain vars |
| 19:02 | dnolen | amalloy: this doesnt seem to work (do (def ^:dynamic *some-flag* nil) (set! *some-flag* true)) |
| 19:05 | amalloy | dnolen: (binding [*some-flag* nil] (set! *some-flag* true) *some-flag*) |
| 19:06 | amalloy | not really sure why this works, but it does |
| 19:06 | dnolen | amalloy: but you don't need to do what with *warn-on-reflection*, I suppose the compiler does something behind the scenes. |
| 19:07 | amalloy | i suspect that *w-o-r* works because the repl establishes a binding for it |
| 19:07 | amalloy | (not necessarily the compiler) |
| 19:08 | dnolen | related, now that you have binding conveyance, is it not possible to fork a thread with a binding, and compute a lazy sequence in that thread? |
| 19:08 | dnolen | thus avoiding the lazy-sequence can't see the binding? |
| 19:08 | dnolen | or rather the binding goes out of scope I mean. |
| 19:13 | gfrlog | Is http.async.client the thing to use for doing that? |
| 19:17 | dnolen | hmm, lazy-sequences are always computed on the main-thread ... |
| 19:17 | dnolen | ,(let [t (future (repeatedly #(.getId (Thread/currentThread))))] (println "id:" (.getId (Thread/currentThread))) (println (take 1 @t))) |
| 19:17 | clojurebot | id: 616 |
| 19:17 | clojurebot | (616) |
| 20:00 | danbell | is there a way to have swank-clojure execute the (ns (:use), etc.) statement of the .clj file you're editing in emacs? |
| 20:03 | amalloy | danbell: C-c C-k loads the whole file, including ns stuff. to change the namespace the prompt is "in", C-c M-p |
| 20:05 | danbell | amalloy: oh hey, it worked! Thanks! |
| 20:35 | david` | /whois redinger |
| 20:35 | david` | haha |
| 20:57 | TimMc | $findfn [4 6 2 3] 6 1 |
| 20:58 | spewn | TimMc: sexpbot timed out about 4 hours ago |
| 20:58 | TimMc | hrmf |
| 21:01 | TimMc | If (get-in {:a [4 5]} [:a 1]) => 5, is there a (foo {:a [4 5]} 5) => [:a 1] ? |
| 21:04 | Sgeo | I take it there will never be tail-call optimization in Clojure? |
| 21:05 | TimMc | Sgeo: Depends on what happens with the JVM. |
| 21:06 | Sgeo | Given that I'm not at all tied to the JVM, what reasons are there to use Clojure instead of, say, Racket? |
| 21:07 | dnolen | Sgeo: in the mean time there are solid tools to write tail-call style code, and it performs at least as well as Racket (which isn't slow) as far I can tell. |
| 21:08 | joegallo | Sgeo: the java libraries that come along for the ride are pretty nice to have IMO |
| 21:08 | dnolen | Sgeo: data structures are the central part of any program. The design of the data structures in Clojure are much more thought out, and the interface are available to extend, reimplement. |
| 21:09 | spewn | Sgeo: With regard to data structures, you might want to read http://programming-puzzler.blogspot.com/2010/08/racket-vs-clojure.html |
| 21:09 | Sgeo | spewn, that's pretty much the only reason I'm looking at Clojure, despite the objection of some of my friends' |
| 21:10 | Sgeo | Although at least some of their objections seem to be more about the community >.> |
| 21:10 | dnolen | Sgeo: which isn't to say you shouldn't use/learn Racket. I spend a good deal of time using Racket these days. |
| 21:10 | Sgeo | It looks like Racket is less of a language and more of a ... JVM/.NET competitor |
| 21:10 | dnolen | Sgeo: people w/ strong opinions about the various good Lisp dialect are suspect (aka don't know what their talking about). |
| 21:11 | dnolen | Sgeo: huh? No. Racket is performant Scheme, w/ a boatload of many many useful extensions. |
| 21:12 | Sgeo | dnolen, I guess I'm thinking since it's somewhat easy to define one's own language that interoperates with others... |
| 21:12 | Sgeo | (Not that I've tried it) |
| 21:14 | Sgeo | I must admit I do kind of wish Clojure just came with an IDE >.>. I'm lazy >.> |
| 21:15 | dnolen | Sgeo: even if it did, it wouldn't beat the Racket IDE any time soon, a good 15 years of work has gone into it. |
| 21:19 | TimMc | DrScheme is pretty fly. |
| 21:19 | TimMc | Excuse me, DrRacket. |
| 21:25 | Sgeo | I guess it's not obvious to me how DrRacket's interesting functionality is more than REPL on bottom that gets executed in the environment of running the code on top |
| 21:25 | Sgeo | Is at least that much for Clojure difficult? |
| 21:27 | Sgeo | (binding [x 2 y 3] |
| 21:27 | Sgeo | (+ x y)) |
| 21:27 | Sgeo | I just know that Racket would write it like: |
| 21:27 | Sgeo | (binding ([x 2] [y 3]) |
| 21:27 | Sgeo | (+ x y)) |
| 21:27 | Sgeo | Coming from a non-Lisp background, guess which is easier on my mind? |
| 21:28 | dnolen | Sgeo: it has good paren matching, syntax highlighting, macro stepper, debugger, tabs, integration with Planet, REPL history, integrated docs, etc. etc. etc. |
| 21:28 | Sgeo | Let's implement Clojure in Racket! |
| 21:30 | dnolen | Sgeo: don't see much point in that. Clojure gets numerous non-trivial performance benefits from the JVM. |
| 21:30 | Sgeo | According to Wikipedia, Clojure has an emphasis on recursion. How? |
| 21:31 | TimMc | It's a lisp? |
| 21:31 | TimMc | :-P |
| 21:31 | Sgeo | I meant, considering the lack of TCO |
| 21:31 | TimMc | Recursion has to handled a little differently in Clojure. I wouldn't say there's an "emphasis". |
| 21:32 | dnolen | Sgeo: http://dosync.posterous.com/continuation-passing-style-in-clojure |
| 21:33 | dnolen | lazy-sequences, trampoline, recur explicitly get you what Scheme does automatically (which I admit is nice). |
| 21:36 | Sgeo | How much Java do I have to understand to have a good grasp of Clojure? |
| 21:36 | Sgeo | I mean, I do know C#, which is like Java but somewhat decent >.>, so... |
| 21:37 | Sgeo | [So says the hypocrite, who yells at Java for lacking lambdas but likes Python] |
| 21:37 | gregh | familiarity with the java libraries is helpful if you want to do useful stuff with clojure |
| 21:38 | dnolen | Sgeo: I prefer to focus on the Lispy elements of Clojure and it's quite easy to live there. But if you want build production apps, you're probably gonna want to pull in some Java libs. |
| 21:42 | dnolen | ,(let [t (future (repeatedly #(.getId (Thread/currentThread))))] (println "id:" (.getId (Thread/currentThread))) (future (println (take 1 @t)))) |
| 21:42 | clojurebot | id: 618 |
| 21:42 | amalloy | TimMc: .indexOf will do what you want for vectors, but anytime you touch an index you should seriously rethink why you're doing that |
| 21:42 | clojurebot | #<core$future_call$reify__5500@168db68: :pending> |
| 21:42 | dnolen | (let [t (future (repeatedly #(.getId (Thread/currentThread))))] (println "id:" (.getId (Thread/currentThread))) @(future (println (take 1 @t)))) |
| 21:42 | dnolen | ,(let [t (future (repeatedly #(.getId (Thread/currentThread))))] (println "id:" (.getId (Thread/currentThread))) @(future (println (take 1 @t)))) |
| 21:42 | clojurebot | id: 621 |
| 21:43 | amalloy | also, i guess Raynes isn't around, so i'll see if i can get sexpbot going again |
| 21:43 | dnolen | binding conveyance in 1.3.0. is really nice, no more future-out silliness. |
| 21:44 | TimMc | amalloy: I have a vector of control points for a higher order Bézier curve. The user is dragging one vertex. I identify the vertex in the first place by scanning the vector for the first Point2D under the mouse's coordinates. |
| 21:45 | TimMc | Currently I replace the element with a new Point2D every time the user drags the vertex. I do this with (map #(if (identical? % old) new %) verts). Seems like using an index might be better. |
| 21:46 | amalloy | TimMc: ##(doc replace) |
| 21:46 | sexpbot | ⟹ "([smap coll]); Given a map of replacement pairs and a vector/collection, returns a vector/seq with any elements = a key in smap replaced with the corresponding val in smap" |
| 21:46 | TimMc | hmmm |
| 21:47 | amalloy | also, ##(.indexOf [1 2 5 6 8] 6) ; hopefully works? :P |
| 21:47 | sexpbot | ⟹ 3 |
| 21:48 | TimMc | Is = going to be fast and accurate for comparing two Point2D$Double objects, compared to identical? ? |
| 21:48 | amalloy | probably not |
| 21:48 | TimMc | In this case, I know I have a pointer to the same object that I want to replace. |
| 21:49 | amalloy | but indexes do seem like a more appropriate choice for this problem |
| 21:49 | TimMc | I mean, map does *work*. |
| 21:50 | TimMc | I'm just trying to get a sense of whether this optimization is worth the fragility it might add. |
| 21:50 | Sgeo | let is for lexical scoping, binding for dynamic scoping? |
| 21:50 | amalloy | Sgeo: yes |
| 21:50 | Sgeo | Why does it feel weird that I first learned about dynamic scoping from Factor? |
| 21:51 | TimMc | replace has to be the worst-named function I've seen so far. |
| 21:52 | TimMc | Rather, the behavior with vectors doesn't make sense. |
| 21:52 | amalloy | &(replace {1 2} (vec (range 10))) |
| 21:52 | sexpbot | ⟹ [0 2 2 3 4 5 6 7 8 9] |
| 21:52 | amalloy | TimMc: what's the problem? |
| 21:53 | TimMc | &(replace [10 11 12 13] [0 3]) |
| 21:53 | sexpbot | ⟹ [10 13] |
| 21:54 | amalloy | TimMc: vectors are maps of their indices |
| 21:54 | TimMc | &(replace [10 11 12 13] [0 3 15]) |
| 21:54 | sexpbot | ⟹ [10 13 15] |
| 21:54 | TimMc | hrm |
| 21:54 | TimMc | It feels icky. |
| 21:56 | Sgeo | Why the discrepency between some and not-any? |
| 22:00 | amalloy | Sgeo: hard to answer unless you say what the discrepancy is |
| 22:01 | Sgeo | I meant in terms of names. Why not any and not-any? |
| 22:06 | Sgeo | (get popsicle-map :green) |
| 22:06 | Sgeo | (popsicle-map :green) |
| 22:06 | Sgeo | Would I be able to make my own values that can be called as functions? |
| 22:06 | Sgeo | That aren't merely functions/ |
| 22:07 | mattdw | Sgeo: I assume you'd just have to implement the IFn interface |
| 22:07 | amalloy | indeed that is the case |
| 22:08 | Sgeo | I'm nowhere near reading about that yet |
| 22:08 | amalloy | Sgeo: some is different from any. filter is functionally the opposite of not-any?, if you want |
| 22:11 | amalloy | or perhaps (comp seq filter) |
| 22:12 | Sgeo | -?> reminds me of the Maybe monad... |
| 22:18 | Sgeo | defmulti is like Factor's GENERIC: and defmethod is like Factor's M: |
| 22:18 | Sgeo | As far as I can tell |
| 22:19 | Sgeo | Clojure's defmulti seems to be a bit more flexible |
| 22:22 | spewn | ,(doc -?>) |
| 22:22 | clojurebot | No entiendo |
| 22:22 | spewn | Sgeo: What is that? |
| 22:23 | Sgeo | "There is also a -?> macro in the clojure.contrib.core namespace that stops and returns nil if any function in the chain returns nil. This avoids getting a NullPointerException." |
| 22:24 | spewn | Ah, in c.c. Thanks. |
| 22:24 | Sgeo | -> feels backwards, as does comp |
| 22:25 | Sgeo | Then agian, I haven't actually tried it |
| 22:26 | Sgeo | Huh. |
| 22:26 | Sgeo | Python just got something like memoize |
| 22:28 | illuminati1113 | Anyone use Clojure on Android? |
| 22:28 | sattvik | illuminati1113: I do. |
| 22:29 | spewn | sattvik: That was your app I tried on my phone... Very slow, but cool! |
| 22:29 | illuminati1113 | sattvik: I'm trying to instantiate a SurfaceViewwith gen-class. |
| 22:30 | illuminati1113 | Can this be done? |
| 22:31 | sattvik | spewn: Thanks. Unfortunately, to get dynamic compilation working it has to use the disk, which is very slow. I hope to be able to do in-memory compilation someday. |
| 22:32 | sattvik | illuminati1113: Hmm.. I think so. Depending on the context, it may be easier to use proxy. |
| 22:33 | DespiteItAll | How do I unload a namespace after accidentally "use"ing it |
| 22:33 | illuminati1113 | I can't use proxy because it needs to use a a protected method. |
| 22:33 | illuminati1113 | Proxy can't access those I don't think. |
| 22:34 | sattvik | illuminati1113: They can, so long as they're not final, I believe. |
| 22:34 | spewn | ,(doc remove-ns) |
| 22:34 | clojurebot | "([sym]); Removes the namespace named by the symbol. Use with caution. Cannot be used to remove the clojure namespace." |
| 22:34 | illuminati1113 | Do you need to use reflexion for that? |
| 22:35 | DespiteItAll | Thanks, that seems to be what I need |
| 22:36 | sattvik | In what sense? There is nothing special you need to do in your Clojure code with the proxy. Whether or not Clojure uses reflection internally, I am not sure. |
| 22:37 | illuminati1113 | "Note that while method fns can be provided to override protected methods, they have no other access to protected members, nor to super, as these capabilities cannot be proxied." |
| 22:38 | illuminati1113 | The problem is that the proxy function is defined within the proxy namespace. |
| 22:38 | amalloy | illuminati1113: override the protected method as public, then call it |
| 22:38 | amalloy | oh right, but super |
| 22:38 | illuminati1113 | amalloy: I did that using gen-class. |
| 22:39 | illuminati1113 | But I still get an error and don't know why. |
| 22:42 | sattvik | illuminati1113: Ah, yes, you're correct about the proxy. With gen-class, have you tried exposes-super? |
| 22:42 | illuminati1113 | ,(doc exposes-super) |
| 22:42 | clojurebot | It's greek to me. |
| 22:42 | sattvik | ,(doc gen-class) |
| 22:42 | clojurebot | "([& options]); When compiling, generates compiled bytecode for a class with the given package-qualified :name (which, as all names in these parameters, can be a string or symbol), and writes the .cl... |
| 22:43 | sattvik | Well, there's an option to provide a map for :exposes-super in gen-class. |
| 22:43 | illuminati1113 | do you mean exposes-method? |
| 22:43 | sattvik | Yes, that's right. |
| 22:43 | amalloy | &(doc gen-class) |
| 22:43 | sexpbot | ⟹ "Macro ([& options]); When compiling, generates compiled bytecode for a class with the given package-qualified :name (which, as all names in these parameters, can be a string or symbol), and writes the .class file to the *compile-path* directory. When not compiling, ... http://gist.github.com/839968 |
| 22:43 | illuminati1113 | That's what I'm using. |
| 22:43 | amalloy | for docs that don't truncate :P |
| 22:44 | sattvik | Have you tried not using exposes-method, and just calling (.protectedMethod this ...)? |
| 22:45 | illuminati1113 | Yes. |
| 22:45 | illuminati1113 | It's the same error either way. |
| 22:47 | illuminati1113 | https://gist.github.com/839973 |
| 22:47 | illuminati1113 | Is my current code. |
| 22:55 | illuminati1113 | sattvik: I'm going to just extend this class in Java and call it from Clojure. I know that works. Thanks. |
| 22:55 | illuminati1113 | BTW, I've been reading your articles on Clojure on Android. I've been finding them useful; keep them up. |
| 22:55 | sattvik | illuminati1113: Alright... I'll look at it a bit more since it's something I think I've run into before with AsyncTask. |
| 22:56 | sattvik | Thanks. I am glad they have been useful. |
| 22:58 | Sgeo | How is Clojure-in-Clojure doing? |
| 23:05 | sattvik | illuminati1113: I think you ran into the exact same bug I did. There is no access to protected *fields*, but there should be access to protected *methods*. The problem you ran into is that, like me, you tried to use a protected final method. I believe that's a bug. |
| 23:08 | illuminati1113 | sattvik: Is this an Android or Clojure bug? |
| 23:09 | sattvik | illuminati1113: It's a Clojure bug (CLJ-744). I think that gen-class/proxy try to do some filtering as to what methods should be exposed, and protected final methods don't seem to be making the cut. |
| 23:11 | illuminati1113 | sattvik: I see. Thanks, that means there's some hope for seeing it fixed! |
| 23:12 | illuminati1113 | I'll look at myself at least. |
| 23:19 | Sgeo | Yay, got Clojure REPL working |
| 23:19 | Sgeo | Aww, it doesn't do automatic indenting/ |
| 23:39 | technomancy | Sgeo: the bare clojure repl is pretty sorry; most people opt for more integrated tools. |
| 23:57 | amalloy | Sgeo: emacs, vim, textmate, and eclipse all have lovely integrated clojure repls |
| 23:57 | amalloy | and lein/cake both provide a smarter command-line repl |
| 23:59 | Sgeo | Does (recurse) work with (fn)? |