2009-12-05
| 00:00 | _ato | (.getURLs (.getContextClassLoader (Thread/currentThread))) |
| 00:00 | _ato | ^ that might work for add-classpath stuff |
| 00:07 | alexyk | _ato: thx! |
| 00:14 | alexyk | did clojure-maven-plugin disappear from build.clojure.org/snapshots? |
| 00:16 | slyrus_ | duper: common lisp, #lisp |
| 00:16 | cemerick | alexyk: huh, I didn't know it was ever there |
| 00:16 | alexyk | cemerick: my bad |
| 00:16 | alexyk | cemerick: but now I can ask you about importing << :) |
| 00:17 | cemerick | that was fast :-) |
| 00:17 | alexyk | IDEA did a load-file on your goodies, says, #'commons.clojure.strint/<< |
| 00:18 | cemerick | alexyk: did you hit a snag? |
| 00:18 | alexyk | now I'm in my own namespace user=> still |
| 00:18 | alexyk | it works with full name, but I can't rename it into the current namespace in repl |
| 00:18 | cemerick | oh -- just (use 'commons.clojure.strint) if you're at a repl |
| 00:18 | alexyk | I'm sure it works fine in a new script, but I want a way to get it into repl without modifying classpath |
| 00:19 | alexyk | or restarting the repl |
| 00:19 | alexyk | folks suggested (alias '<< #'commons.clojure.strint/<<) -- fails |
| 00:19 | alexyk | and a version of (defmacro << {your #'commons.clojure.strint/<< tortured}) |
| 00:19 | cemerick | that's not necessary -- 'use' doesn't work? |
| 00:19 | alexyk | didn't work either |
| 00:20 | cemerick | that doesn't make sense |
| 00:20 | alexyk | the file is not on my classpath as I pasted it into IDEA :) |
| 00:20 | cemerick | oh, oh |
| 00:20 | cemerick | I don't know anything about how IDEA's clojure stuff works |
| 00:20 | alexyk | I'm generally curious about importing things from other namespaces in repl |
| 00:20 | alexyk | it was loaded into repl with (load-file ...) |
| 00:20 | alexyk | and created << in its own namespace |
| 00:21 | alexyk | and it works fine! :) |
| 00:21 | cemerick | then (use 'commons.clojure.strint) should bring << into user (or whatever ns your repl is in) |
| 00:21 | cemerick | *ns*, I should say |
| 00:21 | alexyk | (use 'commons.clojure.strint) => java.io.FileNotFoundException: Could not locate commons/clojure/strint__init.class or commons/clojure/strint.clj on classpath: (NO_SOURCE_FILE:0) |
| 00:22 | alexyk | it's not compiled yet as was loaded as-is |
| 00:22 | cemerick | and that's after using load-file? |
| 00:22 | alexyk | with (load-file ...) :) |
| 00:22 | alexyk | yep |
| 00:22 | cemerick | huh |
| 00:22 | cemerick | there's a lot of things that could be getting in the way there. |
| 00:22 | cemerick | I haven't used load-file in about a year :-) |
| 00:23 | alexyk | this is general, I understand no aspersions are cast on the fine-crafted << programming |
| 00:23 | cemerick | heh |
| 00:23 | alexyk | yeah, IDEA did it after clicking on "run file in repl" |
| 00:23 | alexyk | cemerick: I'll overlook your Scala flame-bait, this time, there :) |
| 00:23 | cemerick | oh. Maybe it's running the file in a separate classloader, which would make it inaccessible |
| 00:24 | alexyk | it just types (load-file ...) into a repl, I see it |
| 00:24 | alexyk | but anyways it's contrived, I should use it from a script anyhow |
| 00:25 | hiredman | alexyk: use won't work if the file is already loaded |
| 00:25 | hiredman | use refer |
| 00:25 | hiredman | use tries to load then refer a namespace |
| 00:25 | alexyk | hiredman: (refer '...)? |
| 00:25 | hiredman | ,(doc refer) |
| 00:25 | clojurebot | "([ns-sym & filters]); refers to all public vars of ns, subject to filters. filters can include at most one each of: :exclude list-of-symbols :only list-of-symbols :rename map-of-fromsymbol-tosymbol For each public interned var in the namespace named by the symbol, adds a mapping from the name of the var to the var to the current namespace. Throws an exception if name is already mapped to something else in the current nam |
| 00:26 | cemerick | alexyk: OK, so I get the same behaviour in enclojure. I really never use load-file, so I guess I don't understand what its semantics are. |
| 00:27 | alexyk | hiredman: almost there! my previous attempts defined << in local ns, how do I undefine it? |
| 00:27 | hiredman | (ns-unmap *ns* '<<) |
| 00:28 | alexyk | eureka! |
| 00:28 | alexyk | (<< "There's ~(seq (range n 90 -1)) bottles of beer on the wall...") |
| 00:28 | alexyk | "There's (99 98 97 96 95 94 93 92 91) bottles of beer on the wall..." |
| 00:28 | alexyk | cemerick deserves one of those! :) |
| 00:29 | alexyk | (refer 'commons.clojure.strint) ; did the trick |
| 00:30 | hiredman | but I guess I am old fashioned |
| 00:30 | alexyk | cemerick: your blog says, "you should follow me on twitter..." usually this is written as "follow me on twitter..." :) |
| 00:31 | hiredman | there was a blog post somewhere about commanding people to follow you results in more follows |
| 00:31 | alexyk | hiredman: I look down on Ruby's interpolation, format is visually separable, but the bottle example is good in terms of -- try to format that |
| 00:32 | cemerick | alexyk: I'm aping http://dustincurtis.com/you_should_follow_me_on_twitter.html there |
| 00:32 | cemerick | I could care less about the wording, so... |
| 00:32 | cemerick | hiredman: I've been using format and String.format for too long, and too much. I couldn't take it anymore for certain things. |
| 00:33 | hiredman | ,(format "There's %s bottles of bear on the wall..." (prn-str (range 100 99 -1))) |
| 00:33 | clojurebot | "There's (100)\n bottles of bear on the wall..." |
| 00:33 | hiredman | erp |
| 00:33 | hiredman | ,(format "There's %s bottles of bear on the wall..." (pr-str (range 100 90 -1))) |
| 00:33 | clojurebot | "There's (100 99 98 97 96 95 94 93 92 91) bottles of bear on the wall..." |
| 00:33 | hiredman | ,(format "There's %s bottles of beer on the wall..." (pr-str (range 100 90 -1))) |
| 00:33 | clojurebot | "There's (100 99 98 97 96 95 94 93 92 91) bottles of beer on the wall..." |
| 00:33 | cemerick | yeah, sure. It's when there's 10 args that it gets rough. |
| 00:33 | hiredman | sure |
| 00:34 | hiredman | which is why you write the function that takes a map and generates the string once |
| 00:34 | alexyk | cemerick: nice explanation of twitter :) |
| 00:35 | hiredman | cemerick: it's neat macro and everyone likes it |
| 00:35 | cemerick | I'm surprised that there's been such a response, but I'm happy others appreciate it. |
| 00:36 | alexyk | but you can't avoid () can you |
| 00:36 | cemerick | avoid ()? |
| 00:36 | alexyk | or ~(seq ...) will fall apart |
| 00:37 | hiredman | erm |
| 00:37 | hiredman | it's a function call |
| 00:37 | alexyk | can you do: There's 100 99 ... 91 bottles... |
| 00:37 | alexyk | I mean in the result |
| 00:37 | alexyk | format does it in the same way, but interpolation? |
| 00:38 | _ato | i guess theres: ~(apply str (range 100 90 -1)) |
| 00:38 | _ato | ugh |
| 00:38 | hiredman | ,(format "There's %s bottles of beer on the wall..." (apply str (range 100 90 -1))) |
| 00:38 | clojurebot | "There's 100999897969594939291 bottles of beer on the wall..." |
| 00:38 | _ato | no that won't give you spaces |
| 00:38 | hiredman | you have to use interleave |
| 00:38 | hiredman | or reduce |
| 00:39 | _ato | yeah, or join from str-utils2 |
| 00:39 | hiredman | ,(format "There's %s bottles of beer on the wall..." (reduce (partial str " ") "" (range 100 90 -1))) |
| 00:39 | clojurebot | "There's 100999897969594939291 bottles of beer on the wall..." |
| 00:39 | hiredman | hmmm |
| 00:39 | _ato | ,(format "THere's %s bottles of beer on the wall..." (clojure.contrib.str-utils2/join " " (range 100 90 -1))) |
| 00:39 | clojurebot | java.lang.RuntimeException: java.lang.ClassNotFoundException: clojure.contrib.str-utils2 |
| 00:39 | hiredman | ,(format "There's %s bottles of beer on the wall..." (reduce #(str %1 " " %2) (range 100 90 -1))) |
| 00:39 | clojurebot | "There's 100 99 98 97 96 95 94 93 92 91 bottles of beer on the wall..." |
| 00:40 | _ato | (require 'clojure.contrib.str-utils2) |
| 00:40 | _ato | ,(format "THere's %s bottles of beer on the wall..." (clojure.contrib.str-utils2/join " " (range 100 90 -1))) |
| 00:40 | clojurebot | java.lang.RuntimeException: java.lang.ClassNotFoundException: clojure.contrib.str-utils2 |
| 00:40 | _ato | ,(require 'clojure.contrib.str-utils2) |
| 00:40 | clojurebot | nil |
| 00:40 | _ato | ,(format "THere's %s bottles of beer on the wall..." (clojure.contrib.str-utils2/join " " (range 100 90 -1))) |
| 00:40 | alexyk | yes! now will cemerick's << do that? without ()? |
| 00:40 | clojurebot | "THere's 100 99 98 97 96 95 94 93 92 91 bottles of beer on the wall..." |
| 00:40 | hiredman | same call I would imagine |
| 00:40 | hiredman | where is the url for cemericks code? |
| 00:41 | alexyk | http://muckandbrass.com/ |
| 00:42 | cemerick | alexyk: I don't really think you want to go down that path. If you start adding formatting options to something like <<, the syntax will degrade into misery. |
| 00:42 | cemerick | the permutations expand *really* fast |
| 00:42 | hiredman | ,(refer 'commons.clojure.strint |
| 00:42 | clojurebot | EOF while reading |
| 00:42 | hiredman | ,(refer 'commons.clojure.strint) |
| 00:42 | clojurebot | nil |
| 00:42 | hiredman | ,>> |
| 00:42 | clojurebot | java.lang.Exception: Unable to resolve symbol: >> in this context |
| 00:42 | _ato | ,<< |
| 00:42 | clojurebot | java.lang.Exception: Can't take value of a macro: #'commons.clojure.strint/<< |
| 00:43 | alexyk | cemerick: I want to avoid surrounding parens, that's all |
| 00:43 | _ato | ,(<< "hello ~(join \" \" (range 10)) world") |
| 00:43 | clojurebot | java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Character |
| 00:43 | cemerick | oh, gawd, it's in clojurebot now :O |
| 00:43 | hiredman | _ato: can't have strings inside |
| 00:43 | alexyk | right: (<< "There's ~(reduce #(str %1 " " %2) (range 100 90 -1)) bottles of beer on the wall...") => java.lang.IllegalArgumentException: Wrong number of args passed to: strint$-LT--LT- (NO_SOURCE_FILE:0) |
| 00:43 | hiredman | cemerick: :) |
| 00:44 | alexyk | need to quote is somehow... |
| 00:44 | hiredman | use \space |
| 00:44 | hiredman | ,\space |
| 00:44 | clojurebot | \space |
| 00:44 | hiredman | ,(str \space) |
| 00:44 | hiredman | … |
| 00:44 | _ato | ,(<< "hello ~(join \space (range 10)) world") |
| 00:44 | alexyk | clojurebot: breathe |
| 00:44 | hiredman | ,(str "a" \space "b") |
| 00:44 | cemerick | alexyk: you want the parens, otherwise, you'd be depending on whitespace after your binding name, etc. |
| 00:44 | clojurebot | " " |
| 00:44 | clojurebot | Unsupported escape character: \s |
| 00:44 | clojurebot | Titim gan éirí ort. |
| 00:44 | clojurebot | "a b" |
| 00:44 | hiredman | ah |
| 00:45 | hiredman | \space isn't going to work either |
| 00:45 | alexyk | cemerick: yeah, but I don't want them to be in output! |
| 00:45 | cemerick | alexyk: well, that's what you get when you str a seq *shrug* |
| 00:45 | hiredman | _ato: format works :P |
| 00:46 | alexyk | true |
| 00:46 | alexyk | can live with that |
| 00:46 | cemerick | cemerick: retarding clojure programmer productivity WORLDWIDE! :-P |
| 00:46 | _ato | ,(<< "hello ~(+ 1 1)") |
| 00:46 | clojurebot | "hello 2" |
| 00:47 | alexyk | now we can say, take that, Ruby folk! |
| 00:47 | cemerick | eh, hardly |
| 00:48 | cemerick | << is an order of magnitude of capability away from #{} and heredocs |
| 00:49 | alexyk | ,(<< "hello ~(reverse \"ruby\")") |
| 00:49 | clojurebot | "hello (\\y \\b \\u \\r)" |
| 00:49 | _ato | ,(str "hello " (reverse "ruby")) |
| 00:49 | clojurebot | "hello (\\y \\b \\u \\r)" |
| 00:49 | _ato | so much nicer :p |
| 00:50 | alexyk | _ato: ambiguous spaces and gluing! |
| 00:50 | alexyk | I see [ " ] and am not sure whether it begins or ends what |
| 00:52 | _ato | (<< "hello ~(<< \"nested ~(str \\"world\\")\")!") |
| 00:52 | _ato | ,(<< "hello ~(<< \"nested ~(str \\"world\\")\")!") |
| 00:52 | clojurebot | java.lang.IllegalArgumentException: Wrong number of args passed to: strint$-LT--LT- |
| 00:52 | _ato | ok.. I can't pull that off |
| 00:52 | _ato | too confusing |
| 00:53 | _ato | ,(<< "hello ~(<< \"nested ~(str \\\"world\\\")\")!") |
| 00:53 | clojurebot | "hello nested world!" |
| 00:53 | _ato | ah |
| 00:53 | _ato | heh |
| 00:53 | cemerick | oy |
| 00:54 | _ato | alexyk: fair enough. I can see the simple variable case, like "hello $foo". But anything more complex quickly becomes ugly |
| 00:55 | alexyk | exactly |
| 00:55 | alexyk | (<< "hello ~(<< \"nested ~(str \\\"cemerick\\\")\")!") |
| 00:55 | alexyk | ,(<< "hello ~(<< \"nested ~(str \\\"cemerick\\\")\")!") |
| 00:55 | clojurebot | "hello nested cemerick!" |
| 00:56 | alexyk | now we only need to rot13 the nested string... |
| 00:57 | hiredman | ,(+ (mod (+ (int \a) 13) 26) (int \a)) |
| 00:57 | clojurebot | 103 |
| 00:58 | hiredman | hmmm |
| 00:58 | cemerick | _ato: I suspect the best usage will be stuff like (<< "Hi ~(:name user), you have ~{msg-cnt} messages waiting for you in ~(:inbox-loc user)"), or whatever |
| 00:58 | hiredman | ,(char 103) |
| 00:58 | clojurebot | \g |
| 00:58 | hiredman | ,(+ (mod (+ (int \z) 13) 26) (int \a)) |
| 00:58 | clojurebot | 102 |
| 00:58 | hiredman | ,(char 102) |
| 00:58 | clojurebot | \f |
| 00:58 | hiredman | :| |
| 00:58 | hiredman | ,(+ (mod (+ (- (int \z) (int \a) 13) 26) (int \a)) |
| 00:58 | clojurebot | EOF while reading |
| 00:59 | hiredman | ,(+ (mod (+ (- (int \z) (int \a)) 13) 26) (int \a)) |
| 00:59 | clojurebot | 109 |
| 00:59 | hiredman | that's not right |
| 00:59 | duncanm | la la la |
| 01:00 | hiredman | is that right? |
| 01:01 | hiredman | (yes) |
| 01:03 | interferon | how do i do a multiline regex match? |
| 01:05 | hiredman | ,(re-find #"foo\nbar" "foo\nbar") |
| 01:05 | clojurebot | "foo\nbar" |
| 01:05 | hiredman | ,(re-find #"foo\nbar" "foobar") |
| 01:05 | clojurebot | nil |
| 01:07 | interferon | i have a string that looks like "Account\rfoo" |
| 01:07 | interferon | but Acc(.*) only gets "ount" in the first group[ |
| 01:07 | interferon | it's either not doing multiline or the \r is confusing it |
| 01:10 | hiredman | you aren't writing a csv parser are you? |
| 01:10 | hiredman | (just checking) |
| 01:11 | hiredman | (because really there are a million libraries for that and you should just use one, if that is what you are doing) |
| 01:11 | interferon | nope, QIF parser |
| 01:11 | interferon | ,(re-find #"Ac(.*)" "Account\rxyz") |
| 01:11 | clojurebot | ["Account" "count"] |
| 01:12 | interferon | i want what's after the line too... |
| 01:13 | hiredman | ,(re-find #"Ac(.*)+" "Account\rxyz") |
| 01:13 | hiredman | ,(re-find #"Ac(.*)+" "Account\rxyz") |
| 01:13 | clojurebot | ["Account" ""] |
| 01:15 | chouser | ,(re-find #"(?s)Ac(.*)" "Account\rxyz") |
| 01:15 | clojurebot | ["Account\rxyz" "count\rxyz"] |
| 01:15 | cark | Pattern.compile(regexString,Pattern.MULTILINE); |
| 01:15 | hiredman | " The regular expression . matches any character except a line terminator unless the DOTALL flag is specified. " |
| 01:15 | chouser | (?s) turns on DOTALL |
| 01:16 | hiredman | neat |
| 01:17 | chouser | "The s is a mnemonic for "single-line" mode, which is what this is called in Perl" |
| 01:17 | chouser | just to clear things up. :-P |
| 01:18 | hiredman | makes total sense |
| 01:18 | hiredman | … |
| 01:19 | slyrus_ | so what are we supposed to use now that add-classpath is deprecated? |
| 01:19 | hiredman | nothing |
| 01:20 | hiredman | you shouldn't be using add-classpath |
| 01:20 | hiredman | so it's removal should be a nop |
| 01:20 | slyrus_ | so how do you, say, add a jar to the classpath? |
| 01:20 | hiredman | you don't |
| 01:20 | hiredman | there is no reliable way to do it |
| 01:21 | hiredman | add-classpath fails in weird ways in weird places |
| 01:21 | slyrus_ | i get that. I've got a jar. I want clojure's java process to know about its contents. how do i tell clojure "hey, there's a whole bunch of java classes in this file -- go look in there!"? |
| 01:22 | hiredman | … |
| 01:22 | hiredman | you just rephrased the question I already answered |
| 01:22 | slyrus_ | is that some weird unicode smiley? |
| 01:22 | hiredman | if you want another answer ask a different question |
| 01:23 | hiredman | unicode ellipsis |
| 01:23 | hiredman | . . . |
| 01:23 | slyrus_ | i have a jar file, let's call it incanter.jar. i'd like clojure to know about its contents. how can i tell clojure that it should consider looking in incanter.jar for the class files? |
| 01:24 | hiredman | slyrus_: put it on your classpath |
| 01:24 | slyrus_ | great. how do i do that? add-classpath? |
| 01:24 | hiredman | -cp or CLASSPATH environment variable |
| 01:24 | hiredman | ~google java classpath |
| 01:24 | clojurebot | First, out of 292000 results is: |
| 01:24 | clojurebot | Setting the class path |
| 01:24 | clojurebot | http://java.sun.com/j2se/1.3/docs/tooldocs/win32/classpath.html |
| 01:24 | slyrus_ | bah. I don't want to do that at the time i start the damn process! |
| 01:25 | slyrus_ | i want to find the jar later. surely that's what add-classpath used to do, no? |
| 01:25 | hiredman | well, you can copy the implementation of add-classpath, just don't expect support when it fails |
| 01:25 | slyrus_ | i'm confused... are you telling me i have to know the jars I want to use when i _launch the process_? |
| 01:25 | hiredman | yes |
| 01:26 | JAS415 | its the java way |
| 01:26 | slyrus_ | I thought the whole point of clojure was that it was supposed to make the jvm dynamic! |
| 01:26 | cark | you can use wildcard in the classpath |
| 01:26 | hiredman | dynamic is a word that encompasses a wide variety of behaviour |
| 01:26 | JAS415 | you can load whatever clojure code you want :-) |
| 01:26 | slyrus_ | look, this whole jvm thing is ... interesting, but i expect things to be done the ... right way ... the lisp way. :) |
| 01:27 | hiredman | slyrus_: well, sign a CA and submit a patch |
| 01:27 | JAS415 | oh man |
| 01:27 | JAS415 | that would be a heck of a patch |
| 01:27 | slyrus_ | i guess i was just blissfully ignorantly using add-classpath before and everything seemed ok |
| 01:28 | JAS415 | rewrote JVM to make it lispy :-) |
| 01:28 | hiredman | ~add-classpath |
| 01:28 | clojurebot | add-classpath is bad, avoid it. I mean it! |
| 01:28 | cark | there are always limitations, even with CL, in practice the classpath stuff is no problem at all |
| 01:28 | hiredman | should have asked clojurebot |
| 01:29 | JAS415 | one time in CL I managed to get myself into a state where the code couldn't be loaded from a file |
| 01:29 | JAS415 | because there were like |
| 01:29 | JAS415 | forward and backward dependencies |
| 01:30 | JAS415 | it was a learning experience :-) |
| 01:30 | polypus | same thing happeded to me in C++ but we won't talk about that |
| 01:33 | polypus | does clojurebot have documentation someplace? |
| 01:33 | slyrus_ | i'm still in a state of shock here, but i find it hard to believe that there's no better way than to specify the location of the classes at the time the process is started. |
| 01:34 | slyrus_ | am i missing something really obvious here? |
| 01:34 | JAS415 | i was in that same state of shock for a while too |
| 01:34 | hiredman | polypus: docs for clojurebot? (no) |
| 01:35 | slyrus_ | JAS415: and then what? |
| 01:35 | JAS415 | i got really good at writing the bash script to start clojure with whatever jars i want |
| 01:35 | JAS415 | :-P |
| 01:35 | JAS415 | uh |
| 01:35 | JAS415 | also |
| 01:35 | JAS415 | what i tend to do |
| 01:35 | JAS415 | is i make a deps directory |
| 01:35 | hiredman | there is kind of a vague and incomplete list of the various plugins in the readme |
| 01:35 | JAS415 | and just point java at that with a wildcard |
| 01:36 | JAS415 | i end up with a couple copies of certain jars laying around |
| 01:36 | polypus | hiredman: ty |
| 01:36 | hiredman | I stick jars in ~/.jars and put $HOME/.jars/* on the classpath |
| 01:36 | JAS415 | but less of a headache to drop the jar into the directory than to rewrite thescript |
| 01:36 | cark | ah i do it on a per project basis |
| 01:36 | JAS415 | i do that to cark |
| 01:37 | JAS415 | mostly for startup time |
| 01:37 | cark | so that i stay with the same version of libs and clojure |
| 01:37 | JAS415 | (or at least in my semi-magical understanding it seems to change the startup time) |
| 01:37 | hiredman | I tend to move in that direction when I am farther down the road once dependencies have all been figured out |
| 01:37 | cark | also when you distribute the project, it's easy, no need to hunt for dependencies |
| 01:38 | cark | ah that makes sense |
| 01:38 | hiredman | otherwise I just throw everthing in .jars and it's always there if I need it |
| 01:38 | JAS415 | i built a jar the other day |
| 01:38 | JAS415 | that was exciting |
| 01:39 | JAS415 | i figured out the voodoo, did it, then promptly forgot :-/ |
| 01:40 | JAS415 | but you can get all of your deps into a single jar |
| 01:40 | cark | JAS415: http://github.com/cark/clj-exe-jar i just take this as a starting point |
| 01:40 | JAS415 | even clojure and clojurecontrib |
| 01:40 | JAS415 | that's a niceity |
| 01:40 | cark | run ant and be done with it |
| 01:40 | JAS415 | oh wow |
| 01:40 | JAS415 | cool |
| 01:41 | JAS415 | *bookmarked* |
| 01:53 | tomoj | I think there were a couple blog entries about it too |
| 01:54 | tomoj | (making executable clojure jars I mean) |
| 02:19 | timothypratley1 | is there a nice way to call 'read' on a string? |
| 02:20 | timothypratley1 | something like (read "{:a 1, :b 2}") <-- but not |
| 02:22 | danlarkin | read-string |
| 02:22 | timothypratley1 | danlarkin: thanks!!! |
| 03:09 | triyo | anyone using Leiningen to compile and build their projects? |
| 03:09 | tomoj | certainly someone is? |
| 03:10 | _ato | triyo: what's the problem? |
| 03:10 | triyo | It would be really cool if there was a command that generates .emacs entries for dev purpose (i.e. load all the deps jars) |
| 03:11 | _ato | triyo: do you know about M-x swank-clojure-project ? |
| 03:11 | triyo | _ato: no, I don't, how does it work? |
| 03:11 | tomoj | I would think that leiningen would work well with swank-clojure-project |
| 03:11 | tomoj | since I learned of both from the same person |
| 03:12 | _ato | just run it and it'll ask you for a project directory. Point it at the directory of your lein project and it'll start slime with the correct classpath |
| 03:12 | tomoj | does lein download deps into lib/? |
| 03:12 | _ato | yes |
| 03:12 | tomoj | I still haven't tried it :/ |
| 03:13 | tomoj | "maven repositories" scare me |
| 03:13 | triyo | _ato: oh great, thats awesome. I'll give it try |
| 03:13 | tomoj | I mean, say I have enlive as a dependency |
| 03:13 | tomoj | is it in maven somewhere? if not, will lein help me? |
| 03:14 | triyo | _ato: any ideas what swank-clojure-project module comes with? I don't seem to have it installed. I do have clojure slime / swank installed |
| 03:14 | _ato | If you run into trouble, you might need to copy ~/.swank-clojure/swank-clojure-1.0.jar into your-project/lib. I think it's supposed to add it automatically, but it doesn't work with my setup for some reason (I've probably broken it somehow when tinkering with my emacs config) |
| 03:14 | _ato | ah |
| 03:14 | _ato | triyo: you probably need a newer version of swank-clojure |
| 03:14 | _ato | triyo: did you install via ELPA? |
| 03:14 | triyo | yup |
| 03:15 | triyo | how do you do update again :>? |
| 03:15 | _ato | M-x package-list-packages |
| 03:15 | tomoj | I don't need to screw around with swank-clojure jars |
| 03:15 | tomoj | and I don't have a .swank-clojure |
| 03:16 | tomoj | ..maybe I have an old version |
| 03:16 | _ato | press "i" on the swank-clojure entry and hit C-c C-c (and pray) ;-) |
| 03:16 | tomoj | oh, I have swank-clojure from git |
| 03:16 | tomoj | (and clojure-moe) |
| 03:16 | mee | if there other other lurking clojure newbs here, this is good (if slow) http://blip.tv/file/2145329/ |
| 03:17 | triyo | ok I see swank-clojure 1.0... is that the right ver? |
| 03:17 | _ato | tomoj: looks like nobody has uploaded enlive to clojars yet |
| 03:17 | tomoj | mee: thanks, always love to find more clojure videos |
| 03:17 | _ato | triyo: that's the version I'm running |
| 03:21 | triyo | _ato: press "i" on the swank-clojure entry and hit C-c C-c -> C-c C-c undefined |
| 03:21 | piccolino | Aren't you supposed to hit X? |
| 03:22 | _ato | ah yeah |
| 03:22 | _ato | that's the one |
| 03:22 | triyo | hehe, yup it is |
| 03:22 | _ato | C-c C-c is "submit" or "go" in virtually every other mode |
| 03:24 | triyo | _ato: greate, it broke my slime :) |
| 03:25 | piccolino | Are you using some variant of Emacs 23? |
| 03:25 | _ato | piccolino: yeah |
| 03:25 | _ato | triyo: aww really? :( |
| 03:26 | triyo | piccolino: yup, aquamacs |
| 03:26 | piccolino | _ato, I was asking triyo. :) |
| 03:26 | piccolino | OK, Aquamacs 2.0? |
| 03:26 | triyo | nope, 1.8c |
| 03:26 | piccolino | Ah, Slime won't work on that. |
| 03:26 | piccolino | You need one of the 2.0 betas. |
| 03:26 | piccolino | Pre-2.0 is based on Emacs 22. |
| 03:27 | triyo | slime was working...it just broke when I installed swank-clojure |
| 03:27 | tomoj | hmm |
| 03:27 | tomoj | I thought I had slime+clojure working in a non-beta aquamacs |
| 03:27 | tomoj | triyo: what's the breakage look like? |
| 03:27 | piccolino | I dunno, I've only recently come to Clojure, but that was the reason it wasn't working for me, and upgrading Aquamacs fixed it. |
| 03:28 | piccolino | I'm sure regular slime works in 22. |
| 03:28 | piccolino | There was some undefined symbol or function in swank-clojure, as I recall, in 22. |
| 03:29 | tomoj | I think I might have had that same problem in gnu emacs |
| 03:29 | tomoj | but I don't remember how I fixed it :( |
| 03:29 | _ato | hmm, I guess make sure you've got the latest clojure-mode as well and also try commenting out all the swank/slime-related stuff in your .emacs |
| 03:29 | _ato | I run it with no configuration at all |
| 03:30 | tomoj | huh? |
| 03:30 | tomoj | don't you at least need to specify your clojure src directory? or is there a default? |
| 03:30 | _ato | it'll download it |
| 03:30 | _ato | to ~/.swank-clojure |
| 03:30 | tomoj | hm |
| 03:31 | tomoj | I must have an old version I guess |
| 03:31 | _ato | and I think it also looks like ~/.clojure |
| 03:31 | tomoj | I have to do (clojure-slime-config ...) |
| 03:31 | _ato | it does a whole bunch of magic these days |
| 03:31 | tomoj | though if I weren't also using slime for sbcl, that'd be all I needed to do |
| 03:31 | triyo | clojure-test-mode.el:87:1:Error: You must specifiy either a `swank-clojure-binary' or a `swank-clojure-jar-path' |
| 03:31 | triyo | oh, thats just clojure-test |
| 03:32 | tomoj | I think I will try upgrading, wish me luck :) |
| 03:32 | triyo | tomoj: 2.0preview3? |
| 03:32 | tomoj | of what, aquamacs? |
| 03:32 | triyo | yup |
| 03:33 | tomoj | I abandoned my mac a while ago |
| 03:33 | triyo | oh i see |
| 03:33 | tomoj | the clojure-mode/swank-clojure versions I was using with aquamacs are probably at least a couple months old |
| 03:33 | tomoj | but I'm sure I didn't use a beta version of aquamacs |
| 03:34 | triyo | When I run M-x slime -> You must specify either a "swank-clojure-binary" or a "swank-clojure-jar-path" |
| 03:34 | _ato | hmm |
| 03:35 | _ato | I just grepped my .emacs.d for swank-clojure-jar-path and got no hits |
| 03:35 | _ato | you must have an old version of something still |
| 03:35 | triyo | hmm |
| 03:36 | triyo | would it help to drop all downloaded packages and try fresh install? |
| 03:37 | _ato | I have: clojure-mode-1.6, clojure-test-mode-1.3, swank-clojure-1.0, slime-20091016, slime-repl-20091016 |
| 03:37 | tomoj | do you have a clojure-slime config? |
| 03:37 | tomoj | er, (clojure-slime-config ...)? |
| 03:37 | tomoj | maybe if you're using ELPA stuff this is no longer necessary |
| 03:37 | triyo | I upgraded clojure-mode from 1.3 to 1.6 |
| 03:38 | tomoj | I did a clojure-install in a non-default place and so needed to add a (clojure-slime-config ...) to my emacs config |
| 03:38 | _ato | maybe it didn't remove the old swank-clojure and just installed the new one on top or something. I had issues with upgrading stuff through ELPA |
| 03:38 | _ato | look in ~/.emacs.d/elpa |
| 03:39 | tomoj | when using elpa, are you restricted to whatever releases the people in control make? I feel like if I tried to use elpa I'd end up wanting some other fork or patches and wind up abandoned elpa for git anyway |
| 03:39 | triyo | yup you right, it hasn't removed the old ver |
| 03:41 | _ato | tomoj: well it doesn't stop you installing things manually, but yeah you only get the easy install for stuff that people have packages |
| 03:45 | _ato | ELPA still seems pretty buggy :-( It's not that great for someone who knows emacs well, but if you're new to it, it at least makes setting things up a bit easier. |
| 03:45 | _ato | The reason I'm using it is mainly just to try it out cause technomancy was talking about it all the time |
| 03:57 | mee | oh wow, ref validators are rad |
| 03:57 | triyo | correct me if I'm wrong, but isn't clojure-mode or one of other ELPA packages suppose to download clojure from github automatically? |
| 03:58 | _ato | triyo: yeah, it's supposed to happen when you do M-x slime |
| 03:58 | _ato | if it's not working check if you have a ~/.clojure or ~/.swank-clojure directory and if so rename it |
| 04:00 | _ato | sweet. javascript has a (weirdly-named) recur: return arguments.callee(arg1, arg2); |
| 05:02 | talios | 'lo |
| 05:03 | talios | Given a list of [:foo "bar" :bar "foo"] - how can I easily turn that into a map? I thought I saw something in clojure core for that, or I should I just use map or something? |
| 05:07 | arbscht | ,(apply hash-map [:foo "bar" :bar "foo"]) |
| 05:07 | clojurebot | {:foo "bar", :bar "foo"} |
| 05:07 | arbscht | like that? |
| 05:07 | talios | thats the one ;) |
| 05:08 | arbscht | :) |
| 05:09 | micampe | I am exploring clojure and I was trying to do it by myself |
| 05:09 | micampe | why is this giving an error? |
| 05:09 | micampe | (let [v [:foo "foo" :bar "bar"]] |
| 05:09 | micampe | (reduce conj {} (partition 2 v))) |
| 05:09 | talios | arbscht - first I had maven building clojure code, now I have maven building code WITH maven ( pom.clj ) :) |
| 05:11 | _ato | ,(reduce #(conj %1 %2) {} (partition 2 [:foo "foo" :bar "bar"])) |
| 05:11 | clojurebot | java.lang.Exception: Unable to resolve symbol: in this context |
| 05:11 | _ato | ,(reduce #(conj %1 %2) {} (partition 2 [:foo "foo" :bar "bar"])) |
| 05:12 | clojurebot | java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.util.Map$Entry |
| 05:12 | _ato | oh right |
| 05:12 | _ato | ,(reduce conj {} (partition 2 [:foo "foo" :bar "bar"])) |
| 05:12 | clojurebot | java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.util.Map$Entry |
| 05:12 | arbscht | ,(partition 2 [:foo "foo" :bar "bar"]) |
| 05:12 | clojurebot | ((:foo "foo") (:bar "bar")) |
| 05:12 | _ato | ,(reduce conj {} (map vec (partition 2 [:foo "foo" :bar "bar"]))) |
| 05:12 | clojurebot | {:bar "bar", :foo "foo"} |
| 05:12 | arbscht | (conj {} '(:foo "foo")) |
| 05:13 | _ato | ,(conj {} '(:foo "foo")) |
| 05:13 | clojurebot | java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.util.Map$Entry |
| 05:13 | _ato | so it looks like conj on a map can only take vectors, not lists |
| 05:13 | micampe | thanks |
| 05:13 | tomoj | ,(apply hash-map [:foo "foo" :bar "bar"]) |
| 05:13 | clojurebot | {:foo "foo", :bar "bar"} |
| 05:13 | tomoj | ? |
| 05:13 | arbscht | talios: interesting! |
| 05:14 | talios | arbscht - using a project similar to leiningen's, but this is using the maven3 polyglot apis |
| 05:15 | talios | whether I can get anything working enough to include in maven3 who knows ( not sure if this code base will be merged either ) |
| 06:06 | lisppaste8 | nipra pasted "dissoc for a list of keys" at http://paste.lisp.org/display/91630 |
| 06:07 | _ato | ,(dissoc {:a 1 :b 2 :c 3} :a :b :c) |
| 06:07 | clojurebot | {} |
| 06:07 | _ato | nipra: ^ |
| 06:08 | _ato | ,(apply dissoc {:a 1 :b 2 :c 3} [:a :b :c]) |
| 06:08 | clojurebot | {} |
| 06:08 | nipra | _ato, ?? |
| 06:09 | _ato | nipra: your paste? |
| 06:10 | _ato | just saying a simpler definition would be: (defn dissoc* [map keys] (apply dissoc map keys)) |
| 06:11 | nipra | _ato, oops.. yes :-) |
| 06:12 | nipra | my bad |
| 06:12 | nipra | didn't read the doc well |
| 06:33 | cgrand | _ato, tomoj: I think there's a problem with Clojar's search function: http://clojars.org/enlive is up since tuesday |
| 06:35 | AWizzArd | About monitors: in the repl i do (def x (Object.)) and then have a function (defn foo [n] (println n) (.wait x) (println "Ending" n)). Now I (dotimes [i 10] (future (foo i))) and then wait a bit and want to (.notifyAll x). |
| 06:36 | AWizzArd | Why does it throw an IllegalMonitorStateException? What can I do to become the owner of the Monitor? |
| 06:41 | _ato | cgrand: ah right, yeah it messes up when there's no description. I'll push a fix out for it tomorrow |
| 06:42 | cgrand | _ato: thanks, I'll put a description string |
| 06:43 | cgrand | AWizzArd: (locking x (.notifyAll x)) |
| 06:43 | AWizzArd | ok, let me try that |
| 06:45 | cgrand | AWizzArd: and wrap you .wait in a locking form too |
| 06:45 | AWizzArd | ok |
| 06:46 | AWizzArd | Okay, that works, thanks. |
| 07:17 | timothypratley1 | ,(str nil) |
| 07:17 | clojurebot | "" |
| 07:17 | timothypratley1 | how do I get "nil"? |
| 07:18 | _ato | ,(prn-string nil) |
| 07:18 | clojurebot | java.lang.Exception: Unable to resolve symbol: prn-string in this context |
| 07:18 | _ato | ,(prn-str nil) |
| 07:18 | clojurebot | "nil\n" |
| 07:18 | _ato | hmm |
| 07:19 | timothypratley1 | ah grea thanks _ato! |
| 07:19 | timothypratley1 | ,(pr-str nil) |
| 07:19 | clojurebot | "nil" |
| 07:19 | _ato | ah |
| 07:47 | StartsWithK | can i simulate 'let' form with push/pop-thread-bindings? http://paste.pocoo.org/show/155005/ |
| 07:47 | _ato | let is implemented differently, it doesn't use vars |
| 07:48 | _ato | I think anyway. ;-) |
| 07:49 | StartsWithK | i'm looking at LetExpr in compiler, and i can see it uses Var/pushThreadBindings |
| 07:50 | _ato | I could be wrong, but I'm pretty sure the compiler is using pushThreadBindings there to store a map of the local environment, but that's just a compile-time thing |
| 07:51 | _ato | it doesn't exist at runtime |
| 07:51 | StartsWithK | i see |
| 07:54 | _ato | also let bindings are lexically scope while thread bindings are dynamically scoped, so you can't even emulate a let binding with a thread binding |
| 07:55 | _ato | which means that if you close over a thread binding and then exit the binding form it won't work as you'd expect a let binding to |
| 07:56 | _ato | ,(binding [inc 5] ((fn [] inc))) |
| 07:56 | clojurebot | 5 |
| 07:56 | _ato | ,((binding [inc 5] (fn [] inc))) |
| 07:56 | clojurebot | #<core$inc__4732 clojure.core$inc__4732@1121f65> |
| 07:56 | _ato | ,((let [inc 5] (fn [] inc))) |
| 07:56 | clojurebot | 5 |
| 07:57 | StartsWithK | ,(binding [i 1] ((binding [i 2] (fn [] i)))) |
| 07:57 | clojurebot | java.lang.Exception: Unable to resolve var: i in this context |
| 07:58 | _ato | a thread-binding must be on an already existing var, that's why I used "inc" |
| 07:58 | StartsWithK | ,(binding [inc 1] ((binding [inc 2] (fn [] inc)))) |
| 07:58 | clojurebot | 1 |
| 07:58 | StartsWithK | :) your right, this is not let-like |
| 08:03 | _ato | ,(((fn [x] (fn [] x)) 4)) |
| 08:03 | clojurebot | 4 |
| 08:04 | _ato | ^ you can a closure to implement let |
| 08:04 | _ato | (at the expense of generating a whole bunch of unnecessary anonymous functions) |
| 08:04 | michaeljaaka | hello mastas |
| 08:04 | michaeljaaka | fast question |
| 08:04 | michaeljaaka | (defn me[ & a ] (if (seq a) true false)) |
| 08:04 | michaeljaaka | how to make equivalent with identity |
| 08:04 | michaeljaaka | ? |
| 08:05 | michaeljaaka | (defn me[ & a ] (identity (true? (seq a ))))) |
| 08:05 | michaeljaaka | doesn't work |
| 08:05 | Chousuke | just (seq a)? |
| 08:05 | michaeljaaka | :D |
| 08:05 | michaeljaaka | ehhh, it is time to go out ;D |
| 08:06 | _ato | (defn me [& a] (boolean (seq a))) if it absolutely has to return true/false |
| 08:06 | michaeljaaka | ok |
| 08:07 | michaeljaaka | yes I wanted to return true or false |
| 08:07 | michaeljaaka | but when I use seq in if |
| 08:07 | michaeljaaka | I should get true/false right? |
| 08:07 | michaeljaaka | the seq won't be evaluated |
| 08:07 | _ato | yes |
| 08:07 | _ato | that's correct |
| 08:08 | michaeljaaka | ok, thanks |
| 08:08 | StartsWithK | _ato: thanks, would that be a good way to construct let if trying to create one of thoes crazy metacircular evaluators? where environment would be replaced with normaln clojure namespace? |
| 08:09 | _ato | yeah that'd be one way to do it |
| 08:11 | _ato | also if you say wanted to write something that converts clojure code to say Python and wanted let to behave like it does in Clojure. In Python a local var is accessible anywhere in the function, not just inside the enclosing form. |
| 08:13 | StartsWithK | for now what i'll try to do is clojure->clojure with one extra special form so it has to have custom macro expander, i think that will be a good minimal start |
| 08:15 | StartsWithK | with-local-vars and bindings is not a problem, they realy use push/pop thread-bindings, so there should be no problem |
| 08:23 | StartsWithK | so (fn [] (let [a 1] (println a)) (println a)) -> (fn [] (let [a 1] (println a)) (let [a nil] (println a)) -> convert to python |
| 08:26 | _ato | other way around: (let [a 1] (println a)) -> ((fn [a] (println a)) 1) -> (lambda a: print(a))(1) |
| 08:26 | _ato | python doesn't have a "let" |
| 08:27 | _ato | of course the other way to do it is to keep track of your local environment and do clearing of vars and figure out nesting in the compiler, which is faster at runtime and what I think Clojure's compiler does. |
| 08:28 | _ato | but just turning lets into calls to anonymous functions is a really easy way to implement it |
| 08:44 | cgrand | _ato: thanks for the tip, http://clojars.org/search?q=enlive isn't empty anymore |
| 09:21 | triyo | I tried doing a clean install of swank-clojure and got this error during install -> swank-clojure.el:37:1:Error: Cannot open load file: clojure-mode |
| 09:23 | triyo | clojure-mode is a dependent, which it seem to have installed during install using ELPA |
| 09:25 | triyo | line 37 -> (require 'clojure-mode) |
| 09:28 | triyo | here is my full output of installing swank-clojure via ELPA: http://pastebin.com/m5d7c2d26 |
| 09:33 | _ato | stupid ELPA :( |
| 09:33 | _ato | that's crazy |
| 09:33 | _ato | it says it compiled it just above, why can't it now find it? |
| 09:33 | _ato | :/ |
| 09:33 | triyo | _ato: I am so so so unhappy now :) |
| 09:34 | triyo | ignore the smiley |
| 09:34 | triyo | I'll try continue as ELPA says all is installed fine... go figure |
| 09:35 | _ato | oh.. well it might be ok actually |
| 09:36 | _ato | I didn't read the output when I installed it, so I could have got the same thing :-P |
| 09:36 | triyo | hehe, can you try reinstall again see if you do get it? *just kidding* :) |
| 09:38 | _ato | I just did actually (in a fresh user account) |
| 09:38 | clojurebot | a is t |
| 09:38 | _ato | got the same error but for slime instead of clojure-mode |
| 09:38 | _ato | so yeah, looks like that's normal |
| 09:38 | triyo | hehe so seems thats ok |
| 09:39 | _ato | completely blank user: I pasted the ELPA stuff instead *scractch*, evaled it, did M-x package-list-packages, hit "i" on "swank-clojure", pressed "x". Let it download everything. M-x slime. "y" yes to install Clojure. let it download. Got a REPL |
| 09:40 | _ato | so that works ok. That's on regular Emacs 23 under Linux though. I don't have a mac handy to try aquamacs |
| 09:41 | _ato | does clojurebot like parens or something: (scala) |
| 09:41 | _ato | does clojurebot like parens or something: (in a fresh user account) |
| 09:41 | _ato | hmm... maybe it's random |
| 09:49 | triyo | On "do you want to install clojure y/n? I got -> "Wrong number of arguments: delete-directory, 2" |
| 09:49 | triyo | grr |
| 09:50 | triyo | _ato: what instructions do you use to install? |
| 09:50 | triyo | I must be doing something wrong |
| 09:53 | triyo | Ok, I think I got it....even better, I think I got it running just the way I wish I did in the first place.. |
| 09:54 | offby1 | ([2 3 5 7] 0) => 2, of course. What's an easy way to make ([2 3 5 7] 10) yield nil? I assume I can either handle the IndexOutOfBoundsException, or else perhaps there's some syntax or something that says "If the element isn't present, return this instead". What do y'all recommend? |
| 09:55 | triyo | _ato: I install swank-clojure then I ran swank-clojure-project and pointed to an existing leingen created project I have that has a /lib with all libs including swank-clojure, clojure-lang, etc. |
| 09:55 | Chousuke | offby1: pass it a second argument |
| 09:55 | Chousuke | ,([1 2] 5 :not-found) |
| 09:55 | clojurebot | java.lang.IllegalArgumentException: Wrong number of args passed to: PersistentVector |
| 09:55 | Chousuke | hm. |
| 09:55 | triyo | _ato: ohh it works 100% now |
| 09:55 | Chousuke | oh well |
| 09:55 | Chousuke | I guess you need to use get then |
| 09:56 | Chousuke | ,(get [1 2] 5 :not-found) should work :P |
| 09:56 | clojurebot | :not-found |
| 09:56 | offby1 | Chousuke: thanks |
| 09:57 | cark | any idea when the protocols will be somewhat stabilized ? |
| 09:57 | offby1 | Chousuke: figured it'd be something easy like that :) |
| 09:57 | cark | the "new" stuff |
| 09:58 | Chousuke | cark: I think the syntax is pretty much decided now. |
| 09:58 | cark | right now i have manu protocol files everywhere with multimethods ... i'd like to convert that to real protocols |
| 09:58 | cark | *many |
| 09:59 | cark | but i'm a bit shy ! |
| 10:14 | interferon | ,(defn parse-transactions (txs) (let [records (re-split #"\\r\\^\\r(?m)" txs)](map #(parse-detail (re-split #"\\r(?m)" %)) records))) |
| 10:14 | clojurebot | DENIED |
| 10:14 | interferon | when i evaluate that i get an obscure "cannot create iseq from symbol" exception |
| 10:14 | interferon | anyone see anything wrong with it? |
| 10:14 | cark | parameters to your function should be a vector |
| 10:15 | cark | (defn parse-transaction [txs] ... |
| 10:15 | interferon | oh man! |
| 10:15 | interferon | i feel dumb |
| 10:15 | interferon | thanks |
| 10:15 | interferon | used to CL :) |
| 10:15 | cark | i still get bitten by that after a year =/ |
| 10:24 | maddis | is there a way to do negation? like (!nil? foo), meaning "not nil" ? |
| 10:24 | interferon | maddis: (not foo) |
| 10:24 | interferon | is there a good clojure debugger? i love slime, but it seems like i can't do much once i hit an error |
| 10:24 | interferon | ,(not true) |
| 10:24 | clojurebot | false |
| 10:25 | interferon | ,(not false) |
| 10:25 | clojurebot | true |
| 10:25 | cark | you have println |
| 10:25 | cark | and if you want to get fancy, go with c.c.pprint ! |
| 10:25 | cark | seriously : you can use java debugers |
| 10:25 | maddis | oh thanks, of course, stupid me |
| 10:26 | rhickey | interferon: Java debuggers work well with Clojure - |
| 10:26 | interferon | i can still see clojure variables and function names in a java debugger? |
| 10:27 | cark | if you like single step hell i guess, i never even tried any debugger with clojure |
| 10:28 | rhickey | variables - yes, and function names get a slight but readable mangle. and you can set breakpoints in Clojure code |
| 10:29 | interferon | oh how do i set breakpoints? |
| 10:30 | interferon | and is there a clojure debugger in slime that i'm missing or is that feature not there? |
| 10:30 | rhickey | interferon: depends on the debugger - usually just park the cursor on the code |
| 10:31 | rhickey | interferon: I don't think Slime debugging works with CLojure as it does with CLs. It presumes an interleaving of the runtime with execution that doesn't exist in Clojure |
| 10:32 | interferon | oh i see what you mean |
| 10:32 | interferon | okay |
| 10:34 | triyo | swank-clojure docs shows that I can keep my CL implementation using: (add-to-list 'slime-lisp-implementations '(sbcl ("sbcl"))) and then running M-- M-x slime which enables me to type the impl name in. However it doesn't have my CL impl, it only has clojure. Am I missing something? |
| 10:35 | triyo | I just wish to run my working CL slime side-by-side with my clojure env |
| 10:35 | interferon | thought you meant something like a "(break)" form |
| 10:37 | interferon | ,(clojure.contrib.str-utils/re-split #"x.*b(?s)" "fooxy\nzbbar" ) |
| 10:37 | clojurebot | java.lang.ClassNotFoundException: clojure.contrib.str-utils |
| 10:38 | interferon | why doesn't that (?s) modifier make the . match anything? |
| 10:43 | interferon | ahh needs to be a the front |
| 10:43 | interferon | ,(re-find #"(?s)x.*b" "fooxy\nzbbar" ) |
| 10:43 | clojurebot | "xy\nzbb" |
| 10:43 | interferon | stay tune, while i answer more of my own questions |
| 10:55 | slyrus_ | speaking of swank-clojure... has there been any progress on making it run with the current slime CVS HEAD? |
| 10:56 | slyrus_ | whoops... my window was scrolled back a few screens. we weren't just talking about swank-clojure... |
| 10:56 | slyrus_ | oh, yes we were... too early for me. |
| 10:59 | rsynnott | The slime CVS head tends to be a moving target :) |
| 11:00 | rsynnott | It might almost make sense to incorporate swank-clojure into the swank project proper, but I suppose the maintainers mightn't want to do that |
| 11:01 | MikeDev | do you need to say return in clojure? |
| 11:02 | the-kenny | MikeDev: No. |
| 11:02 | the-kenny | The result of the last form us returned from a function |
| 11:15 | MikeDev | Ought one be able to defnine functions with clourebot |
| 11:17 | the-kenny | MikeDev: You can always define inline-functions |
| 11:17 | the-kenny | ,(let [myfun (fn [a |
| 11:17 | clojurebot | EOF while reading |
| 11:17 | the-kenny | oop |
| 11:18 | the-kenny | ,(let [myfun (fn [a] (inc a))] (myfun 42)) |
| 11:18 | clojurebot | 43 |
| 11:19 | MikeDev | so let's syntax is: let [def] expr |
| 11:20 | MikeDev | in ML it's let def in expr |
| 11:20 | the-kenny | (let [foo 42 bar 23] (list foo bar)) |
| 11:20 | the-kenny | ,(let [foo 42 bar 23] (list foo bar)) |
| 11:20 | clojurebot | (42 23) |
| 11:22 | MikeDev | for if it's (if (expr) expr expr)??? |
| 11:23 | the-kenny | (if (expr) expr else-expr |
| 11:23 | the-kenny | +) |
| 11:24 | Chousuke | actually just (if test-expr then-expr else-expr) |
| 11:24 | the-kenny | MikeDev: You can look at the api-docs on clojure.org. |
| 11:24 | the-kenny | There are plenty of examples on the site |
| 11:25 | MikeDev | I'm looking on clojure.org and the reference section sucks |
| 11:26 | the-kenny | http://richhickey.github.com/clojure/clojure.core-api.html |
| 11:26 | MikeDev | much better |
| 11:28 | Chousuke | let is not described very well by its docstring though :/ |
| 11:28 | the-kenny | Chousuke: let and every other special form too |
| 11:29 | Anniepoo | If some AI oriented person on this list is looking for a modest sized project a nice version of find-doc that had some intelligence would be a cool one |
| 11:29 | MikeDev | yeah that happens too but kenny fixed that 4 me |
| 11:30 | slyrus_ | liebke: you're missing a parenthesis in incanter.el |
| 11:31 | MikeDev | can a function return things of 2 completely diff types |
| 11:31 | JAS415 | yes? |
| 11:31 | alexyk | liebke: why did project.clj disappear? |
| 11:32 | offby1 | is (count x), when x is a list, fast? (i.e., constant-time?) |
| 11:32 | Chousuke | MikeDev: a function can return any descendant of Object currently. |
| 11:32 | chouser | offby1: yes |
| 11:32 | chouser | ,(counted (list 1 2 3)) |
| 11:32 | clojurebot | java.lang.Exception: Unable to resolve symbol: counted in this context |
| 11:32 | offby1 | chouser: thanks |
| 11:32 | Chousuke | offby1: For lists yes, but not for all sequences :/ |
| 11:32 | chouser | ,(counted? (list 1 2 3)) |
| 11:32 | clojurebot | true |
| 11:33 | Anniepoo | ,#([{:tacos "Yes!"} :deconstructionism 7]) |
| 11:33 | clojurebot | #<sandbox$eval__5478$fn__5480 sandbox$eval__5478$fn__5480@a6287> |
| 11:33 | MikeDev | for example, I'm making a function that will take a url arg and if valid, parse it and return a list of certain elements. If it's not a valid URL, I'd want to have an error of some sort. It would be nice to return either an error string or a list of 0 or more elements |
| 11:34 | liebke | alexyk: it is possible I broke the original incanter.el file technomancy contributed, but since I don't use emacs, I wouldn't have noticed. Can you submit the fixed version? |
| 11:34 | Anniepoo | while you can do that, why not have it throw an exception? |
| 11:34 | MikeDev | because I'm stupid and ont know how |
| 11:34 | liebke | alexyk: I removed project.clj until we have a version that can actually build the project |
| 11:34 | MikeDev | that prob would be best, yes |
| 11:34 | alexyk | liebke: that was slyrus :) I'm using TextMate |
| 11:35 | Anniepoo | ah, then there's no time like the present to learn |
| 11:35 | MikeDev | :) |
| 11:35 | alexyk | liebke: so for *using* incanter, just :dependencies [[incanter/incanter "0.9.0"]] is enough in a project.clj? |
| 11:35 | liebke | sorry :) |
| 11:35 | liebke | slyrus_ can you submit a fixed version of the el file? |
| 11:36 | MikeDev | Anniepoo, plus i have to get this done in a timely manner |
| 11:36 | liebke | alexyk: yes |
| 11:36 | chouser | ,(-> "Something failed" Exception. throw) |
| 11:36 | clojurebot | java.lang.Exception: Something failed |
| 11:36 | slyrus_ | liebke: can you be a bit more specific about what you mean by "submit"? e.g. send you an email with a patch? |
| 11:36 | Anniepoo | then use the exception. |
| 11:36 | alexyk | liebke: so incanter.jar sucks in all the deps? |
| 11:36 | Anniepoo | like that |
| 11:36 | MikeDev | i might be able to get a job doing this |
| 11:37 | alexyk | liebke: I miss fine-grained histogram control of R. E.g. specifying bucket boundaries... |
| 11:37 | liebke | alexyk: patches welcome :-) |
| 11:37 | MikeDev | and stop doing PHP content managed websites |
| 11:37 | clojurebot | we can't stop here! this is bat country! |
| 11:38 | Anniepoo | right now there are a large number of talented programmers who have discovered Clojure, but the message hasn't percolated |
| 11:38 | liebke | there are a lot of features I'd like to add to the charts library |
| 11:39 | MikeDev | is that exception code above to be considered an expression? |
| 11:39 | Anniepoo | to more conservative software devs/cto's/ceo's and so currently there's a shortage of clojure work |
| 11:39 | Anniepoo | but we all feel your pain |
| 11:39 | alexyk | liebke: so these JFreeCharts, are they actively under development? |
| 11:40 | liebke | yep: http://www.jfree.org/jfreechart/ |
| 11:40 | Anniepoo | jfreecharts are a good thing |
| 11:40 | liebke | i've only scratched the surface of the jfreechart api |
| 11:41 | Anniepoo | and would be a great application for a DSL |
| 11:42 | offby1 | I've got a loop that's orders of magnitude slower than I'd expect. How might I investigate? |
| 11:42 | Anniepoo | ,(import 'java.util.Date)(macroexpand '(.getDay (Date.))) |
| 11:42 | clojurebot | java.util.Date |
| 11:42 | cark | offby1 set *warb-on-reflection* to true |
| 11:42 | cark | then recompile |
| 11:42 | Anniepoo | ,(macroexpand '(.getDay (Date.))) |
| 11:42 | clojurebot | (. (Date.) getDay) |
| 11:43 | Anniepoo | ok, why does that expand to Date. and not (new Date)? |
| 11:43 | offby1 | cark: aaaaaahhh. |
| 11:44 | offby1 | cark: I'm not sure how to do that, though. I'm currently just loading a file; I don't know how to set the variable before compiling. I doubt it'll suffice to just stick an assignment at the top of the file. |
| 11:44 | cark | *warn-on-reflection* actually |
| 11:44 | cark | yes it will suffice |
| 11:44 | offby1 | that too. |
| 11:44 | offby1 | oh! |
| 11:44 | offby1 | ok, I'll try that |
| 11:45 | cark | if you have no warning, just show us some of your code =) |
| 11:47 | offby1 | cark: well, I do have a warning, but it's not blindingly obvious that it's pertinent. So here be the code: http://gist.github.com/249755 |
| 11:47 | offby1 | the slow loop is around line 35 |
| 11:50 | cark | count on a list is O(n) |
| 11:50 | cark | err i think |
| 11:50 | cark | try passing in a vector instead |
| 11:50 | offby1 | oh! |
| 11:51 | offby1 | but ... ,(counted? (list 1 2 3)) |
| 11:51 | offby1 | ,(counted? (list 1 2 3)) |
| 11:51 | clojurebot | true |
| 11:51 | offby1 | I thought that implied it was O(1) |
| 11:51 | chouser | count on a PersistentList is O(1) |
| 11:51 | cark | ah right, anyways you should test with (seq words) |
| 11:51 | offby1 | is that the equivalent to Scheme's (not (null? words)) |
| 11:51 | chouser | offby1: are you using set/union to add a single thing to a set? |
| 11:52 | offby1 | chouser: I think so, lemme double-check |
| 11:52 | cark | offby1 : yes |
| 11:52 | offby1 | should I use conj? |
| 11:52 | chouser | I bet that's slow. try conj instead. |
| 11:52 | chouser | ,(conj #{1 2 3} 4) |
| 11:52 | clojurebot | #{1 2 3 4} |
| 11:52 | cark | anyways you're passing in a lazy list, not a persistent list (i think) |
| 11:52 | offby1 | ,(conj #{1 2} 2) |
| 11:52 | clojurebot | #{1 2} |
| 11:52 | offby1 | hm |
| 11:53 | chouser | yeah, don't use (zero? (count words)), just (seq words) |
| 11:53 | cark | ,(counted? (filter odd? (list 1 2 3 4))) |
| 11:53 | clojurebot | false |
| 11:54 | offby1 | ,(conj #{"x" "y"} "x") |
| 11:54 | clojurebot | #{"x" "y"} |
| 11:54 | ikitat | anyone know why `lein swank` would fail with (use 'clojure.test) in the repl? |
| 11:57 | cark | offby1 : i wonder why you're not using reduce =/ |
| 12:00 | MikeDev | ,(re-matches #"<h[1-6]>.*?</h[1-6]>" "<h1>Clow</h1><div><h2>Jure</h2></div>") |
| 12:00 | clojurebot | nil |
| 12:01 | MikeDev | why? |
| 12:01 | MikeDev | It works in perl |
| 12:01 | offby1 | cark: probably because I didn't know it existed |
| 12:01 | cark | hehe =) |
| 12:03 | offby1 | I stuck (seq words) in instead of (zero?(count words)), but that made the test fail. |
| 12:03 | ikitat | ,(re-find #"<h[1-6]>.*?</h[1-6]>" "<h1>Clow</h1><div><h2>Jure</h2></div>") |
| 12:03 | clojurebot | "<h1>Clow</h1>" |
| 12:03 | MikeDev | yeah ok |
| 12:03 | offby1 | ,(seq? (list)) |
| 12:03 | clojurebot | true |
| 12:03 | offby1 | ,(seq (list)) |
| 12:03 | clojurebot | nil |
| 12:03 | offby1 | ,(seq (list 1)) |
| 12:03 | clojurebot | (1) |
| 12:05 | alexyk | liebke: lein deps/repl works fine for an incanter app! nice |
| 12:05 | offby1 | cark: what is this =/ of which you speak? |
| 12:06 | alexyk | so in lein, as opposed to mvn, you specify a top dependency alone, and all the subdeps are included, apparently |
| 12:07 | cark | offby1 : err sorry that a smiley |
| 12:08 | offby1 | ah |
| 12:08 | offby1 | I considered "reduce". Can't remember why I didn't use it |
| 12:08 | offby1 | anyway, using (seq words), despite my earlier protestation, works great; thanks. |
| 12:08 | cark | great |
| 12:28 | MikeDev | Question: does clojure have an html parser? |
| 12:29 | MikeDev | http://clojure.org/libraries sez maybe clj-html? |
| 12:30 | MikeDev | but doesnt look like it |
| 12:30 | MikeDev | upon further review |
| 12:33 | mikem | MikeDev: you could try using a Java library for that (ie: TagSoup) |
| 12:34 | MikeDev | k |
| 12:41 | chouser | tagsoup is beatiful, and works well with clojure.xml, clojure.contrib.lazy-xml, and then zip and zip-filter |
| 12:42 | chouser | beautiful |
| 12:43 | MikeDev | if you had a big tree structure of an html document, how do you easily pull out certain tags that could be arbitrarily deep |
| 12:45 | the-kenny | MikeDev: Xpath |
| 12:45 | the-kenny | MikeDev: There's also something in contrib, wait |
| 12:45 | the-kenny | c.c.zip-filter |
| 12:45 | the-kenny | That's almost xpath, but in clojure-style |
| 12:46 | MikeDev | so i have to download tagsoup right? |
| 12:47 | MikeDev | wouldnt be standard right? |
| 12:48 | the-kenny | tagsoup? |
| 12:51 | MikeDev | yes |
| 12:52 | the-kenny | What's that? |
| 12:52 | MikeDev | I hope this is fine: http://home.ccil.org/~cowan/XML/tagsoup/tagsoup-1.2.jar |
| 12:52 | KirinDave | cgrand-r1c: Hey, are you around? |
| 12:53 | MikeDev | can u just use any java class with clojure? |
| 12:53 | the-kenny | MikeDev: Yes |
| 12:53 | MikeDev | neet |
| 12:54 | the-kenny | MikeDev: But you won't need tagsoup.jar or any other external library to use c.c.zip-filter. It's written in clojure and integrated in contrib |
| 12:55 | the-kenny | MikeDev: Clojure's Java-Interop: http://clojure.org/java_interop |
| 12:56 | MikeDev | kenny: zip-filter can parse HTML and not just XML |
| 12:56 | MikeDev | ? |
| 12:56 | the-kenny | MikeDev: xhtml is valid xml. "normal" html should be xml too |
| 12:56 | MikeDev | html 4 strict isnt |
| 12:56 | MikeDev | <br> |
| 12:57 | the-kenny | hm... I would give it a try |
| 12:57 | the-kenny | Maybe it can handle the special cases of html |
| 12:58 | MikeDev | bear in mind that all i need to do is process header tags. dont care about anything else. the only reason I ask about html parsers is that the guys in #perl are saying I suck if I dont use an html parser |
| 12:59 | MikeDev | i think I will just use re's |
| 12:59 | MikeDev | particularly over something more complicated that might not work anyway |
| 13:11 | MikeDev | So if you do (?'Name'pattern) in a re, you are supposed to be able to recall it in the pattern later with \k'Name' ? |
| 13:11 | danlarkin | java regexes doen't support named groups |
| 13:12 | MikeDev | i see |
| 13:13 | KirinDave | Ahah, got enlive working. :\ |
| 13:15 | KirinDave | I gotta patch that. |
| 13:15 | KirinDave | it shouldnt throw a null pointer exception for a missing file. |
| 13:15 | KirinDave | This is the problem with direct code generation macro systems. People get so caught up in the codegen logic that it gets difficult to add solid error handling. |
| 13:16 | KirinDave | clj needs MBE. |
| 13:19 | interferon | i'm having a hard time working with a data structure i've set up. basically, i have a map of vendor names to vendor structs. each vendor struct has an :inventory key that contains a list of inventory structs, each of which contains a name and a quantity |
| 13:20 | interferon | if i want to adjust the quantity of one product for one vendor, my code becomes somewhat convoluted |
| 13:20 | interferon | are there any guides to working with complex structures like this? |
| 13:20 | arohner | KirinDave: what is MBE? |
| 13:20 | chouser | MikeDev: tagsoup parses broken html pages as if they were valid xml, so you can feed that into clojure.xml/parse or clojure.contrib.lazy-xml |
| 13:21 | cark | interferon : go bottom-up ... first write functions that work with your inventory structs |
| 13:21 | cark | taking the struct as first parameter |
| 13:21 | interferon | here's what i have now http://paste.lisp.org/display/91655 |
| 13:21 | cark | the you can go one level up |
| 13:21 | cark | then* |
| 13:22 | KirinDave | arohner: PLT Scheme has a different macro system that many people have adopted |
| 13:22 | KirinDave | there are even CL libraries for it |
| 13:22 | KirinDave | It's called "Macro By Example" |
| 13:22 | KirinDave | Or "pattern macros" |
| 13:22 | KirinDave | http://docs.plt-scheme.org/guide/pattern-macros.html |
| 13:22 | KirinDave | It also is a good way to encapsulate truly hygienic macros. |
| 13:23 | arohner | interferon: probably the biggest lesson I've learned about writing clj code is to build composable functions. Small functions with a clearly identified purpose |
| 13:23 | cark | interferon : so when you want to go a level up you can use update-in, using your lower level functions |
| 13:24 | arohner | interferon: well designed functions play nicely with map, filter, reduce, etc |
| 13:24 | arohner | or whatever the appropriate core functions for your datastructure is |
| 13:24 | interferon | is update-in built-in? |
| 13:25 | arohner | yes |
| 13:26 | arohner | ,(doc update-in) |
| 13:26 | clojurebot | "([m [k & ks] f & args]); 'Updates' a value in a nested associative structure, where ks is a sequence of keys and f is a function that will take the old value and any supplied args and return the new value, and returns a new nested structure. If any levels do not exist, hash-maps will be created." |
| 13:26 | cark | of course it's not always that simple... but that should get you going |
| 13:27 | arohner | KirinDave: thanks. this is probably the first documentation for syntax rule that I've ever understood |
| 13:28 | cark | you're using merge when assoc should do the work, or assoc-in or update-in |
| 13:30 | cark | in the end you should have an api such that you can (update-vendor "paul" add-inventory "nasal spray" 2) |
| 13:30 | cark | or something like it =) |
| 13:31 | interferon | can someone explain how -> works? |
| 13:33 | cark | ,(-> "hello" count inc) |
| 13:33 | clojurebot | 6 |
| 13:33 | cark | ,(-> "hello" count inc (* 5)) |
| 13:33 | clojurebot | 30 |
| 13:34 | cark | ,(-> {:a 1 :b {:c 2 :d 3}} :a :d) |
| 13:34 | clojurebot | nil |
| 13:34 | cark | ,(-> {:a 1 :b {:c 2 :d 3}} :b :d) |
| 13:34 | clojurebot | 3 |
| 13:35 | cark | ,(:d (:b {:a 1 :b {:c 2 :d 3}})) |
| 13:35 | clojurebot | 3 |
| 13:35 | dulanov | vah, (count (range 100)) |
| 13:35 | dulanov | (count (range 100)) |
| 13:35 | dulanov | ,(count (range 100)) |
| 13:35 | clojurebot | 100 |
| 13:36 | interferon | so it applies functions in a chain? |
| 13:36 | KirinDave | arohner: It's not new. PLT Scheme has fabulous documentation, they have for years. |
| 13:36 | cark | ,(doc ->) |
| 13:36 | clojurebot | "([x form] [x form & more]); Threads the expr through the forms. Inserts x as the second item in the first form, making a list of it if it is not a list already. If there are more forms, inserts the first form as the second item in second form, etc." |
| 13:36 | MikeDev | suppose you *know* that the arg to function will be a list of which you want the second element. can u pattern match on that? |
| 13:36 | MikeDev | in ML you can do fun Blah a::list |
| 13:37 | cark | interferon : you can use macroexpand to see what a macro does |
| 13:37 | KirinDave | MikeDev: You mean, checking type? Or deconstructing objects in the list? |
| 13:37 | MikeDev | probably deconstructing |
| 13:37 | KirinDave | MikeDev: Because then it's no and yes. |
| 13:38 | MikeDev | in ML you can do fun blah a | fun blah a::list |
| 13:38 | MikeDev | | fun blah nil |
| 13:38 | cark | ,((fn [[_ a]] (inc a)) 10) |
| 13:38 | clojurebot | java.lang.UnsupportedOperationException: nth not supported on this type: Integer |
| 13:38 | cark | ,((fn [[_ a]] (inc a)) (list 10 11)) |
| 13:38 | clojurebot | 12 |
| 13:38 | interferon | update-in is very helpful - thanks guys |
| 13:39 | MikeDev | so can I do fn [a b] = b |
| 13:40 | the-kenny | MikeDev: Looks like haskell |
| 13:40 | cark | that's what i showed or did i misunderstand your question ? |
| 13:41 | MikeDev | i guess |
| 13:42 | arohner | KirinDave: I hadn't seen PLT's documentation before. I always saw links to either R5RS or some random blog post. Those weren't very good. |
| 13:43 | arohner | lisppaste8: url |
| 13:43 | lisppaste8 | To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste. |
| 13:43 | MikeDev | cark, no yours is a list of 2 i have a list of n which are lists of 2 |
| 13:43 | MikeDev | i guess i need map |
| 13:43 | lisppaste8 | arohner pasted "weak reference" at http://paste.lisp.org/display/91658 |
| 13:44 | arohner | weak-reference seems useful. I wonder if it is worthy to go into contrib |
| 13:45 | MikeDev | ,(re-seq #"<h[1-6]>(.*?)</h[1-6]>" "<h1>Clow</h1><div><h2>Jure</h2></div>") |
| 13:45 | clojurebot | (["<h1>Clow</h1>" "Clow"] ["<h2>Jure</h2>" "Jure"]) |
| 13:45 | MikeDev | want the 2nd args |
| 13:45 | MikeDev | is that a list of lists? |
| 13:45 | the-kenny | MikeDev: Yes |
| 13:45 | MikeDev | a list of vectors? |
| 13:46 | the-kenny | list of vectors |
| 13:46 | the-kenny | now just (map second your-result) |
| 13:46 | MikeDev | ,(map (fn [[_ b]] (b)) (re-seq #"<h[1-6]>(.*?)</h[1-6]>" "<h1>Clow</h1><div><h2>Jure</h2></div>")) |
| 13:46 | clojurebot | java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn |
| 13:46 | MikeDev | That is what I thought would work |
| 13:46 | MikeDev | ,(map (fn [_ b] (b)) (re-seq #"<h[1-6]>(.*?)</h[1-6]>" "<h1>Clow</h1><div><h2>Jure</h2></div>")) |
| 13:46 | clojurebot | java.lang.IllegalArgumentException: Wrong number of args passed to: sandbox$eval--5653$fn |
| 13:47 | the-kenny | why (b) |
| 13:47 | the-kenny | you try to call the function in b, but b holds a string |
| 13:47 | the-kenny | oh.. and you can just use second |
| 13:47 | MikeDev | thought that's how fn's are defined syntactialy |
| 13:47 | the-kenny | ,(map second (list ["foo" "bar"] ["bla" "foobar"])) |
| 13:47 | clojurebot | ("bar" "foobar") |
| 13:47 | the-kenny | No |
| 13:48 | the-kenny | ,((fn [_ a] a) 42) |
| 13:48 | clojurebot | java.lang.IllegalArgumentException: Wrong number of args passed to: sandbox$eval--5668$fn |
| 13:48 | the-kenny | ,((fn [_ a] a) 42 23) |
| 13:48 | clojurebot | 23 |
| 13:48 | the-kenny | ,((fn [_ a] (a)) 42 (fn [] 23)) |
| 13:48 | clojurebot | 23 |
| 13:48 | the-kenny | ,("foobar") |
| 13:48 | clojurebot | java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn |
| 13:48 | MikeDev | seond will work |
| 13:49 | the-kenny | Yes |
| 13:49 | solussd | is there a function/macro that prints the code for a function? |
| 13:49 | the-kenny | and take a look at the syntax for (fn) |
| 13:49 | solussd | e.g. (show-code loop) |
| 13:49 | the-kenny | solussd: I think so. Somewhere in clojure.contrib |
| 13:49 | the-kenny | repl-utils iirc |
| 13:49 | solussd | thanks |
| 13:50 | the-kenny | (use 'clojure.contrib.repl-utils) |
| 13:50 | arohner | source in repl-utils |
| 13:50 | the-kenny | ,(use 'clojure.contrib.repl-utils) |
| 13:50 | clojurebot | java.lang.ExceptionInInitializerError |
| 13:50 | solussd | yep. found it |
| 14:06 | MikeDev | Is there any kind of filter function which will go thru a list, apply a function you create to each item, and return a list of only the items for which your function returned true? |
| 14:07 | solussd | yes, filter does that |
| 14:07 | the-kenny | MikeDev: (first (filter ...))? |
| 14:07 | the-kenny | Oh, I read "only one item" |
| 14:07 | the-kenny | sorry |
| 14:07 | MikeDev | only *the* items |
| 14:07 | MikeDev | didnt see filter in cor |
| 14:07 | MikeDev | core* |
| 14:07 | solussd | ,(filter #(= 3) [1 2 3 4 5 6 3]) |
| 14:08 | clojurebot | java.lang.IllegalArgumentException: Wrong number of args passed to: sandbox$eval--5698$fn |
| 14:08 | MikeDev | no filter: http://richhickey.github.com/clojure/clojure.core-api.html |
| 14:08 | solussd | ,(filter #(= 3 %) [1 2 3 4 5 6 3]) |
| 14:08 | clojurebot | (3 3) |
| 14:08 | the-kenny | ,(doc filter) |
| 14:08 | clojurebot | "([pred coll]); " |
| 14:08 | MikeDev | that's fine, thx |
| 14:09 | KirinDave | Man |
| 14:09 | KirinDave | Wtf |
| 14:09 | KirinDave | http://github.com/richhickey/clojure-contrib/blob/5055f41c8bc99747392396d622f17f723470858e/src/clojure/contrib/http/agent.clj#L306 |
| 14:09 | KirinDave | ,(#{:foo :baz} {:foo 1 :bar 2 :baz 3}) |
| 14:09 | clojurebot | nil |
| 14:09 | KirinDave | I'm confused. |
| 14:10 | offby1 | (printf "foo") goes to stdout. How do I print to stderr? |
| 14:10 | MikeDev | printf 2 "foo" |
| 14:10 | MikeDev | (maybe) |
| 14:10 | arohner | ,(#{:foo :baz} :foo) |
| 14:10 | clojurebot | :foo |
| 14:10 | arohner | ,(#{:foo :baz} :bogus) |
| 14:10 | clojurebot | nil |
| 14:10 | KirinDave | Ahh, I see |
| 14:10 | arohner | that's checking whether an item belongs to a set |
| 14:10 | KirinDave | Yeah, I was reading it backwards |
| 14:10 | KirinDave | like, "Can you union two keys with a set for access into a hash? |
| 14:10 | solussd | a set is function |
| 14:11 | KirinDave | That'd actually be pretty cool. |
| 14:11 | offby1 | dynamically bind *out*, maybe |
| 14:11 | arohner | offby1: yeah |
| 14:11 | arohner | (binding [*out* error-stream] (println ...) |
| 14:12 | MikeDev | if there's a second, is there a third? |
| 14:12 | arohner | I think there's a name for stderr, but I don't remember what it is |
| 14:12 | arohner | oh, *err* |
| 14:12 | arohner | duh |
| 14:12 | offby1 | System/err, I'd guess |
| 14:12 | arohner | ,(doc *err*) |
| 14:12 | clojurebot | "; A java.io.Writer object representing standard error for print operations. Defaults to System/err, wrapped in a PrintWriter" |
| 14:14 | MikeDev | ,((fn [z y x] x) ["a" "b" "c"]) |
| 14:14 | clojurebot | java.lang.IllegalArgumentException: Wrong number of args passed to: sandbox$eval--5772$fn |
| 14:14 | offby1 | ,(print "hey") |
| 14:15 | clojurebot | hey |
| 14:15 | offby1 | ,(binding [*out* *err*](print "hey")) |
| 14:15 | clojurebot | nil |
| 14:15 | clojurebot | hey |
| 14:15 | offby1 | odd, the output vanishes when I try it :-| |
| 14:15 | arohner | where are you trying it? |
| 14:16 | solussd | MikeDev, I think you want 'apply' |
| 14:16 | arohner | something in your environment could be ignoring/ dropping stderr |
| 14:16 | dulanov | ,(.toString *out*) |
| 14:16 | clojurebot | "" |
| 14:16 | solussd | (apply (fn [z y x] x) ["a" "b" "c"]) |
| 14:16 | dulanov | ,(class*out*) |
| 14:16 | clojurebot | java.lang.Exception: Unable to resolve symbol: class*out* in this context |
| 14:16 | solussd | ,(apply (fn [z y x] x) ["a" "b" "c"]) |
| 14:16 | clojurebot | "c" |
| 14:17 | arohner | stupid keyboard shortcuts |
| 14:17 | solussd | or you could just pass the vec as args: |
| 14:17 | arohner | I hate that emacs shortcuts typed into another other program does bad stuff |
| 14:17 | arohner | * into any other program |
| 14:17 | solussd | ,((fn [z y x] x) "a" "b" "c") |
| 14:17 | clojurebot | "c" |
| 14:18 | dulanov | ,((fn [_ _ x] x "a" "b" "c") |
| 14:18 | clojurebot | EOF while reading |
| 14:18 | dulanov | ,((fn [_ _ x] x) "a" "b" "c") |
| 14:18 | clojurebot | "c" |
| 14:18 | the-kenny | arohner: I really miss paredit in almost every other program... I keep forgetting to close braces |
| 14:18 | solussd | paredit is a pain though if you want to rearrange things... |
| 14:19 | dulanov | ,(#(%3) "a" "b" "c") |
| 14:19 | clojurebot | java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn |
| 14:19 | arohner | the-kenny: I'd be happy with ctrl-N, ctrl-P, ctrl-W not doing destructive things or popping up dialog boxes |
| 14:19 | the-kenny | solussd: "Rearrange"? |
| 14:19 | dulanov | ,(#('%3) "a" "b" "c") |
| 14:19 | clojurebot | java.lang.IllegalArgumentException: Wrong number of args passed to: Symbol |
| 14:19 | arohner | or leaving chat rooms... |
| 14:20 | arohner | dulanov: #() is not the same as fn |
| 14:20 | solussd | the-kenny: in emacs, using paredit always balances your parens, If I want to kill the end of a line (with closing parens) and maybe yank it somewhere else, it seems to get in the way. |
| 14:21 | Chousuke | solussd: use C-k to kill s-exps instead :/ |
| 14:21 | solussd | the-kenny: but I only used it for maybe an hour before getting frustrated with it, so what do i know... |
| 14:21 | the-kenny | solussd: hm.. I understand what you mean |
| 14:21 | MikeDev | hey I fed a bad thing to closurebot how do I cancel it |
| 14:21 | MikeDev | now it just hangs for me |
| 14:21 | Chousuke | solussd: it makes no sense to delete everything to the end of the line if it breaks the s-exp structure. :) |
| 14:21 | the-kenny | But I like it for lisp-development. As Chousuke said, it will yank the sexp instead |
| 14:22 | MikeDev | nevermind, it' thinkgs |
| 14:22 | solussd | Chousuke: i'm sure I'd learn to work with it if I gave it enough of a chance. It would probably just spoil me though. :) |
| 14:22 | Chousuke | solussd: yeah, it does :P |
| 14:22 | the-kenny | It always keep the sexp-tree valid :) |
| 14:22 | Chousuke | sometimes you can end up with mismatching parens though :/ |
| 14:23 | Chousuke | but then it's not too difficult to force emacs to insert them |
| 14:26 | the-kenny | agh... |
| 14:26 | solussd | which git repository? |
| 14:27 | Chousuke | the-kenny: just delete the commit :) |
| 14:27 | the-kenny | Chousuke: ..or change the password ;) |
| 14:27 | Chousuke | well, whichever. |
| 14:27 | the-kenny | I think I already committed it with the initial commit... It's easier to change it |
| 14:28 | Chousuke | heh |
| 14:28 | Chousuke | you could also use git's history filtering features! |
| 14:29 | Chousuke | I like how nothing is sacred in git :P |
| 14:29 | the-kenny | I could also shoot myself in the foot :p |
| 14:29 | Chousuke | you can change anything at any time and it's not git's problem if that breaks things. |
| 14:39 | MikeDev | how do you cast a string to a char sequence? |
| 14:39 | cark | ,(seq "blah") |
| 14:39 | clojurebot | (\b \l \a \h) |
| 14:39 | MikeDev | ty |
| 14:41 | JAS415 | the-kenny needs to use oauth :-P |
| 14:42 | the-kenny | JAS415: hm.. Maybe I'll have a look at oauth ;) But I have to refactor some files before that |
| 14:44 | eno__ | how do you get the key of a map with max value? |
| 14:44 | eno__ | e.g. {:three 3 :five 5 :four 4}, I want to get :five |
| 14:51 | j3ff86 | eno, i have a function that does that, let me get it |
| 14:53 | j3ff86 | (apply max-key second (indexed coll)))) |
| 14:53 | eno__ | j3ff86: thx |
| 14:54 | j3ff86 | (apply max-key second (indexed coll)) |
| 14:56 | j3ff86 | actually i dont know if it works for symbols |
| 14:56 | eno__ | not quite |
| 14:58 | eno__ | ,(let [m {:three 3 :five 5 :four 4}] (apply max-key #(val (second %)) (indexed m))) |
| 14:58 | clojurebot | [1 [:five 5]] |
| 14:58 | eno__ | getting close |
| 15:00 | eno__ | ,(let [m {:three 3 :five 5 :four 4}] (key (second (apply max-key #(val (second %)) (indexed m)))) |
| 15:00 | clojurebot | EOF while reading |
| 15:01 | eno__ | ,(let [m {:three 3 :five 5 :four 4}] (key (second (apply max-key #(val (second %)) (indexed m))))) |
| 15:01 | clojurebot | :five |
| 15:10 | MikeDev | What is :blah all about? |
| 15:11 | Chousuke | it's a keyword |
| 15:11 | Chousuke | a symbol which evaluates to itself. |
| 15:12 | Chousuke | hmm |
| 15:12 | Chousuke | ,(map identical? [:foo 'bar] [:foo 'bar]) |
| 15:12 | clojurebot | (true false) |
| 15:12 | MikeDev | Hey keyword, why dont you go evaluate yourself? |
| 15:12 | JAS415 | the-kenny: i used this when i did oauth in clojure: http://code.google.com/p/oauth-signpost/ |
| 15:14 | the-kenny | JAS415: I'll bookmark this. Thanks :) |
| 15:15 | ska2342 | Chousuke: (identical 'bar 'bar) is false, because quote creates a new symbol every time. |
| 15:15 | ska2342 | ..identical?.. |
| 15:16 | Chousuke | ska2342: yeah |
| 15:17 | ska2342 | Chousuke: do you have any idea, how to access a symbol later again? E.g. to retrieve metadata associated with that sym? |
| 15:18 | chouser | the reader creates a new symbol every time, whether it's quoted or not |
| 15:18 | StartsWithK | ,(let [m {:three 3 :five 4 :four 4}] (-> m seq (apply max-key second) first)) |
| 15:18 | clojurebot | java.lang.ClassCastException: clojure.lang.PersistentArrayMap$Seq cannot be cast to clojure.lang.IFn |
| 15:18 | StartsWithK | ,(let [m {:three 3 :five 4 :four 4}] (->> m seq (apply max-key second) first)) |
| 15:18 | clojurebot | :four |
| 15:18 | StartsWithK | ups |
| 15:19 | chouser | ,(apply = ((juxt first second) '(:foo :foo))) |
| 15:19 | clojurebot | true |
| 15:19 | chouser | ,(apply = ((juxt first second) '(foo foo))) |
| 15:19 | clojurebot | true |
| 15:19 | chouser | ,(apply identical? ((juxt first second) '(foo foo))) |
| 15:19 | clojurebot | false |
| 15:19 | chouser | ,(apply identical? ((juxt first second) '(:foo :foo))) |
| 15:19 | clojurebot | true |
| 15:20 | ska2342 | chouser: I already tried to get an answer to this from the groups, but w/o success. If I create a symbol and add metadata to it, how can I access the metadata of /that symbol/ later (not a copy of it attached to a Var)? |
| 15:23 | MikeDev | what is string concat? |
| 15:23 | MikeDev | ,(. "a" "b") |
| 15:23 | clojurebot | java.lang.IllegalArgumentException: Malformed member expression |
| 15:23 | MikeDev | ,(+ "a" "b") |
| 15:23 | clojurebot | java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number |
| 15:24 | eno | ,(str "abc" "def") |
| 15:24 | clojurebot | "abcdef" |
| 15:24 | MikeDev | ,(str "a" "b") |
| 15:24 | clojurebot | "ab" |
| 15:24 | MikeDev | k |
| 15:24 | ska2342 | ,(str "first" "second") |
| 15:24 | clojurebot | "firstsecond" |
| 15:26 | ekontsevoy | http://clojure.org/libraries says "There are many libraries for Clojure that complement what is in the Clojure core" and then goes a long list of clojure.contrib.* pacakges, but where's a reference for aforementioned "Clojure Core"? Or should I use verbose Java SE for everything? |
| 15:27 | dulanov | http://richhickey.github.com/clojure/ |
| 15:27 | dulanov | ? |
| 15:27 | dulanov | API section |
| 15:28 | ekontsevoy | Oh! Thanks |
| 15:29 | ska23421 | chouser: is my question concerning symbols and metadata too stupid? Am I missing something easy and important? |
| 15:31 | hiredman | ,(meta (with-meta 'foo {:bar 1})) |
| 15:31 | clojurebot | {:bar 1} |
| 15:31 | hiredman | ,(identical? 'foo 'foo) |
| 15:31 | clojurebot | false |
| 15:32 | ska23421 | hiredman: and how would you access the metadata of 'foo later? |
| 15:32 | hiredman | keep 'foo around |
| 15:32 | hiredman | (def a 'foo) |
| 15:33 | hiredman | (let [a 'foo]) |
| 15:33 | hiredman | etc |
| 15:34 | hiredman | if that doesn't work for your, then your data isn't a good fit for metadata |
| 15:34 | ska23421 | hiredman: actually I don't need that functionality. Just trying to grok metadata attached to symbols |
| 15:36 | hiredman | symbols are not interned, so a 'foo somewhere and a 'foo somewhere else in code don't yield the same object |
| 15:37 | ska23421 | hiredman: OK. What happens to the metadata of (def #^{:context "Symbol"} my-symbol "What ever value") |
| 15:37 | ska23421 | Is only copied once from the symbol 'my-symbol to the Var with that name or is it still hanging around and accessible somehow? |
| 15:38 | hiredman | it is only copied if you use def |
| 15:38 | MikeDev | how to comment a line? |
| 15:38 | MikeDev | / |
| 15:39 | MikeDev | /// |
| 15:39 | hiredman | ; |
| 15:39 | the-kenny | ; |
| 15:39 | MikeDev | k |
| 15:39 | hiredman | ,;comment |
| 15:39 | clojurebot | EOF while reading |
| 15:39 | ska23421 | hiredman: consider (def #^{:c "sym"} mysym #^{:c "val"} [1 2 3]) |
| 15:40 | ska23421 | {:c "sym"} is nowhere to be found later, or? |
| 15:40 | hiredman | you don't retain a reference to mysym, so the object is lost a long with it's metadata |
| 15:40 | hiredman | but def copies the metadata to the var named by mysym |
| 15:41 | ska23421 | hiredman: ^mysym --> {:c "val"}. No copy here. |
| 15:41 | hiredman | that is not the var |
| 15:41 | hiredman | #'mysym is the var |
| 15:42 | hiredman | mysym is resolved to the three element vector |
| 15:42 | hiredman | which has the metadat {:c "val"} |
| 15:42 | hiredman | ,+ |
| 15:42 | clojurebot | #<core$_PLUS___4745 clojure.core$_PLUS___4745@120c359> |
| 15:42 | hiredman | vs. |
| 15:42 | hiredman | ,#'+ |
| 15:42 | clojurebot | #'clojure.core/+ |
| 15:42 | ska23421 | hiredman: hang on, need some REPLing :-) |
| 15:43 | hiredman | ,(meta +) |
| 15:43 | clojurebot | nil |
| 15:43 | hiredman | ,(meta #'+) |
| 15:43 | hiredman | clojurebot: are you kidding me? |
| 15:44 | clojurebot | {:ns #<Namespace clojure.core>, :name +, :file "clojure/core.clj", :line 654, :arglists ([] [x] [x y] [x y & more]), :inline-arities #{2}, :inline #<core$fn__4742 clojure.core$fn__4742@552a98>, :doc "Returns the sum of nums. (+) returns 0."} |
| 15:44 | clojurebot | You will not become skynet |
| 15:44 | the-kenny | clojurebot: No, clojurebot will become skynet |
| 15:44 | clojurebot | clojurebot will become skynet |
| 15:45 | the-kenny | :) |
| 15:48 | interferon | is there a function that checks to see i a sequence contains an object, e.g. (contains [1 2 3] 2) => true |
| 15:48 | hiredman | ,(.contains [1 2 3] 2) |
| 15:48 | clojurebot | true |
| 15:49 | hiredman | ,(some #{2} [1 2 3]) |
| 15:49 | clojurebot | 2 |
| 15:49 | interferon | doesn't work on sets |
| 15:49 | interferon | ah some is better |
| 15:49 | hiredman | uh |
| 15:49 | hiredman | are you sure? |
| 15:49 | chouser | (#{:a :b :c} :b) |
| 15:49 | hiredman | ,(.contains #{1 2} 2) |
| 15:49 | clojurebot | true |
| 15:49 | chouser | ,(#{:a :b :c} :b) |
| 15:49 | clojurebot | :b |
| 15:50 | interferon | :) |
| 15:50 | hiredman | clojure's collections are all java Collections and .contains is a java Collection method |
| 15:51 | ska23421 | wow, this almost answers my questions concerning contains? for lists in the group. Good day today: to long standing questions seem to go away. Thanks |
| 15:52 | ska23421 | (I still think contains? should do something on lists other than returning false all the time) |
| 15:53 | hiredman | lists don't have keys, so a list won't have the key you are looking for |
| 15:53 | slyrus_ | liebke: is it your intent that folks using incanter should be using the bundled clojure and clojure-contrib? |
| 15:53 | interferon | i find the use of sets as functions a little confusing, so it's good to know that contains? is a function |
| 15:54 | ska23421 | hiredman: contains? even works on strings and arrays |
| 15:54 | ska23421 | ,(contains? [1 2 3] 3) |
| 15:55 | clojurebot | false |
| 15:55 | ska23421 | It is a confusing function, isn't it? |
| 15:57 | the-kenny | It is |
| 15:57 | interferon | ,(contains? '(1 2) 1) |
| 15:57 | clojurebot | false |
| 15:58 | the-kenny | ,(doc contains?) |
| 15:58 | clojurebot | "([coll key]); Returns true if key is present in the given collection, otherwise returns false. Note that for numerically indexed collections like vectors and Java arrays, this tests if the numeric key is within the range of indexes. 'contains?' operates constant or logarithmic time; it will not perform a linear search for a value. See also 'some'." |
| 15:58 | interferon | that is an offensive function |
| 15:58 | ska23421 | interferon: it will *always* return false if fed a list |
| 15:59 | ska23421 | ,(contains? "hello" \e) |
| 15:59 | clojurebot | false |
| 15:59 | ska23421 | ,(contains? "hello" 2) |
| 15:59 | clojurebot | true |
| 16:00 | ska23421 | OK, in line with docs. Confusing nevertheless. And just nothing implemented for lists. |
| 16:01 | hiredman | the majority of your "lists" are lazy sequences regardless |
| 16:01 | hiredman | which means there would have to be a non-lazy linear time search |
| 16:02 | MikeDev | http://pastie.org/private/5shvcyia8dnzowg7qwldw |
| 16:02 | MikeDev | I have no idea what that error even is |
| 16:03 | hiredman | and your code is unreadble |
| 16:03 | hiredman | ~style |
| 16:03 | clojurebot | style is http://paste.lisp.org/display/81021 |
| 16:03 | danlarkin | oh god |
| 16:03 | ska23421 | hiredman: I agree that a linear non-lazy search would be neccessary if really searching for an element == the key. The index-bases lookup would be O(1) for lists, so at least that would be possible. |
| 16:03 | danlarkin | hurts my eyeballs! |
| 16:04 | hiredman | MikeDev: and you didn't paste the exception (as far as I can tell) so no one can help you |
| 16:04 | MikeDev | http://pastie.org/private/gpd3vq1xhl8de9holniagw |
| 16:04 | MikeDev | oh sorry |
| 16:04 | hiredman | and camelcase has got to go |
| 16:05 | arohner | any clojuresql people online? |
| 16:05 | hiredman | foo-bar vs fooBar |
| 16:05 | arohner | the clojureql wiki link is broken |
| 16:06 | MikeDev | I dont use camelcase |
| 16:06 | MikeDev | so np |
| 16:07 | Chousuke | What's that HeadingResultsToTable called then? :/ |
| 16:07 | Chousuke | should be heading-results-to-table |
| 16:07 | hiredman | or heading-results->table |
| 16:08 | MikeDev | http://pastie.org/private/dyr2o1fg0ncjvklbacvaxw |
| 16:08 | MikeDev | Try that |
| 16:08 | MikeDev | It's got the exception and code |
| 16:08 | Chousuke | also you should learn out of the habit of putting the closing parens on their own lines. |
| 16:08 | Chousuke | no-one does that. |
| 16:08 | MikeDev | It's not camelcase |
| 16:08 | MikeDev | and no thanks |
| 16:08 | Chousuke | so your code will just look different from everyone else's |
| 16:09 | MikeDev | camelCase |
| 16:09 | MikeDev | MyCase |
| 16:09 | danlarkin | aaaaand gross |
| 16:09 | Chousuke | YourCase is just as bad :P |
| 16:09 | hiredman | so you don't want other people to be able to read your code and help you? |
| 16:09 | MikeDev | no, camelCase doesnt scale |
| 16:09 | hiredman | … |
| 16:09 | danlarkin | troll alert! |
| 16:09 | MikeDev | I can use all_lower, FirstLetter, and ALL_CAPS |
| 16:10 | hiredman | all-lower |
| 16:10 | Chousuke | Clojure has a few exceptions to the foo-bar style though |
| 16:10 | Chousuke | namely, most java stuff |
| 16:10 | Chousuke | but it seems it's also okay to name protocols as FooProtocol |
| 16:11 | ska2342 | MikeDev: you probably use the case to denote something? Scope, type? |
| 16:11 | MikeDev | well, in object oriented langs, yes |
| 16:11 | hiredman | ~def slurp* |
| 16:11 | ska2342 | MikeDev: which Clojure is not |
| 16:11 | Chousuke | anyway, you won't see that style used in anything but newbie code. |
| 16:11 | Chousuke | so you shouldn't use it either :) |
| 16:12 | MikeDev | But I always use FirstLetter with functions |
| 16:13 | hiredman | MikeDev: you are passing slurp* nil |
| 16:13 | cark | are you not able to adapt to language conventions ? |
| 16:13 | cark | when in rome act as a roman |
| 16:13 | MikeDev | I may have to to get paid |
| 16:13 | Chousuke | MikeDev: You'll learn out of that habit if you keep using clojure though. |
| 16:13 | MikeDev | hiredman, thx |
| 16:13 | MikeDev | o i c |
| 16:13 | hiredman | MikeDev: in the future, if you need help, please consider the poor brain of the person who has to read your code |
| 16:13 | MikeDev | yeah I gotta catch that |
| 16:14 | Chousuke | MikeDev: you also indent way too much. Two spaces is just fine for lisp |
| 16:14 | hiredman | instead of being a jerk and saying "this is how I write it!" |
| 16:15 | Chousuke | lisp code tends to nest quite a lot so if you use excessive indentation it's going to look awful |
| 16:15 | MikeDev | well i use tab. cant u change it to be = to 2 spaces? |
| 16:15 | patrkris | MikeDev: and you don't have to worry about having a lot of end-parens on one line if you have a decent editor |
| 16:16 | technomancy | well you could make everyone who reads your code change their tab stops, or you could just do it right in the first place. |
| 16:16 | hiredman | rainbow parens! |
| 16:16 | Chousuke | MikeDev: 2 spaces is pretty much universal accross all lisp dialects. |
| 16:16 | Chousuke | MikeDev: it's not like with C or Java where everyone has their own indentation preference. |
| 16:16 | Chousuke | across* |
| 16:17 | ska2342 | I never indent my code. Emacs does :-) C-M-q |
| 16:32 | mee | any vim users? how do you automatically format your code? is there a standalone code formatter like perltidy for clojure? |
| 16:33 | hiredman | that is an excellent qquestion to which I have no answer |
| 16:33 | mee | searching turned up this, which is hilarious (read the contents of the Command(s)) http://www.flickr.com/photos/manjilab/4097992719/ |
| 16:34 | hiredman | … |
| 16:35 | Chousuke | :P |
| 16:48 | LauJensen | Evening gents. I'm trying to call a C lib via clojure-jna and documentation is a little scarce. I believe the function takes an argument of the by BSTR and returns a Long. How do I call passing a BSTR? |
| 16:53 | technomancy | mee: hah; nice |
| 16:57 | MikeDev | is there a good example of exception catching? |
| 16:59 | the-kenny | MikeDev: It's pretty straightforward if you know the syntax: http://clojure.org/special_forms#toc12 |
| 17:02 | MikeDev | (catch classname name expr*) |
| 17:03 | the-kenny | Inside a (try), yes. |
| 17:03 | MikeDev | what are classname and name |
| 17:05 | Chousuke | MikeDev: NullPointerException somename |
| 17:05 | Chousuke | the name is arbitrary. it's used to refer to the exception itself |
| 17:06 | the-kenny | lisppaste8: url |
| 17:06 | lisppaste8 | To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste. |
| 17:06 | MikeDev | how did you get NullPointerException? |
| 17:06 | lisppaste8 | the-kenny pasted "try-catch-example" at http://paste.lisp.org/display/91665 |
| 17:06 | the-kenny | (Bad indent, but there's an example) |
| 17:07 | the-kenny | (the whole thing is sent to an agent, so [] is there to set the new state of the agent) |
| 17:08 | prhlava | Are questions about 1.1-alpha considered here or I should wait for the release? |
| 17:09 | MikeDev | if they consider my questions, they'll probably consider yours |
| 17:09 | the-kenny | prhlava: Just ask ;) |
| 17:09 | prhlava | :-) OK |
| 17:09 | prhlava | I have a simple "skeleton" application which uses http://www.gridgain.com/ - free cloud platform - Clojure 1.0 works, 1.1 - does not - class not found. No other change, but switched clojure version |
| 17:10 | prhlava | all points to clojure.lang.RT |
| 17:10 | prhlava | (the gridgain uses remote class loader and the app fails only when more than 1 node is started) |
| 17:12 | michaeljaaka | why the contrib APi was taken from clojure.org? |
| 17:12 | michaeljaaka | it was very usefull |
| 17:12 | michaeljaaka | now again it is hard to find the doc |
| 17:13 | michaeljaaka | and link under API was replaced from old clojure.org/api |
| 17:17 | prhlava | The application works with clojure 1.0 on multiple nodes - no problem. With clojure 1.1 - the remote node fails to load a clojure class: "core_init". |
| 17:19 | prhlava | (back in 5 minutes) |
| 17:20 | MikeDev | thx all. im tired |
| 17:26 | prhlava | hmm, otoh, it is quite possible that gridgain class loader does something not quit right :-( |
| 17:26 | prhlava | what is the main function of clojure.lang.RT? |
| 17:31 | technomancy | clojure.lang.RT does basically everything |
| 17:31 | technomancy | RT stands for Runtime |
| 17:32 | prhlava | technomancy: :-) |
| 17:33 | Chousuke | prhlava: it implements core functions in Java for performance/bootstrapping reasons as far as I can tell. |
| 17:34 | prhlava | I am just looking at the RT, it is failing at: at clojure.lang.RT.doInit(RT.java:406), that line does load("clojure/core"). |
| 17:35 | Chousuke | prhlava: is the code AOT-compiled? |
| 17:35 | Chousuke | prhlava: if it's AOT-compiled for 1.0, it probably won't work with 1.1 |
| 17:37 | prhlava | Chousuke: yes, it is AOT compiled (and I did AOT re-compile with 1.1) |
| 17:37 | prhlava | (before running with 1.1) |
| 17:37 | Chousuke | hmm :/ |
| 17:42 | leafw | anybody knows of a java-only persistent list with structural sharing? |
| 17:42 | leafw | being stuck in java world with a clojure view can get hard |
| 17:44 | arohner | leafw: clojure.lang.PersistentList? |
| 17:45 | arohner | or do you mean without loading clojure.jar? |
| 17:45 | leafw | arohner: I'd use it, but I suspect it may disappear in future clojure releases |
| 17:45 | arohner | why is that? |
| 17:45 | leafw | and it depends on a lot of cthe clojure.jar |
| 17:45 | leafw | arohner: clojure-in-clojure project. |
| 17:45 | Chousuke | leafw: type everything as IPersistentCollection then |
| 17:45 | Chousuke | or whatever interface there is |
| 17:46 | Chousuke | those most likely will stay |
| 17:46 | arohner | right. the implementation might change, but I'd be very surprised if rhickey dropped java interop with a persistent list |
| 17:46 | leafw | Chousuke: ok, so then I should just copy the whole class and freeze it in time |
| 17:46 | leafw | and use the clojure.jar for the interfaces only |
| 17:47 | arohner | why do you need to copy it? |
| 17:47 | leafw | is that a horrible idea? I kind of think that it is. I wish for a proper package like java.util.concurrent.* but for persistent collections |
| 17:48 | arohner | clojure's list implements j.u.list and j.u.collection |
| 17:48 | LauJensen | Evening gents. I'm trying to call a C lib via clojure-jna and documentation is a little scarce. I believe the function takes an argument of the by BSTR and returns a Long. How do I call passing a BSTR? |
| 17:48 | arohner | run (ancestors (class (list 1 2))) |
| 17:49 | leafw | arohner: I know, I know |
| 17:49 | arohner | LauJensen: what is BSTR? byte string? |
| 17:50 | LauJensen | I don't know, I've never come across it in Java |
| 17:50 | arohner | LauJensen: http://markmail.org/message/ypuginjtwdvqc6do#query:java%20JNA%20bstr+page:1+mid:mpoiqq36yxdnbgy2+state:results |
| 17:51 | LauJensen | arohner, that looks like the stuff, thanks a lot |
| 17:51 | LauJensen | 'night all |
| 17:52 | leafw | by the way the IPersistentList .containsAll(Collection col) function is ... weird: returns col.isEmpty() |
| 18:01 | prhlava | Thank you all, and good night... |
| 18:06 | arohner | lisppaste8: url |
| 18:06 | lisppaste8 | To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste. |
| 18:07 | lisppaste8 | arohner pasted "untitled" at http://paste.lisp.org/display/91668 |
| 18:07 | arohner | any ideas why that's blowing up? |
| 18:09 | arohner | oh right, the arities are different |
| 18:10 | arohner | that's a little confusing |
| 18:10 | clojurebot | a is t |
| 18:10 | ataggart | just started playing with protocols about 15 mins ago |
| 18:11 | Chousuke | hm |
| 18:12 | arohner | it'd be nice if there was a convention or something for that |
| 18:12 | arohner | like _ |
| 18:13 | Chousuke | there was a lot of discussion about whether there should be an explicit "this" |
| 18:15 | arohner | I just want the arity on the protocol and deftype to match |
| 18:15 | ataggart | ah just firgured out what you're talking about |
| 18:15 | ataggart | yeah that's a bit weird |
| 18:16 | ataggart | perhaps it could be solved with a better warning? |
| 18:17 | Chousuke | I think things ended up so that 'this' is explicit, but can be left out, in which case you have no way to refer to it. |
| 18:23 | ataggart | ok, I'm confused. What was the arity problem above? |
| 18:25 | arohner | if you define a protocol method with an arity of (method [dispatch-type foo bar]), then when making a deftype implement the protocol, the arity must be (method [foo bar]) |
| 18:25 | arohner | s/arity/signature/ |
| 18:27 | arohner | is there a clean, generic way to update a nested map and then return the root of the tree? |
| 18:27 | ataggart | update-in |
| 18:28 | arohner | yeah, but my leaf node is a set rather than a map |
| 18:28 | ataggart | just have the fn return a modified set |
| 18:29 | arohner | nm, I was reading it wrong |
| 18:29 | arohner | that might do what I want |
| 18:29 | _ato | (update-in {...} [:foo :bar] conj thing-to-add-to-set) |
| 18:29 | arohner | perfect. thanks |
| 18:29 | ataggart | ah and I see my confusion with defprotocol. I thought the symbol for the instance was specified in the deftype implementation. |
| 18:30 | ataggart | seems weird to only have it specified in the defprotocol. |
| 18:30 | Chousuke | it can be specified in deftype as well |
| 18:30 | Chousuke | or hm |
| 18:31 | ataggart | does that mean if I have a deftype that reifies multiple protocols, there could be multiple symbols referencing the instance object? |
| 18:31 | Chousuke | I'm not sure how the new syntax works, anymore :P |
| 18:32 | Chousuke | ah, right. (deftype Foo [a b c] :as thisname (blah [] ...)) |
| 18:32 | arohner | and using :as doesn't change the method signatures, right? |
| 18:33 | Chousuke | correct |
| 18:35 | ataggart | so then why did that code not work? both the arglists have the same arity |
| 18:36 | ataggart | clearly I'm not grokking this yet |
| 18:36 | arohner | why did my pasted code not work? |
| 18:36 | ataggart | ya |
| 18:36 | arohner | because my deftype implementation needed one fewer argument |
| 18:37 | ataggart | yeah, I'm just trying to figure out why that's the case. All of the examples on the wiki use the same number of args |
| 18:38 | Chousuke | same hm? |
| 18:38 | ataggart | (defprotocol P |
| 18:38 | ataggart | (foo [x]) |
| 18:38 | ataggart | (bar-me ([x] [x y]))) |
| 18:38 | ataggart | (deftype Foo [a b c] [P] |
| 18:38 | ataggart | (foo [x] a) |
| 18:38 | ataggart | (bar-me [x] b) |
| 18:38 | ataggart | (bar-me [x y] (+ c y))) |
| 18:38 | Chousuke | that's not right. |
| 18:38 | Chousuke | that's out of date |
| 18:38 | ataggart | http://www.assembla.com/wiki/show/clojure/Protocols |
| 18:38 | arohner | that example is out of date. Try that in the repl |
| 18:38 | ataggart | ahh k |
| 18:39 | Chousuke | look at the datatype lpage. |
| 18:40 | ataggart | time for (doc defprototype) |
| 18:41 | ataggart | erm defprotocol |
| 18:47 | the-kenny | technomancy: Is there a nice way to use defprotocol etc. with leiningen? |
| 18:48 | ataggart | I'm sure Rich has a good reason for it, but that defprotocol and a called method have a different number of args from the deftype impl is odd. |
| 18:48 | ataggart | e.g., http://paste.lisp.org/display/91669 |
| 18:48 | technomancy | the-kenny: sure; just use the clojure version number from the "new" branch |
| 18:49 | technomancy | I haven't done it myself, but that branch is being built regularly on build.clojure.org, so there shouldn't be any tricks necessary |
| 18:51 | the-kenny | technomancy: hm.. what's the version number? |
| 18:51 | the-kenny | Or: Where can I find it? |
| 18:54 | _ato | doesn't look like it's actually being put in the snapshots directory though: http://build.clojure.org/snapshots/org/clojure/clojure/ |
| 18:57 | the-kenny | _ato: hm :( |
| 19:00 | the-kenny | Any idea why not? |
| 19:02 | ataggart | the project is configured to run ant jar |
| 19:03 | ataggart | instead of ant nightly-build |
| 19:03 | ataggart | hence no uploading |
| 19:03 | ataggart | compare http://build.clojure.org/job/clojure/40/console with http://build.clojure.org/job/clojure%20%28new%29/35/console |
| 19:07 | the-kenny | hm |
| 19:20 | ataggart | it's a simple config change, just need rights to do so. |
| 19:22 | konr1 | I'm moving from vi to emacs - is there a slime tutorial you guys recommend me watching/reading? |
| 19:23 | konr1 | And are CL-focused slime tutorials applicable to Clojure? |
| 19:24 | the-kenny | konr1: Yes, they are |
| 19:24 | the-kenny | konr1: Slime isn't very complicated |
| 19:26 | j3ff86 | is there a limit to how big a sequence can be in clojure? |
| 19:26 | the-kenny | j3ff86: the java heap-space ;) |
| 19:26 | j3ff86 | ah |
| 19:26 | the-kenny | I don't think there's another limit |
| 19:27 | the-kenny | But if you're working with long sequences, you maybe want a lazy-sequence |
| 19:27 | j3ff86 | good point |
| 20:07 | technomancy | konr1: the slime manual is pretty thorough |
| 20:07 | technomancy | a few features haven't been ported to clojure yet, but most of it is solid |
| 20:27 | mtm_ | technomancy: just ran 'lein self-install' on a fresh Snow Leopard box, it installed fine. When I try 'lein help new' or lein new foo' I get an trace that says "Exception in thread "main" java.io.FileNotFoundException: project.clj (No such file or directory)" |
| 20:27 | mtm_ | any ideas? |
| 20:28 | Chousuke | try creating an empty project.clj? |
| 20:29 | mtm_ | hmm, that blowed up real good with "Exception in thread "main" java.io.FileNotFoundException: Could not locate leiningen/new__init.class or leiningen/new.clj on classpath:" |
| 20:29 | mtm_ | maybe a buggy lein script? |
| 20:29 | mtm_ | I'll dig further |
| 20:30 | _ato | mtm_: "lein new" doesn't exist in 0.5.0. It's coming in 1.0.0 |
| 20:30 | mtm_ | ah, I was going from the readme |
| 20:30 | mtm_ | silly me :) |
| 20:31 | ataggart | what's the "right" way to organize tests if we want to get lein to run them (which I assume it can, haven't delved too deeply yet) |
| 20:31 | toups | Hi #clojure. I notice there is a kind of impedane mismatch between the way swank-clojure-project expects things to be set up and my desire to maintain some general libraries which I use in many differeny projects. Is there a community standard way of handling this? |
| 20:33 | somnium | toups: put symlinks in ./lib ? |
| 20:33 | _ato | technomancy: what do you think of setting the default github branch to stable for Leiningen (github project -> admin -> default branch)? That way the main page will show the README from the stable branch. I think mtm_ is the third person I've seen run into problems due to the README not matching what self-install installs. |
| 20:33 | toups | somnium: simple as they, eh? |
| 20:33 | toups | that, I mean |
| 20:33 | somnium | toups: it works for me |
| 20:34 | toups | I just like to check to see if everyone is doing the same thing before I reinvent the wheel |
| 20:34 | _ato | ataggart: just put a bunch of .clj files in project/test/ that use clojure.test and define some tests with (deftest) |
| 20:34 | _ato | ataggart: you can see how I do it here: http://github.com/ato/clojars-web/blob/master/test/clojars/test/utils.clj |
| 20:34 | ataggart | so you split them out from the code being tested? |
| 20:35 | ataggart | hmm, looks like it could work either way |
| 20:35 | _ato | yeah. well Leiningen's just going to go through every namespace under project/test, load it and eval (run-tests) in it |
| 20:36 | _ato | so you could just symlink your sources in there if you mix deftests into your implementation files |
| 20:36 | _ato | I assume that would work |
| 20:38 | ataggart | cool |
| 20:43 | mtm_ | _ato: all is well now; I've got the latest leiningen built and working. thanks for the help |
| 20:44 | _ato | :-) |
| 20:50 | tolstoy | Is there a way to get the name of the namespace your functions running in? |
| 20:53 | _ato | ,*ns* |
| 20:53 | clojurebot | #<Namespace sandbox> |
| 20:53 | tolstoy | Ah, cool. Still trying to learn how to learn where things like *ns* are documented. |
| 20:54 | konr1 | Has anyone any idea on how clojure-swank handles the classpath? I just installed the whole thing on emacs using ELPA, and after starting slime with "m-x slime", swank complains that it couldn't find test.clj on the classpath |
| 20:56 | _ato | ,(name (ns-name *ns*)) |
| 20:56 | clojurebot | "sandbox" |
| 20:56 | _ato | tolstoy: ^ you might need that if you want it as a string |
| 20:57 | tolstoy | _ato: Thanks. Mostly just for println/debugging or whatever. |
| 21:00 | hjiang | It seems I need to add ~/.m2/repository to CLASSPATH in my shell config. Is that the correct way? I didn't see it in the installation notes. |
| 21:01 | hjiang | sorry, the question was for Leiningen |
| 21:02 | _ato | hjiang: you shouldn't need to, the bin/lein script should set the classpath for you. |
| 21:02 | _ato | hjiang: is it not working? |
| 21:03 | hjiang | _ato: lein new testp |
| 21:03 | hjiang | Exception in thread "main" java.io.FileNotFoundException: Could not locate leiningen/new__init.class or leiningen/new.clj on classpath: |
| 21:03 | hjiang | _ato: yeah, seems the path isn't setup properly. |
| 21:04 | _ato | hjiang: I think you're having exactly the same problem mtm_ just had. "lein new" doesn't exist in lein 0.5.0 |
| 21:05 | hjiang | oh, I see. I'll try the latest then. Thanks! |
| 21:06 | tolstoy | Hm. *ns* seems bound to clojure.core when I run my app. Interesting. |
| 21:07 | chouser | tolstoy: would you bring that up on the google group |
| 21:07 | chouser | tolstoy: I don't think it's intentional, and we might be able to fix it before 1.1 |
| 21:07 | tolstoy | Ah, really? Hm Okay. |
| 21:13 | tolstoy | I think *ns* is bound to the name space of the initial function being called, and even if you call functions in other names spaces, which print out *ns*, you get the original value. |
| 21:13 | tolstoy | I'm not sure that's wrong. |
| 21:15 | tolstoy | All I'm really looking for is something like class.getName(). Something analogous to that. |
| 21:15 | _ato | tolstoy: ah yeah, that's current. If you want the namespace that function is defined in you might need to do it with a macro |
| 21:16 | tolstoy | Okay. It's not that big of a deal, fortunately. ;) |
| 21:16 | _ato | this might work: (defmacro current-ns [] *ns*) |
| 21:18 | _ato | so then you can do something like (println "I'm in" (current-ns)) |
| 21:18 | tolstoy | _ato: Yeah, that's closer. |
| 21:18 | _ato | because its a macro *ns* is evaluated at compile-time so *ns* should be set to whatever file the macro is being expanded in |
| 21:19 | tolstoy | Yes, exactly. |
| 21:21 | technomancy | _ato: I think it should be less of a problem post-1.0 since our main launch stuff won't be changing much |
| 21:22 | _ato | technomancy: good, and I noticed you've put in a task not found error, which is less befuddling than the stacktrace 0.5.0 throws up |
| 21:38 | mee | what's the difference between (advantages of?) (> foo 0) and (pos? 0). Just sugar? |
| 21:38 | mee | err (pos? foo) |
| 21:39 | Chousuke | I guess pos? is a bit faster |
| 21:39 | mee | oh, return values are different |
| 21:40 | mee | it's very cool that the documentation links to the implementation, even if I can't read it all very well |
| 21:41 | Chousuke | heh |
| 21:41 | Chousuke | that's a recent improvement. |
| 22:04 | technomancy | is there some trick to calling clojure.main/repl and getting standard in hooked up correctly? |
| 22:04 | technomancy | java -cp clojure-1.1.0-alpha-SNAPSHOT.jar clojure.main -e "(clojure.main/repl)" # <= does not cut it |
| 22:05 | JAS415 | hmm |
| 22:05 | JAS415 | what are you trying to do? |
| 22:06 | mee | java -cp .../clojure.jar clojure.lang.Repl "$@" ? |
| 22:06 | mee | is the command in clojure-repl, which seems to work |
| 22:06 | JAS415 | yeah mine has jline.ConsoleRunner in there too |
| 22:06 | technomancy | yep, I'm just wondering if there's a way to call it from inside clojure.main -e |
| 22:07 | JAS415 | i would guess that you would have to connect it to the tty or whatever |
| 22:09 | JAS415 | maybe try /legacy_repl |
| 22:12 | JAS415 | hmm |
| 22:12 | JAS415 | nope |
| 22:14 | JAS415 | hmm |
| 22:14 | JAS415 | it looks like that command prints one repl |
| 22:14 | JAS415 | neat |
| 22:23 | JAS415 | ah |
| 22:24 | JAS415 | technomancy: got a little closer with this... java -cp clojure.jar clojure.main -e "(clojure.lang.Repl/main (make-array String 0))" |
| 22:24 | JAS415 | still not quite |
| 22:30 | JAS415 | hmm |
| 22:30 | JAS415 | looks like the stuff you need to do it isn't externalized |
| 22:30 | ataggart | use clojure.lang.Script if you want to pass it a clj file |
| 22:31 | ataggart | as for eval'ing a string from the commandline, I don't know |
| 22:31 | JAS415 | i think he's trying to start a repl by evaling the string |
| 22:31 | ataggart | why? |
| 22:32 | ataggart | what's wrong with: java -cp clojure.jar clojure.lang.Repl |
| 22:32 | ataggart | (besides missing the convenience jars) |
| 22:33 | JAS415 | i have no idea :-P |
| 22:33 | ataggart | k |
| 22:33 | JAS415 | you can also do java -cp clojure.jar clojure.main |
| 22:34 | ataggart | my clj script still works thankfully. no-args and it starts the repl, otherwise it runs a file, etc. |
| 22:34 | JAS415 | i'm just intrigued now as to why it doesn't loop when you try to call main directly |
| 22:40 | ataggart | anyone know of a simple way to return a modified version of a deftype'd instance, akin to how assoc would work on structs? |
| 22:51 | somnium | ataggart: you can use conj if you include IPersistentMap in interfaces |
| 22:51 | somnium | ataggart: otherwise seems necessary to implement Associative atm |
| 22:51 | ataggart | aha! |
| 22:52 | ataggart | I had read that part of the wiki, but it didn't sink in |
| 22:56 | technomancy | ataggart: I'm wanting to start the repl from within a "java" ant task so I can set the classpath in Clojure |
| 22:56 | technomancy | since ant sets up a subclassloader for you |
| 22:57 | ataggart | gotcha |
| 22:59 | JAS415 | woahh |
| 23:00 | JAS415 | hm |
| 23:01 | JAS415 | so you want to start the ant task in java, run the repl in the middle, and finish the ant task? |
| 23:03 | JAS415 | could you start the repl in the beginning and call ant from clojure in like another thread and then call back to the prompt? |
| 23:03 | JAS415 | (I clearly don't know how ant works) |
| 23:05 | technomancy | no, the repl needs to be loaded from the subclassloader so it will have the calculated classpath |
| 23:06 | JAS415 | darn |
| 23:06 | ataggart | why not stick the calculated classpath into the java task itself? |
| 23:09 | ataggart | ah, unless you're using clojure to calculate it |
| 23:09 | technomancy | yeah, that's right |
| 23:10 | JAS415 | haha |
| 23:10 | JAS415 | could you use sys.exec to run clojure |
| 23:13 | technomancy | actually... it looks like it's the ant task that's screwing up *in*. bugger. |
| 23:55 | ngoc | Hi, is it possible to use more than 1 infinite seq like this? |
| 23:55 | ngoc | (def l100 |
| 23:55 | ngoc | (for [a (iterate inc 1) |
| 23:55 | ngoc | b (iterate inc 1) |
| 23:55 | ngoc | :when (= (+ a b) 100)] |
| 23:55 | ngoc | [a b])) |
| 23:55 | ngoc | (take 2 l100) |
| 23:55 | technomancy | ngoc: map accepts mutiple seqs in parallel |
| 23:56 | technomancy | if you use for it treats one of them as an "inner seq" or some such |
| 23:57 | ngoc | Can you show me how to fix the code using map? |
| 23:58 | tomoj | b |
| 23:58 | tomoj | oops.\ |
| 23:58 | technomancy | ngoc: something like this: (map (fn [a b] [...]) (iterate inc 1) (iterate inc 1)) |