2011-01-31
| 00:36 | clizzin | is there anything that does concat for transients? or am i limited to just conj for a single item when dealing with transients? |
| 01:32 | TakeV | Are all the basic functions, such as inc, cached? |
| 01:32 | replaca | TakeV: I don't know what you mean by cached |
| 01:32 | TakeV | Memorized, I should say. |
| 01:32 | replaca | TakeV: they are compiled, yes, but not inlined by default |
| 01:33 | TakeV | The results of the function. Sorry for the lack of clarity. |
| 01:33 | replaca | TakeV: no, but you can use memoize |
| 01:33 | raek | no. afaik, they are not. |
| 01:34 | replaca | caching the result of inc is a negative though, the costs of doing the cache lookup would be larger than the cost of doing the computation |
| 01:34 | raek | (def memoized-inc (memoize inc)) |
| 01:34 | raek | heh, true |
| 01:35 | TakeV | Hmm, then that is odd. I am running inc through dotimes and time to get a baseline time to compare my function with, but after the first couple of times inc is called, the run time is cut in half. |
| 01:36 | replaca | TakeV: yeah, the java hotspot is inlining |
| 01:36 | TakeV | Hmm, but it isn't doing the same with my function. |
| 01:36 | TakeV | Does it only inline the predefined functions in the core? |
| 01:37 | replaca | your function may require introspection. Type hints are probably the way to happiness |
| 01:37 | replaca | sorry, introspection -> reflection |
| 01:37 | TakeV | Ahh, yes, that could be it. |
| 01:39 | TakeV | Yes, that is certainly it. Thank you. |
| 01:40 | replaca | cool, np |
| 02:18 | LauJensen | Morning |
| 03:33 | CedricPineau | fps : You need maven2 to build contrib |
| 03:47 | AWizzArd | technomancy: I think it was because I put it between two '*' chars. (def *foo* 10) ==> warning. When I did a (def +foo+ 10) it did not warn anymore. |
| 04:00 | raek | AWizzArd: *earmuffs* should be used for variables that are intended to be dynamically rebound. for constants, plain names without earmuffs are used |
| 04:01 | raek | this is what this says, anyway: http://www.assembla.com/wiki/show/clojure/Clojure_Library_Coding_Standards |
| 04:09 | AWizzArd | raek: then, at least in my opinion, this document is "wrong". |
| 04:10 | AWizzArd | raek: historically global vars (not introduced by let or fn params) were put into * or +. |
| 04:11 | AWizzArd | As local vars will not have such symbols an accidental shadowing is not likely. |
| 04:11 | raek | yes, there are multiple conventions around |
| 04:13 | raek | ah, is this related to the fact that in some lisps variables are dynamically scoped? |
| 04:13 | AWizzArd | The main lisps are. |
| 04:15 | raek | for a language with dynamically scoped variables, these conventions for global vars indeed make sense (due to shadowing issues) |
| 04:16 | replaca | AWizzArd: I thing that the general consensus was that this was too noisy for clojure and not necessary, since accidental shadowing is unlikely |
| 04:17 | replaca | AWizzArd: given the fact that locals are declared locally |
| 04:17 | AWizzArd | When we have (def x 10) and (defn foo [] (let [x 20] (println x))) I think we would see a 20. |
| 04:18 | replaca | AWizzArd: yes, but that's not accidental |
| 04:18 | replaca | the let is right there |
| 04:18 | AWizzArd | This is accidental. Because may not know by heart all globals. |
| 04:19 | AWizzArd | Of course, my IDE could warn me, but this does not happen anywhere yet. |
| 04:19 | replaca | AWizzArd: (which is not to say that *you* may prefer that to be more explicit, that just wasn't the consensus) |
| 04:19 | replaca | AWizzArd: true, you may shadow without knowing it, but you probably don't care, cause it doesn't "break" you global in any way |
| 04:20 | AWizzArd | As I said: it is about my opinion. |
| 04:20 | replaca | AWizzArd: if you wantd to use it, you'd probably know about it |
| 04:20 | replaca | AWizzArd: and functions you call will still see the global |
| 04:21 | replaca | One point htat was made is tht since Clojure is a lisp-1, most globals are actually functions. There was much appetite for earmuffs or +s there |
| 04:22 | replaca | *that |
| 04:22 | AWizzArd | It's okay. Anyway, then there should still be one default. For example: all globals are static by default. |
| 04:22 | AWizzArd | So when I say (def *foo* 10) it would still be a static var, even though it is stared. |
| 04:23 | replaca | AWizzArd: agreed. And I thought that that was exactly where clojure was going. If not, I haven't heard about it. |
| 04:23 | AWizzArd | In Alpha I also tried (def ^:static *foo* 10) but this also didn't help to make the warning go away. |
| 04:23 | replaca | yup |
| 04:23 | replaca | AWizzArd: I think that's just transition help |
| 04:24 | replaca | AWizzArd: but I'm not the expert |
| 04:24 | AWizzArd | With this hint I told the compiler explicitly: "I thought through this and I am aware of the issues. Static please." |
| 04:25 | replaca | AWizzArd: I though that :static didn't mean that anymore in the latest 1.3 |
| 04:25 | replaca | *thought |
| 04:25 | replaca | (it's late and I can't type anymore) |
| 04:27 | replaca | AWizzArd: I think that :dynamic is the only thing that means something and that Rich had discarded the idea of a :static property (and reused the keyword for a different meaning) |
| 04:27 | AWizzArd | Probably everything is implicitly :static by default. |
| 04:27 | replaca | AWizzArd: yes, exactly |
| 04:27 | AWizzArd | replaca: I even suggested him to add a compiler option that would make everything static. Probably that got him the idea to think about it :) |
| 04:28 | replaca | AWizzArd: could be. Were you at the conj? |
| 04:28 | AWizzArd | Unfortunately not. |
| 04:29 | replaca | AWizzArd: he talked about it there, and requiring :dynamic when you wanted was the opinion |
| 04:29 | replaca | no options :) |
| 04:29 | AWizzArd | I would have to look it up in the chatlogs to find out when I proposed this compiler flag. |
| 04:30 | replaca | in any case, I gotta crash. G'night all! |
| 04:32 | AWizzArd | n8 n8 |
| 04:49 | AWizzArd | $seen rhickey |
| 04:49 | sexpbot | rhickey was last seen quitting 2 weeks and 6 days ago. |
| 05:58 | AWizzArd | Many of you probably already saw this recent interview of rhickey: http://www.infoq.com/interviews/hickey-clojure-protocols |
| 06:34 | Dranik | does anyone know whether symbol macros are planed in clojure? |
| 06:41 | cemerick | Dranik: There's been some thought of it, but that's about it. http://dev.clojure.org/display/design/letmacro appears to be the relevant page to watch. |
| 06:42 | Dranik | cemerick, thanks |
| 06:43 | Dranik | cemerick, actually, I didn't get it. Is the page a kind of roadmap, and symbol macros will be implemented some day? |
| 06:44 | cemerick | Dranik: roughly, yes. When a more thorough (/formal) design has been churned through, it'll appear there. |
| 06:44 | Dranik | yeah, great!! |
| 06:44 | Dranik | thanks! |
| 06:44 | cemerick | np :-) |
| 06:59 | fliebel | cemerick, Dranik: Care to explain what symbol macroes are, and what the "new compiler" is? CinC? |
| 07:01 | Chousuke | fliebel: AFAIK a symbol macro is a symbol that gets replaced with a piece of code during macroexpansion |
| 07:02 | Dranik | can anybody explain what's wrong with the macro? (defmacro reffn [& body] `(let [my-fn# (ref (fn ~@body))] )) |
| 07:02 | fliebel | Chousuke: You mean that foo could become (+ foo 4)? |
| 07:02 | Dranik | i use macroexpand-1 and run the expanded code -- everything is ok |
| 07:03 | Chousuke | fliebel: something like that. except I think it would cause infinite recursion :P |
| 07:03 | Dranik | but when run the macro -- exception is thrown |
| 07:03 | fliebel | Dranik: what exception? stacktrace? |
| 07:03 | Chousuke | Dranik: I don't see anything immediately wrong with it. show me your macro call :P |
| 07:03 | Dranik | moment |
| 07:04 | Dranik | oh no.... |
| 07:04 | Dranik | thank you guys |
| 07:04 | Dranik | that was my error |
| 07:04 | edoloughlin | https://gist.github.com/803947 -- why is the last map 'promoted' out of its nesting? |
| 07:05 | Chousuke | edoloughlin: flatten is recursive, but does not descend into maps. |
| 07:06 | Chousuke | the last map is not inside a map but a vector, which gets flattened |
| 07:15 | edoloughlin | Broadband went down immediately after last posting. Missed any responses :( |
| 07:18 | Chousuke | 14:02 < Chousuke> edoloughlin: flatten is recursive, but does not descend into maps |
| 07:19 | Chousuke | ,(flatten [[[1 {:a [2]}]]]) |
| 07:19 | clojurebot | (1 {:a [2]}) |
| 07:21 | Chousuke | damn, building git manpages takes longer than building git itself :P |
| 07:23 | edoloughlin | Chousuke: Thanks |
| 08:00 | Yuizinha | There's some lein/clojure script for generting script for starting clojure applications ? |
| 08:15 | pppaul | i'm having trouble with lein + slime and classpaths |
| 08:16 | pppaul | i'm running lein, i did slime-connect to the server, and tried to import via (ns solve360-name-fixer |
| 08:16 | pppaul | (:require [solve360-interface :as solve360])), but it fails to find my file |
| 08:18 | mrBliss` | pppaul: replace the dash in solve360-interface with an underscore, but only for the filename, leave the dashes in the namespace. |
| 08:18 | pppaul | lein creates /src/solve360... but that's not on the classpath |
| 08:18 | Yuizinha | Anybody knows a wrapper to clojure like appassembler ? |
| 08:19 | pppaul | ./src is on the classpath, but my files are in /src/solve360... how do i get that on the classpath? |
| 08:19 | pppaul | or did i use lein wrong? |
| 08:20 | mrBliss` | pppaul: read the "Creating a Project" section of https://github.com/technomancy/leiningen/blob/master/TUTORIAL.md pay attention to the last paragraph. |
| 08:20 | pppaul | thank you |
| 08:20 | Yuizinha | could anybody help me? |
| 08:50 | Kototama | hello, can someone explain me why exceptions thrown from lambda functions are wrapped into runtime exceptions? |
| 08:57 | pppaul | i have a lein swank project running, with /src/solve360/<some cljs + curl.clj> when i do (require 'solve360.curl) i get an error: 'namespace 'solve360.curl' not found' |
| 08:58 | pppaul | can someone help me understand this? |
| 08:59 | pdk | are you sure that those clj files are in your classpath |
| 09:00 | pppaul | src/ is in my classpath |
| 09:00 | pppaul | this is the first time i've split a project into multiple files... having problems :( |
| 09:01 | pppaul | 'name.file' translates into /name/file.clj no? |
| 09:01 | mattmitchell | what's the best way to map keys of one hash to another, while giving the ability to change the names as needed? |
| 09:03 | ejackson | pppaul: yes it should |
| 09:04 | jkrueger | mattmitchel: i think that depends on how your keys are changing |
| 09:04 | pppaul | ok, i found out that (require 'solve360.curl) works, but when it's nested in another ns require it doesn't work |
| 09:06 | tonyl | pppaul: when it is nested in ns it doesn't need to be quoted and it needs to be a keyword. like here http://clojuredocs.org/clojure_core/clojure.core/ns#example_527 |
| 09:06 | raek | Kototama: that is probably due to that you use it in a lazy sequence. fn does not do that, but lazy-seq does. |
| 09:07 | pppaul | i know, i'll show example code... (ns solve360-interface |
| 09:07 | pppaul | (:require [clojure.contrib.json :as json]) |
| 09:07 | pppaul | (:require [solve360.curl :as curl])) |
| 09:08 | tonyl | what does it tell you? |
| 09:08 | mattmitchell | jkrueger: for direct mapping, i'm using select-keys. but the changes are simple, something like :parent_code becomes :parent_id etc. |
| 09:08 | jkrueger | in the most general form (into {} (map (fn [key val] [otherkey val]) source)) |
| 09:08 | pppaul | "namespace 'solve360.curl' not found" |
| 09:08 | mattmitchell | jkrueger: ahh ok i'll try that. thanks. |
| 09:08 | jkrueger | there is a [] missing around [key val] |
| 09:08 | tonyl | pppaul: that namespace might not be in your path then |
| 09:09 | ejackson | pppaul: that file needs to saved as solve360_interface.clj |
| 09:09 | pppaul | the file /src/solve360/curl.clj exists |
| 09:09 | ejackson | and the file that contains the code snippet you posted ? |
| 09:10 | tonyl | does the curl.clj file also has the form (ns slove360.curl) in it? |
| 09:10 | pppaul | no |
| 09:10 | pppaul | (ns curl) |
| 09:10 | pppaul | should it be (ns solve360.curl)? |
| 09:10 | ejackson | yes |
| 09:11 | pppaul | oh |
| 09:11 | Kototama | raek: hummm this sample http://pastie.org/1514707 throws a runtime exception in the SLIME repl but not in the REPL ... |
| 09:11 | Yuizinha | Anyone here knows lein-daemon or lein-init-script ? |
| 09:13 | ejackson | pppaul: all sorted ? |
| 09:14 | tonyl | are your files in the same level: /src/solve360/curl.clj /src/solve360/solve360-interface.clj |
| 09:15 | tonyl | pppaul: ^^ |
| 09:15 | pppaul | still having problems after editing my ns's |
| 09:15 | tonyl | pppaul: what does it says now? |
| 09:15 | pppaul | same problem (ns solve360.curl) in curl.clj, but it still gives me the can't find ns solve360.curl error |
| 09:16 | ejackson | the filename /src/solve360/solve360-interface.clj must have _ in the name, not -. |
| 09:17 | pppaul | i have it as /src/solve360/interface.clj |
| 09:17 | tonyl | pppaul: you have to name it the same |
| 09:17 | pppaul | do i need to name my curl file /src/solve360/solve360_curl.clj ??? |
| 09:18 | tonyl | no |
| 09:18 | tonyl | unless it makes sense to change it for your naming conventions |
| 09:18 | tonyl | the namespace just have to reflect the same name as the files |
| 09:18 | pppaul | i don't want to repeat 'solve360' so much |
| 09:18 | tonyl | except for the underscore and dash |
| 09:18 | pppaul | the file is interface.clj, curl.clj |
| 09:19 | tonyl | right |
| 09:19 | pppaul | ns = solve360.interface |
| 09:19 | tonyl | so in the interface.clj you can put it as (ns solve360.interface |
| 09:19 | tonyl | yeah |
| 09:19 | pppaul | that's what i have |
| 09:19 | tonyl | and curl.clj as (ns solve360.curl) |
| 09:19 | pppaul | (ns solve360.interface |
| 09:19 | pppaul | (:require [clojure.contrib.json :as json]) |
| 09:19 | pppaul | (:require [solve360.curl :as curl])) |
| 09:20 | pppaul | (ns solve360.curl |
| 09:20 | pppaul | (:require [clojure.contrib.json :as json]) |
| 09:20 | pppaul | (:use clojure.contrib.shell-out)) |
| 09:20 | tonyl | that didn't work? |
| 09:20 | pppaul | "namespace 'solve360.curl' not found" |
| 09:22 | pppaul | maybe my env is broken? |
| 09:22 | pppaul | i've just started it, and only done ns stuff, though |
| 09:23 | tonyl | i think in (:require [solve360.curl ...] you only need (:require curl) since they are in the same level |
| 09:23 | tonyl | but I am not so sure |
| 09:24 | pppaul | i'll try |
| 09:26 | raek | Kototama: what happens when you use doseq instead of map? |
| 09:31 | pppaul | i'm still having problems with my classpath |
| 09:31 | pppaul | (ns solve360.interface |
| 09:31 | pppaul | (:require [clojure.contrib.json :as json]) |
| 09:31 | pppaul | (:require curl)) |
| 09:31 | pppaul | Could not locate curl__init.class or curl.clj on classpath: |
| 09:33 | mattmitchell | jkrueger: ok so I got this far, would you mind giving me a hint as to how i can "find" the alias key in the mapping? https://gist.github.com/804092 |
| 09:33 | tonyl | pppaul: are you adding the src folder to your classpath? |
| 09:34 | tonyl | or how you are you running these files? |
| 09:34 | raek | pppaul: is the file in solve360/curl.clj? in that case you still have to write solve360.curl, even though the interface file is in "the same level" |
| 09:34 | pppaul | src is in classpath, checked |
| 09:35 | pppaul | i was doing that, someone suggested that i try without solve360.curl |
| 09:35 | pppaul | namespace 'solve360.curl' not found |
| 09:36 | tonyl | are you only running the interface.clj file? |
| 09:37 | pppaul | yes |
| 09:38 | ejackson | mattmitchell: no, do like jkrueger suggested... Ive put it onto your gist |
| 09:40 | ejackson | although it unhelpfully parsed it in some cockeyed manner |
| 09:40 | jkrueger | ejackson : that looks like what i had in mind. but you beat me to it |
| 09:40 | ejackson | well, it was your idea :) |
| 09:42 | mattmitchell | ejackson jkrueger: ok thanks! but to make it work with a list of keys, and optional aliases for the sake of learning, how would i get the aliases working for what I have? |
| 09:43 | jkrueger | mattmitchel: create a map out of the list first |
| 09:43 | tonyl | pppaul: are you using lein or something similar? |
| 09:43 | jkrueger | if you have to pass a vector |
| 09:44 | pppaul | so i'm really curious as to why my '(:require [solve360.curl :as curl]))' isn't making a solve360.curl namespace |
| 09:44 | pppaul | i'm using lein |
| 09:44 | pppaul | lein swank |
| 09:44 | tonyl | oh mm, never used it |
| 09:45 | mattmitchell | jkrueger: oh ok, so the mapping becomes {:id :id :new-name :name} , then i create the new hash by using that map? |
| 09:45 | raek | pppaul: do you have (ns solve360.curl ...) in your curl.clj file? |
| 09:45 | pppaul | yes |
| 09:45 | Kototama | raek: then it's not wrapped anymore |
| 09:46 | raek | ok. lazy sequences wrap them, cause they can end up anywhere |
| 09:46 | raek | so the basic advice is to avoid throwing exceptions through lazy sequences (e.g. map) |
| 09:47 | pppaul | maybe i'm interacting with swank wrong |
| 09:47 | raek | as they don't really fit the model |
| 09:47 | jkrueger | mattmitchel: correct. i'm not entirely sure if that is the most elegant way. but off the top of my head it seems ok |
| 09:47 | raek | pppaul: how did you start the swank server? |
| 09:47 | pppaul | i'm using C--M-x |
| 09:47 | pppaul | i did lein swank |
| 09:47 | pppaul | connected with slime-connect |
| 09:47 | pppaul | and started doing C-M-x on parts of my code |
| 09:47 | mattmitchell | jkrueger: excellent. thanks again. |
| 09:48 | pppaul | starting with (ns) |
| 09:49 | Kototama | i'm parsing an xml file and resolving some imports for the file, not sure how to avoid that |
| 09:50 | Kototama | i did a macro that unwraps the exception and rethrow it :s |
| 09:51 | raek | one way could be to catch the exception inside the fn, and return some error value instead |
| 10:01 | mattmitchell | can any improvements be made with this? https://gist.github.com/804128 |
| 10:04 | jkrueger | mattmitchel: looks fine. since you don't need the bindind form in normalize-mapping, you could shorten the fn to a #() form |
| 10:08 | jkrueger | mattmitchel: on the other hand... the parameter is referenced more than once, so it probably should have a name |
| 10:10 | mattmitchell_ | jkrueger: i see. ok that makes sense. thanks again for your feedback :) |
| 10:11 | jkrueger | mattmitchel: your're welcome |
| 10:23 | edw | I've found myself using sequence operations that work on single elements of sub-sequences. (https://gist.github.com/804165) Are these operations, perhaps more generally, defined anywhere, and if so, do they have established names? |
| 10:29 | hv | is (:use [foo.bar :only (baz)]) wrong? should be [baz] instead of (bar), right? |
| 10:30 | Chousuke | hv: it doesn't matter |
| 10:30 | Chousuke | both are sequential |
| 10:33 | hv | hmm, () seem to cause some problems. |
| 10:34 | hv | for instance, clojure.contrib.prxml seems broken, but if I make that change it seems to work again. |
| 10:41 | raek | hv: as long as you write that in an ns form (i.e. not directly at the repl), both should be equivalent |
| 10:43 | hv | raek, Chousuke: You're right, I'll have to see what was broken then... |
| 11:27 | Yuizinha | Somebody here have sucess using lein-init-script ? |
| 11:28 | Yuizinha | I'm having some troubles, the script returns a null pointer exception |
| 12:14 | zippy314_ | Hi folks. I'm running into the situation where I have name-spaces that want to mutually refer to some parts of eachother in :use clauses, but this seems to fail because of the circularity. Is there a known way to handle this, or do all namespaces have to be strictly hierarchical in their inclusion pattern? |
| 12:15 | ohpauleez | zippy314_: I don't know the answer for sure, but have you tried using :only to specify key functions you want? and also, does require suffer from this? |
| 12:16 | zippy314_ | yah I've tried it, but it doesn't seem to matter. It looks like because of the circularity it's trying to define things that don't exist yet. |
| 12:17 | ohpauleez | right |
| 12:26 | fliebel | zippy314_: You're right. A common way to solve it is to convert a <-> b to a -> c <- b |
| 12:27 | zippy314_ | I guess this it's a one-pass loading scheme, huh. Ok. That's a good idea. |
| 12:27 | fliebel | A more hackish way, is to move the use statements down into the code, right before you need them, and then rearange the code so that it loads in the right order. |
| 12:30 | raek | another way is to convert "abcd <-> xy" into "ab <- cdxy" |
| 12:31 | zippy314_ | fleibel: does that mean that you re-do the ns call multiple times? |
| 12:33 | fliebel | zippy314_: No, it means you just move it down, so that all the code above it is loaded before it loads the other file, so the other file can at least access the code abover the use in the first file. |
| 12:33 | raek | zippy314_: I think it hard to recommend a general strategy (except for "avoid circularity"). can you show us the code? |
| 12:34 | raek | in my experience, functional code tends to be "layered" |
| 12:34 | zippy314_ | I'm going to try and distill it down to the basic parts and see if the layered thing happens naturally. |
| 12:34 | raek | where each layer is only dependent on functionality of layers below it |
| 12:34 | zippy314_ | If not, I'll post some code. |
| 12:37 | raek | lets assume you have one namespace for apples and one for apple baskets. then it might be a good idea to move everything that involves both apples and baskets (e.g. basket-contains-apple?, list-apples, list-enclosing-baskets) into the basket namespace |
| 14:04 | zippy314_ | can anybody point me to tips on opening a stream on a string? I'm trying to write some code for my test routines that simulates *in* and *out* and I think I can do it easily if I can get a stream that reads from a string. |
| 14:05 | fliebel | zippy314_: take a look at java.io and clojure.java.io |
| 14:05 | fliebel | I think there are StringOutputStreams and sucht, and even macroes like with-out or something like that. |
| 14:21 | fliebel | zippy314_: ##(doc with-out-str) |
| 14:21 | sexpbot | ⟹ "Macro ([& body]); Evaluates exprs in a context in which *out* is bound to a fresh StringWriter. Returns the string created by any nested printing calls." |
| 14:21 | chouser | ,(with-in-str "hello" (read-line)) |
| 14:21 | clojurebot | "hello" |
| 14:22 | hiredman | 1d2 |
| 14:22 | clojurebot | 1 |
| 14:22 | hiredman | 1d2 |
| 14:22 | clojurebot | 1 |
| 14:22 | fliebel | hiredman: ? |
| 14:23 | hiredman | fliebel: flipping a coin |
| 14:23 | fliebel | 1d2 |
| 14:23 | clojurebot | 1 |
| 14:23 | fliebel | Does it over return non-1? |
| 14:24 | zippy314_ | 1d10 |
| 14:24 | clojurebot | 1 |
| 14:24 | zippy314_ | 10d1 |
| 14:24 | clojurebot | 10 |
| 14:24 | robonobo | apparently not |
| 14:24 | fliebel | &1d1 |
| 14:24 | sexpbot | java.lang.NumberFormatException: Invalid number: 1d1 |
| 14:24 | hiredman | 5d6 |
| 14:24 | clojurebot | 15 |
| 14:24 | ohpauleez | what is that syntax for? |
| 14:25 | ohpauleez | clojurebot's coin flip? |
| 14:25 | hiredman | it's not clojure syntax, it's dungeon's and dragons dice |
| 14:26 | hiredman | 5d6 is five six sided dice |
| 14:26 | clojurebot | 24 |
| 14:26 | ohpauleez | ahh, rad |
| 14:26 | robonobo | 1d6 |
| 14:26 | clojurebot | 3 |
| 14:27 | fliebel | 1d2 should return 2 sometimes in that case... |
| 14:27 | clojurebot | 2 |
| 14:27 | robonobo | there you go |
| 14:27 | fliebel | I don;t see why a bot would need to throw dice, but it's cool :) |
| 14:28 | hiredman | sometimes you need some random bits |
| 14:28 | fliebel | 1d0 |
| 14:28 | clojurebot | #<NullPointerException java.lang.NullPointerException> |
| 14:28 | robonobo | noooo |
| 14:28 | fliebel | 1d1e5 |
| 14:28 | clojurebot | 1 |
| 14:29 | opqdonut | 1d10000 |
| 14:29 | clojurebot | 8928 |
| 14:29 | opqdonut | 1d10 |
| 14:29 | clojurebot | 10 |
| 14:29 | fliebel | 0d2 |
| 14:29 | clojurebot | 0 |
| 14:29 | opqdonut | 1d10 |
| 14:29 | clojurebot | 1 |
| 14:29 | opqdonut | 1d10 |
| 14:29 | clojurebot | 8 |
| 14:29 | fliebel | 1d-2 |
| 14:29 | ohpauleez | fails the regex |
| 14:29 | fliebel | hmhm |
| 14:30 | fliebel | ,(print "1d2") |
| 14:30 | clojurebot | 1d2 |
| 14:30 | fliebel | &(print "1d2") |
| 14:30 | sexpbot | ⟹ 1d2nil |
| 14:30 | fliebel | uh :( |
| 14:31 | fliebel | Does clojurebot ignores itself completely? |
| 14:32 | robonobo | fliebel: i would think it does, otherwise you could probably set it off in an infinite loop |
| 14:32 | robonobo | s/think/hope |
| 14:32 | sexpbot | <robonobo> fliebel: i would hope it does, otherwise you could probably set it off in an infinite loop |
| 14:32 | technomancy | fliebel: it doesn't need to; IRC doesn't work that way |
| 14:33 | technomancy | you don't see your own messages |
| 14:33 | fliebel | I'm thinking it would be fun to have clojurebot evaluate a… you know, those things that evaluate to themselves :) |
| 14:33 | robonobo | quine |
| 14:33 | fliebel | right |
| 14:33 | robonobo | i've never understood quines |
| 14:33 | tonyl | keywords :P |
| 14:33 | robonobo | except cat $0 |
| 14:33 | zanes | No. Quines print themselves. There's a difference. |
| 14:34 | robonobo | yes, i know, it's a cheat |
| 14:35 | zanes | Was quibbling about the definition, not your example. |
| 14:35 | jkrueger | http://d.hatena.ne.jp/ku-ma-me/20090916/p1 |
| 14:35 | fliebel | robonobo: that does not even work... |
| 14:36 | robonobo | fliebel: it has to be a in a script, not from the shell |
| 14:36 | robonobo | $0 is the script file itself |
| 14:37 | tonyl | *1 |
| 14:37 | robonobo | so cat $0 prints the contents of the script |
| 14:37 | robonobo | jkrueger: that's just too much |
| 14:39 | jkrueger | robonobo: i just thought i'd throw it in there :) |
| 14:39 | jkrueger | not that i comprehend it |
| 14:40 | robonobo | i've been told lisp quines are the easiest to understand due to the whole code is data thing |
| 14:41 | robonobo | anyone have a good short one? |
| 14:41 | fliebel | I wish I had... |
| 14:42 | robonobo | ,((fn [x] (list x (list (quote quote) x))) (quote (fn [x] (list x (list (quote quote) x))))) |
| 14:42 | clojurebot | ((fn [x] (list x (list (quote quote) x))) (quote (fn [x] (list x (list # x))))) |
| 14:42 | robonobo | from here |
| 14:42 | robonobo | http://en.literateprograms.org/Quine_(Clojure) |
| 14:44 | fliebel | I was trying something like this, but that is not how things work… bash -c "echo $@" |
| 14:45 | robonobo | fliebel: yes, no |
| 14:45 | robonobo | bash is hard |
| 14:47 | fliebel | &*1 |
| 14:47 | sexpbot | java.lang.IllegalStateException: Var clojure.core/*1 is unbound. |
| 14:47 | fliebel | ,*1 |
| 14:47 | clojurebot | java.lang.IllegalStateException: Var clojure.core/*1 is unbound. |
| 14:47 | fliebel | :( |
| 14:48 | fliebel | that var is real fun with quines :) |
| 14:59 | fliebel | Whoa, jQuery seems to have (promise)s :) http://www.erichynds.com/jquery/using-deferreds-in-jquery/ |
| 15:07 | hiredman | well, single threaded promises are meh |
| 16:17 | alpheus | clojure-mode.el defines clojure-load-file which calls inferior-lisp-proc. inferior-lisp-proc doesn't exist afaict. |
| 16:18 | alpheus | On one of my systems, C-c C-l runs slime-load-file (which works) and on another it runs clojure-load-file. Drove me crazy, since both systems have all that stuff installed by elpa. |
| 16:19 | amalloy | alpheus: C-c C-l is for reading the current file into the repl? |
| 16:21 | alpheus | yes |
| 16:21 | amalloy | i use C-c C-k, which looks like it's supposed to do the same thing (for clojure, anyway) and haven't had problems |
| 16:21 | semperos_ | general q, what do folks here do for slideshow/powerpoint presentations with syntax-highlighted clojure code? |
| 16:23 | amalloy | i recently needed to select N items from a list of M unique items (M>N) at random without duplicates. it's pretty simple in an imperative language, and not too bad with loop/recur, but i couldn't find a pretty way to do it with the usual HOFs. anyone have an idea? |
| 16:24 | brehaut | semperos: i use pygments (pygments.org to get it) to generate HTML |
| 16:24 | brehaut | semperos: and then copy that generated result into keynote |
| 16:24 | alpheus | weird, C-c C-k isn't bound to anything on my broken system |
| 16:24 | fliebel | &(take 5 (shuffle (range 20))) |
| 16:24 | sexpbot | ⟹ (8 16 17 0 3) |
| 16:25 | fliebel | amalloy: ^^ |
| 16:25 | semperos_ | brehaut: makes sense |
| 16:25 | amalloy | fliebel: which is O(M*ln M) instead of O(N) |
| 16:26 | semperos_ | brehaut: thanks |
| 16:26 | fliebel | But it's pretty :) |
| 16:26 | amalloy | er, just O(M) |
| 16:26 | amalloy | fliebel: *chuckle* |
| 16:26 | fliebel | amalloy: Can I see hte loop/recur? |
| 16:27 | hiredman | seems like it should be doable with reduce |
| 16:27 | amalloy | fliebel: i haven't actually written the loop/recur but i'll show you the php :P |
| 16:27 | fliebel | noo, no more php! these guys at automatic need to understand some functional concepts... |
| 16:27 | fliebel | oh well, bring it on. |
| 16:28 | amalloy | and reduce/iterate seem like the way to go but they'll be ugly anyway. https://gist.github.com/ce05ee104dd6b06e7f03 |
| 16:29 | fliebel | I mean… the_title, that *prints* some title from a *global* variable that is *mutated* the represent the current post. |
| 16:30 | amalloy | fliebel: i know, php is dreadful. i'm sneaking functional code in where i can |
| 16:30 | brehaut | amalloy: just start writing in pharen or similar :P |
| 16:31 | fliebel | brehaut: That does not make sort actually return something, i suppose. |
| 16:32 | brehaut | fliebel: is this what stockholm syndrome feels like? |
| 16:32 | fliebel | *googles* |
| 16:33 | brehaut | amalloy: i think im missing something; how does that php snippet ensure that each index is unique? |
| 16:33 | fliebel | I was thinking the same... |
| 16:34 | fliebel | this sounds much like (take 5 (repeatedly #(rand-nth seq))) |
| 16:34 | amalloy | maybe i left out something relevant. $candidates is (range M) |
| 16:35 | amalloy | every time we select an index from that range, we store it in the list of return values, and then overwrite its entry in the candidate-list with the first element of the list |
| 16:35 | brehaut | oh i see. clever |
| 16:35 | fliebel | I don't see... |
| 16:35 | fliebel | but.. clever, I suppose. |
| 16:35 | amalloy | brehaut: it's not my idea; it's the classic way to do this |
| 16:36 | brehaut | amalloy: i must have dozed throguh that algorithms lecture |
| 16:36 | ossareh | lo all |
| 16:36 | amalloy | brehaut: a lot of my early programs were card games. this was pretty interesting to me at the time :) |
| 16:37 | fliebel | Ah, now I see... |
| 16:38 | brehaut | amalloy: so thats more like O(m+n) than O(n) right? |
| 16:38 | amalloy | brehaut: no, because it's only looping N times, and each iteration is O(1) |
| 16:38 | amalloy | $howmany is my N |
| 16:38 | amalloy | and $max is M |
| 16:38 | brehaut | amalloy: but it has to create the candidates structure |
| 16:38 | brehaut | which is length M ? |
| 16:38 | amalloy | brehaut: hm, i suppose that's true |
| 16:39 | fliebel | amalloy: You can do select-keys on a vector, I think that's interesting :) |
| 16:41 | ossareh | given a protocol which has been extended with extend-protocol how can I tell if the methods have all been implemented? |
| 16:42 | Schuyler | can anyone please tell me why this sequence is not evaluated lazily? https://gist.github.com/804873 |
| 16:42 | amalloy | brehaut, fliebel: the monstrosity of doing this with iterate: https://gist.github.com/8fff306833f5d0852277 |
| 16:43 | brehaut | yeah that isnt so nice |
| 16:44 | amalloy | Schuyler: you have your cons on the wrong side of (primes). it should probably look more like (cons (primes ...) (next-prime factors)) |
| 16:44 | amalloy | though i haven't looked deeply |
| 16:46 | fliebel | Schuyler: Have a look at this, and ate c.c.lazy-seqs/primes. https://gist.github.com/795374 |
| 16:46 | Schuyler | hmm. I thought cons took a seq as its *second* argument. |
| 16:46 | Schuyler | do I really want conj instead? |
| 16:47 | amalloy | er, yeah, my argument order is wrong |
| 16:47 | amalloy | but i think you want cons outside of the call to primes |
| 16:48 | Schuyler | ok. I confess I don't understand. I am pretty sure I want to *add* to the seq before recursing. |
| 16:48 | Schuyler | if I'm not passing the extended sequence to primes, then what do I pass? |
| 16:48 | fliebel | amalloy: Would you mind to update the PHP sample with all the variables, to save me some mind overhead every time I look at it? |
| 16:49 | Schuyler | I'm sorry if I'm coming across like an idiot. Clojure's idea of lazy evaluation feels like magic. I can't see how I can know ahead of time whether Clojure will evaluate a sequence lazily or not. |
| 16:49 | peikos | good evening all.. could someone please help me by explaining a ClassCastException in this small piece of code? http://pastebin.com/9ERCg7pn |
| 16:50 | amalloy | fliebel: done |
| 16:50 | Schuyler | I've been all over Halloway's book, and I am, if anything, *more* confused about recursion in Clojure than I was before./ |
| 16:50 | fliebel | thanks |
| 16:50 | Schuyler | amalloy: could I trouble you to take a moment and give me some idea of what you'd actually pass to primes in your "..." above? |
| 16:51 | Schuyler | *that's* the part I'm flummoxed over. |
| 16:51 | peikos | I'm just starting out in Clojure, after using Haskell for quite some time.. This is my first time trying to access Java classes from Clojure, and the result is not very promising unfortunately.. |
| 16:51 | fliebel | Schuyler: loop/recur is not lazy, and cons is magic. If you want to understand how laziness works, I found iterate to be much simpler to understand. |
| 16:52 | amalloy | (defn primes [factors] (lazy-seq (let [f (next-prime factors)] (cons f (primes (cons f factors)))))) is a sketch, Schuyler |
| 16:53 | amalloy | the point is you need to return a single element before doing something else lazy, as well as update the factor-list for the next call to primes |
| 16:53 | tonyl | peikos: is it giving you that error on the CompononetColorModel class? |
| 16:53 | amalloy | &(class (into-array [8])) |
| 16:53 | sexpbot | ⟹ [Ljava.lang.Integer; |
| 16:54 | peikos | it does not give me any more information than that it's a ClassCastException, and that it occurs on the first line of the pasted fragement.. |
| 16:54 | Schuyler | fliebel, amalloy, thank you for the feedback. I will ponder this and try to make sense of it. |
| 16:54 | amalloy | &(class (int-array [8])) |
| 16:54 | sexpbot | ⟹ [I |
| 16:54 | amalloy | peikos: ^ |
| 16:56 | amalloy | ie, you can't pass that thing an Integer[] when it wants an int[] |
| 16:57 | peikos | ah... of course. I was under the mistaken impression an int was an integer, because (into-array [(int 8)]) resulted in the same problem.. |
| 16:58 | peikos | thanks for that bit of advise :-) |
| 16:59 | Schuyler | holy christ. amalloy, that worked perfectly. |
| 16:59 | Schuyler | could you please explain what you mean by "you need to return a single element before doing something else lazy"? |
| 16:59 | Schuyler | if you don't mind. I've been programming for decades, but aside from some LISP in college I still haven't got my head around pure functional programming |
| 17:00 | amalloy | Schuyler: sure, i'll take a stab |
| 17:00 | Schuyler | and I find it a little baffling that Clojure doesn't support lazy tail recursion like, say, Haskell |
| 17:00 | ossareh | Schuyler: that is a JVM thing. |
| 17:01 | jkrueger | and not really as bothersome as it sounds |
| 17:02 | Schuyler | jkrueger, probably not. but I'm still trying to figure how to do iterative function calls in Clojure *without* loops *or* tail call optimization. |
| 17:02 | brehaut | also, as much as i love Haskell, it says a lot about the language that there is abook titled 'Real World Haskell' |
| 17:02 | Schuyler | brehaut, notice I'm not trying to learn Haskell seriously :) |
| 17:03 | brehaut | Schuyler: thats a mistake ;) |
| 17:03 | Schuyler | you think? |
| 17:03 | brehaut | yeah i do |
| 17:03 | devn | anyone know how tcrayford has his testing setup on http://vimeo.com/9350864 -- there's a link to his watchr script, but im interested in the emacs red/green output |
| 17:03 | brehaut | I learn more every time i stick my head into haskell land for a day, than a week in another language |
| 17:03 | brehaut | that being said, im _way_ more productive in clojure |
| 17:03 | jkrueger | brehaut: and if you read it it doesn't strike you as very application oriented either |
| 17:04 | brehaut | jkrueger: depends on your application i think. |
| 17:04 | amalloy | Schuyler: lazy-seq "delays" everything within its body, and when it is "forced", everything in the body is forced |
| 17:04 | brehaut | jkrueger: it may sound insane, but i think it's probably unmatched for writing unix tools |
| 17:05 | ossareh | amalloy: not everything though right - just anything over the 32nd iteration. |
| 17:05 | amalloy | what you really want is to non-lazily return the list (x the-rest-of-the-primes), and only be lazy about calculating the rest |
| 17:05 | amalloy | ossareh: lazy-seq isn't chunked, just range is. but we can ignore chunking when talking about the concept of laziness |
| 17:05 | ossareh | amalloy: oh, sorry - you're talking about lazy-seq inparticular - I missed that. |
| 17:05 | jkrueger | brehaut: i like haskell. don't get me wrong |
| 17:06 | amalloy | haskell is on my to-learn list |
| 17:06 | jkrueger | but in some ways it is like c++. it eats it's young by driving people into senseless complexity |
| 17:07 | jkrueger | c++ on the syntactic level. haskell with layers upon layers of abstraction |
| 17:07 | brehaut | nah i dont think thats true. in general the levels of abstraction are about consistent with clojure, but they are organised according to more mathematical ideas |
| 17:09 | Schuyler | amalloy: thank you for explaining that. |
| 17:10 | Schuyler | is there a debugger or something for Clojure? |
| 17:10 | Schuyler | I'd like to step through what's happening here. |
| 17:10 | Schuyler | in an imperative language, I'd just stick print statements inside the loop. |
| 17:10 | Schuyler | but I'm not even sure how to do that here. |
| 17:10 | brehaut | Schuyler: i think any java debugger should work i think? |
| 17:12 | fliebel | amalloy: I'm a bit to sleepy to understand the php. But if I walk through it, writing down what would happen if rand was constantly 0, I seem to get [0 0 1 2 3 4], which is neither random or unique. |
| 17:12 | brehaut | Schuyler: although there might be a caveat around the behaviour of let at the moment, it might be a bit squiffy. I saw some discussion o nthe clojure-dev ML recently |
| 17:15 | amalloy | fliebel: nah, you're wrong there |
| 17:15 | amalloy | because i'm doing rand(i, max), so it will turn out to be 0, 1, 2, 3... |
| 17:15 | amalloy | rather than rand(0, max) |
| 17:16 | fliebel | ah! |
| 17:19 | Schuyler | ok, I definitely don't understand. |
| 17:19 | Schuyler | how do you guys debug Clojure programs? |
| 17:19 | fliebel | Schuyler: print statements :) |
| 17:19 | brehaut | Schuyler: i debug with prn and a repl |
| 17:20 | amalloy | Schuyler: yes, sadly print statements are the state of the art. george jahad's cdt is supposed to be pretty cool though |
| 17:20 | fliebel | In tricky cases, you can replace foo with (do (print) foo) and foo will still be returned as expected. |
| 17:20 | Schuyler | ok... but I can't just bung print calls in anywhere, can I? |
| 17:21 | brehaut | Schuyler: mostly you can. |
| 17:21 | fliebel | Schuyler: Why not? |
| 17:21 | amalloy | fliebel, Schuyler: i use https://gist.github.com/c93c37345c49c47dcfa2 for that |
| 17:21 | brehaut | Schuyler: there are a few forms without implicit dos, and you can just use (do (prn ...) thing) |
| 17:24 | brehaut | amalloy: that is really cool |
| 17:24 | fliebel | Why isn't there reduce-indexed? |
| 17:24 | amalloy | brehaut: thanks. i've been tinkering/improving it over the ages as i realize bits that are missing. feel free to steal and/or disseminate |
| 17:25 | brehaut | amalloy: done :) |
| 17:27 | amalloy | there's something similar called spy in contrib somewhere, maybe c.c.log |
| 17:32 | Schuyler | amalloy: can you give an example of how that macro would be used? |
| 17:32 | Schuyler | I mean syntatically |
| 17:32 | Schuyler | *syntactically |
| 17:32 | fliebel | ah, reduce-indexed: (defmacro reduce-indexed [f i s] `(reduce (fn [a# [i# b#]] (~f a# b# i#)) ~i (map vector (range) ~s))) |
| 17:38 | amalloy | Schuyler: (call-some-fn 10 (? (some-other-fn 10))) |
| 17:38 | amalloy | will print something like "(some-other-fn 10) is 55" |
| 17:38 | amalloy | so that you can verify you're passing the right args |
| 17:39 | amalloy | and it will of course still pass 55 as the second argument to call-some-fn |
| 17:39 | Schuyler | `.~> |
| 17:39 | Schuyler | ~> |
| 17:39 | Schuyler | ~> |
| 17:39 | clojurebot | <monads> is "yea, though I should walk in the valley of imperative code, I shall fear no evil, for your monad comforts me" - seen in #haskell |
| 17:39 | Schuyler | ~> |
| 17:39 | Schuyler | ~> |
| 17:39 | Schuyler | ~> |
| 17:40 | clojurebot | the world <reply>what the world needs is more higher order functions |
| 17:40 | clojurebot | the world <reply>what the world needs is more higher order functions |
| 17:40 | clojurebot | the world <reply>what the world needs is more higher order functions |
| 17:49 | amalloy | fliebel: why is that a macro? surely it can be a function |
| 17:49 | fliebel | amalloy: Uhm, because I felt like it, and because I'm much to tired. |
| 17:53 | Schuyler | oops. |
| 17:53 | Schuyler | thanks for the explanations, guys. |
| 17:53 | fliebel | amalloy: I give up, and go to sleep. please remember me to write you a nice indices function, next time I hop on. |
| 17:54 | Schuyler | I do all my day-to-day work in Python, so Clojure is a bit of a head trip. |
| 17:54 | amalloy | Schuyler: and i do mine in php. you'll get used to it, and clojure is worth it |
| 17:54 | Schuyler | however, I'm reaching a point where Python isn't performant enough, and my coworkers don't want me to use C++. |
| 17:54 | Schuyler | and I don't want to use Java ;-) |
| 17:55 | ossareh | Schuyler: what are you writing that a language determines the performance? |
| 17:55 | pdk | your coworkers are wise |
| 17:57 | ossareh | a buddy of mine recently had to port what amounted to a mobile web browser from java to c++ because dalvik blows chunks for graphics (consider flick scrolling a page), but that was the only time that I could think there was a real difference in the performance of the language. |
| 17:59 | Schuyler | ossareh, just real CPU intensive computational geometry stuff. |
| 17:59 | ossareh | Schuyler: huh.. cool - so clojure 1.3 is likely to be of interest to you then |
| 17:59 | Schuyler | how come? |
| 18:00 | pdk | or the alpha of it at any rate |
| 18:00 | ossareh | Schuyler: it has a lot of native math stuff added to it so you don't suffer from the boxing / unboxing overhead. |
| 18:00 | Schuyler | interesting. do you have a link to relevant docs? |
| 18:04 | ossareh | http://dev.clojure.org/display/design/Primitive+Support |
| 18:04 | Schuyler | thanks! |
| 18:05 | ossareh | That is the rationale - and there is a lot in the google groups discussions |
| 18:05 | ossareh | http://groups.google.com/groups/search?q=clojure+primitive+math&btnG=Search&sitesearch= |
| 18:34 | N8Dawg | Hello group |
| 18:34 | N8Dawg | I know its late... |
| 18:35 | N8Dawg | Had a question about macroexpand |
| 18:35 | pdk | do tell |
| 18:35 | N8Dawg | Common Lisp allows you to pass an env block to macroexpand |
| 18:35 | N8Dawg | cannot see a way to do that in Clojure |
| 18:36 | Chousuke | there's no such thing AFAIK |
| 18:36 | brehaut | N8Dawg: that is the case |
| 18:36 | N8Dawg | not sure i understand, you can access an env block from within a macro |
| 18:36 | N8Dawg | Clojure supports that I know |
| 18:37 | N8Dawg | so what you're saying is I cannot lexically expand a macro on demand |
| 18:37 | N8Dawg | drat :( |
| 18:39 | brehaut | N8Dawg: ithink ive missed something, but macroexpand doesnt eval the result, so you can still see symbols that would come from the lexical enviroment? |
| 18:40 | N8Dawg | (defmacro test1 [] (println &env)) |
| 18:41 | N8Dawg | If you run it... you get nil as expected: |
| 18:41 | N8Dawg | (test1) |
| 18:41 | N8Dawg | nil |
| 18:41 | N8Dawg | but run it inside a let block: |
| 18:41 | N8Dawg | (let [a 1] (test1)) |
| 18:41 | N8Dawg | {a #<LocalBinding clojure.lang.Compiler$LocalBinding@4cb17167>} |
| 18:41 | N8Dawg | as expected |
| 18:42 | N8Dawg | lastly: |
| 18:42 | N8Dawg | (let [a 1] (macroexpand '(test1))) |
| 18:42 | N8Dawg | nil |
| 18:44 | N8Dawg | dunno if that makes sense |
| 18:44 | brehaut | N8Dawg: i see what you mean now |
| 18:45 | N8Dawg | thats wy common lisp lets you supply an ooptional env block to macroexpand |
| 18:45 | N8Dawg | i think... |
| 18:46 | brehaut | $source defmacro |
| 18:46 | sexpbot | defmacro is http://is.gd/cDqC1Q |
| 18:48 | N8Dawg | defmacro defines an implicit env block |
| 18:48 | N8Dawg | which is provided by the system when the macro is called |
| 18:50 | N8Dawg | http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/fun_macroexpa_acroexpand-1.html |
| 18:55 | N8Dawg | i better head off |
| 18:55 | N8Dawg | but thanks for the responses |
| 19:20 | ossareh | how do I unextend a protocol? |
| 19:22 | hiredman | you don't |
| 19:53 | mattmitchell | is it possible to create a macro, that contains raw html? |
| 19:54 | pdk | if the html is in strings it should be |
| 19:55 | mattmitchell | pdk: but not like this: https://gist.github.com/805188 :) |
| 19:55 | ossareh | hiredman: thanks - I've taken to destroying the ns's and recreating them as needed. |
| 19:55 | pdk | it's not part of clojure syntax so writing it that directly probably isn't gonna happen |
| 19:56 | pdk | practically every book that talks about lisp macros gives an example of using them to generate html |
| 19:56 | pdk | you could take one those, tweak it a bit for clojure |
| 19:56 | pdk | and be able to write stuff like (html (div "text") ...) |
| 19:57 | mattmitchell | pdk: true yeah, that might be the way to go |
| 19:57 | brehaut | pdk: a macro? seems a bit overkill. why wouldnt a function work? |
| 19:57 | pdk | practical clojure i'm fairly sure uses the xml generating example in its macro chapter |
| 19:59 | brehaut | pdk https://github.com/weavejester/hiccup/ ? |
| 19:59 | pdk | well |
| 19:59 | pdk | then there's hiccup :p |
| 20:00 | mattmitchell | yeah hiccup looks pretty good |
| 20:03 | mattmitchell | anyone know of a good html parser? |
| 20:03 | brehaut | mattmitchell: enlive |
| 20:03 | mattmitchell | something that has good css/xpath selector support? |
| 20:03 | mattmitchell | brehaut: enlive can parse too? |
| 20:03 | brehaut | mattmitchell: enlive; it uses pseudo css selectors |
| 20:04 | mattmitchell | brehaut: interesting ok |
| 20:04 | brehaut | yes; enlive is clojures all singing, all dancing html solution |
| 20:04 | mattmitchell | brehaut: :) cool I'll have a look |
| 20:04 | brehaut | mattmitchell: dnolen's introductory tutorial shows how to use it to scrap as well as generate html |
| 20:04 | mattmitchell | brehaut: oh right, i kinda remember seeing that. will dig it up now. |
| 20:05 | brehaut | mattmitchell: from memory its selectors are more powerful than css because you can use fns |
| 20:05 | brehaut | mattmitchell: https://github.com/swannodette/enlive-tutorial |
| 20:05 | mattmitchell | brehaut: thanks! |
| 20:07 | brehaut | mattmitchell: http://enlive.cgrand.net/syntax.html thats the full (if a little daunting when you havent used it) syntax for selectors in enlive |
| 20:08 | mattmitchell | brehaut: looks really good. |
| 20:10 | ossareh | mattmitchell: enlive is the shit. I just got turned on to it last week and it has changed my life for the better |
| 20:10 | ossareh | as has discovering ~' !! |
| 20:18 | mattmitchell | ossareh: good to know! |
| 20:28 | gfrlog | ,(keys (transient {})) |
| 20:28 | clojurebot | java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.PersistentArrayMap$TransientArrayMap |
| 20:29 | gfrlog | anybody know how to get the keys from a transient map? |
| 20:29 | amalloy | &(-> {} transient persistent! keys) |
| 20:29 | sexpbot | ⟹ nil |
| 20:30 | gfrlog | amalloy: does that forego the benefits of transients if I convert them to persistents at each step of my inner loop? |
| 20:30 | amalloy | gfrlog: my suspicion is that it's impossible on purpose. the keyseq would be doing structural sharing with the transient map, and would therefore be subject to corruption at any time |
| 20:31 | amalloy | perhaps you should reconsider why you want to get a list of all the keys in a map multiple times in performance-sensitive code? |
| 20:31 | gfrlog | perhaps so |
| 20:32 | gfrlog | and I just realized that in my case (keys m) is the same as (range (count m)) |
| 20:32 | gfrlog | so that's easy |
| 20:32 | amalloy | gfrlog: so it sounds like you want a vector, not a map? |
| 20:33 | amalloy | &(keys [1 6 8]) |
| 20:33 | sexpbot | java.lang.ClassCastException: java.lang.Integer cannot be cast to java.util.Map$Entry |
| 20:33 | mattmitchell | &(doc reduce) |
| 20:33 | sexpbot | ⟹ "([f coll] [f val coll]); f should be a function of 2 arguments. If val is not supplied, returns the result of applying f to the first 2 items in coll, then applying f to that result and the 3rd item, etc. If coll contains no items, f must accept no arguments as well... http://gist.github.com/805238 |
| 20:34 | gfrlog | amalloy: man I was about to say "dangit no I need a map because..." |
| 20:34 | gfrlog | amalloy: but of course you're right. I am ashamed. |
| 20:34 | amalloy | *laugh* glad to have helped |
| 20:34 | gfrlog | although I'm confused as to why your code failed |
| 20:35 | gfrlog | &([1 6 8] 2) |
| 20:35 | sexpbot | ⟹ 8 |
| 20:35 | amalloy | gfrlog: keys assumes a map |
| 20:38 | gfrlog | amalloy: thanks |
| 20:46 | gfrlog | ,(apply partial (repeat partial)) |
| 20:46 | clojurebot | #<core$partial$fn__3684 clojure.core$partial$fn__3684@ba372f> |
| 20:46 | gfrlog | awesome |
| 20:47 | gfrlog | ,((apply partial (repeat partial)) 10) |
| 20:47 | clojurebot | #<core$partial$fn__3684 clojure.core$partial$fn__3684@9083c1> |
| 20:47 | mattmitchell | is there a way to handle strings without worrying about escaping quotes? |
| 20:48 | mattmitchell | like heredoc syntax? |
| 20:49 | amalloy | mattmitchell: not at the moment. there's a faction who want to add """python style "really long strings" to the language""" |
| 20:50 | brehaut | mattmitchell: for future reference http://clojure.org/reader will tell you all the literal syntaxes supported by the reader |
| 20:50 | mattmitchell | amalloy: i see. i'm thinking about blobs of html. maybe not the right fit. |
| 20:50 | mattmitchell | brehaut: cool that's helpful |
| 20:52 | tomoj | why do you want blobs of html in your clojure? |
| 20:56 | mattmitchell | tomoj: oh, well i'm just playing around right now! nothing serious. learning etc.. |
| 20:58 | brehaut | mattmitchell: enlive looks for your templates (and snippets) in your source path |
| 20:58 | brehaut | mattmitchell: so its trivial to package them with the rest of a project |
| 20:59 | brehaut | mattmitchell: and it lets you find snippets inside your master templates; it makes working with the html as html much much easier |
| 20:59 | brehaut | (because it is just an html) |
| 21:00 | brehaut | its a little more work initially to set up, but it pays off in a real project |
| 21:00 | brehaut | (even if that project is small) |
| 21:01 | mattmitchell | brehaut: yes, enlive is looking like a good match for some of the things i'd like to do |
| 21:04 | ossareh | I'm actually working on something right now that amounts to a CMS - makes heavy use of enlive |
| 21:04 | brehaut | mattmitchell: its also not really idiomatic lisp to tunnel other data in strings. |
| 21:05 | mattmitchell | ossareh: is it open source/public? |
| 21:05 | ossareh | mattmitchell: I hope to get it there |
| 21:06 | ossareh | mattmitchell: it's not in github yet |
| 21:07 | mattmitchell | ossareh: i'm actually kicking around a little project too. something like ruby's jekyll (https://github.com/mojombo/jekyll) -- but with an admin for editing and uploads. |
| 21:07 | brehaut | mattmitchell: have a look at github.com/lauJensen/bestinclass.dk before you go too far |
| 21:09 | mattmitchell | brehaut: nice! are the pages stored on the file system? |
| 21:09 | brehaut | mattmitchell: database i think |
| 21:09 | mattmitchell | brehaut: oh looks like it works with wordpress, interesting. |
| 21:10 | brehaut | mattmitchell: i believe its more like the old movable type than jekyll/hyde |
| 21:10 | brehaut | its a full web app, but it bakes html pages rather than generating them dynamically |
| 21:11 | mattmitchell | brehaut: good stuff. i'll dig into it. |
| 22:07 | kcl | Has anyone processed a post request using moustache where the content type is "application/vnd.adobe.xfdf"? Can't seem to figure out how to extract the body. |
| 22:11 | amalloy | kcl: have you looked at http://partners.adobe.com/public/developer/xml/index_arch.html#dfdf ? |
| 22:11 | amalloy | that is the extent of my xfdf knowledge though, so happy hunting |
| 22:12 | kcl | amalloy: Yup. Its actually just xml. I think I'm just missing something stupid here. |
| 22:13 | kcl | amalloy: The body in the repl always comes back as org.mort...., with the form-params and query params empty. |
| 22:13 | kcl | amalloy: Found something about forcing a mime type change so that it would parse as xml, but that does not seem to work (or I am doing it wrong) |
| 22:15 | amalloy | kcl: from what i know of http, you should be able to have your server list the content types it understands |
| 22:16 | kcl | amalloy: On the moustache side? I'm trying to capture a post from Acrobat, btw. |
| 22:17 | tomoj | moustache doesn't care, it's ring |
| 22:17 | kcl | tomoj: That's what I thought - but how do I get ring to parse it? |
| 22:17 | tomoj | you have a request handy? |
| 22:17 | brehaut | amalloy: the client can list the content types it accepts (Accepts header on request), but i cant think of any headers the server can send |
| 22:17 | tomoj | what's (class (:body the-req)) ? |
| 22:18 | kcl | tomoj: #<Input org.mortbay.jetty.HttpParser$Input@2471fd20 |
| 22:19 | tomoj | ok, that's an InputStream |
| 22:19 | kcl | tomoj: Right. I think I read that I could slurp* it, but I get nada |
| 22:19 | tomoj | oh, maybe someone else has already read the body? |
| 22:20 | kcl | tomoj: Could be. I'm fuzzy (obviously!) on the inner workings. :-) |
| 22:20 | brehaut | kcl do you have any middleware defined? |
| 22:21 | kcl | brehaut: I'm using wrap-params and wrap-multipart-params |
| 22:21 | kcl | brehaut: I removed them at one point to see if it would help, but it did not. I also tried writing a wrap function to change the content type to application/xml |
| 22:21 | kcl | brehaut: but that did not work either. |
| 22:22 | tomoj | so with no middleware, slurping the body still gives you nothing? |
| 22:23 | kcl | tomoj: Let me try again. Been at this for a while :-/ |
| 22:23 | ihodes | tomoj: great first line to read, glancing back at irc |
| 22:24 | kcl | tomoj: Still get "" back. |
| 22:24 | tomoj | and you're sure the body isn't actually empty? |
| 22:24 | tomoj | :) |
| 22:25 | kcl | tomoj: I used a sniffer and it showed the xml in all its glory :-) |
| 22:25 | tomoj | you tried it now on a brand new request, right |
| 22:27 | kcl | kcl: Yup. |
| 22:28 | tomoj | huh. your setup reliably picked up changes? |
| 22:28 | tomoj | with no middleware, where could the body go? :O |
| 22:31 | kcl | tomoj: :-) |
| 22:31 | brehaut | kcl,how are you starting jetty? |
| 22:31 | kcl | brehaut: (run-jetty #'pdf-handler {:port 8080 :join? false})) |
| 22:31 | brehaut | approximately (run-jetty my-app {:port 3000}) |
| 22:32 | brehaut | ok |
| 22:32 | kcl | I may have been at this too long. I appreciate the help. I think I need to go watch Castle and dream of pdfs :-) |
| 22:33 | brehaut | kcl just one second |
| 22:34 | kcl | brehaut: Ok. I'm tying something here as well... |
| 22:34 | brehaut | can you replace #'pdf-handler |
| 22:34 | brehaut | with |
| 22:35 | brehaut | (fn [{:keys [uri body]] (when (= uri "/your/test/uri/") (slurp body))) |
| 22:35 | brehaut | crap. missed a } |
| 22:35 | brehaut | (fn [{:keys [uri body]}] (when (= uri "/your/test/uri/") (slurp body))) |
| 22:36 | kcl | brehaut: Ok - uri is the local path? |
| 22:36 | brehaut | yeah |
| 22:36 | brehaut | i only put that in because sometimes the client may make multiple requests |
| 22:36 | brehaut | and we want to filter it to only the one we care about |
| 22:36 | brehaut | oh |
| 22:36 | brehaut | you want a print around slurb |
| 22:36 | kcl | k |
| 22:39 | brehaut | ive also used the wrong slurp sorry |
| 22:40 | kcl | brehaut: np. working on it |
| 22:44 | kcl | brehaut: I need to do more to try your idea (not set up to handle inferior lisp, etc. |
| 22:44 | kcl | brehaut: I will give it a shot tomorrow and see what I get. |
| 22:45 | kcl | brehaut: (and all others) Thanks for the help! |
| 22:45 | brehaut | the actual work that ring does before it calls your handler is fairly minor |
| 22:45 | brehaut | you should be able to pinpoint the problem more easily from that point |
| 22:46 | kcl | brehaut: I'll give it a shot. Has to be (I hope) something simple I am missing. |
| 22:46 | brehaut | hopefully |
| 22:46 | brehaut | i need to go cook dinner |
| 22:46 | kcl | brehaut: Have a good one. Wife calling me for Castle. :-) |
| 23:48 | tomoj | any gloss users thinking about validation? |
| 23:49 | tomoj | a keyword typo means sending half a frame over before hitting an encoding error, breaking the connection |
| 23:53 | arohner | is there a pdoseq or pfor anywhere? |
| 23:56 | amalloy | arohner: ##(doc pcalls) maybe? |
| 23:56 | sexpbot | ⟹ "([& fns]); Executes the no-arg fns in parallel, returning a lazy sequence of their values" |
| 23:57 | amalloy | ie, ##(apply pcalls (for [x (range 5)] (constantly x))) |
| 23:57 | sexpbot | ⟹ (0 1 2 3 4) |
| 23:58 | arohner | thanks, I didn't know about pcalls, but I don't understand how that example could work |
| 23:58 | arohner | oh right, constantly returns a function |
| 23:58 | amalloy | arohner: right |
| 23:59 | amalloy | wrap the functions you want to call up in some kind of thunk, and then pcall them |