2010-07-26
| 00:35 | brehaut | presumably there is a library in clojure or contrib to make walking directories and files easy? |
| 00:35 | brehaut | (i also presume im not smart enough to have found it yet) |
| 00:37 | brehaut | ignore me, file-seq appears to be it |
| 00:39 | technomancy | file-seq is sweet |
| 00:40 | technomancy | daaku: things get added to Clojure, but there has only been one purposeful instance of breakage so far since 1.0 |
| 01:02 | brehaut | does the #(... %) macro have any way to type hint the % outside of converting to an (fn ..) form ? |
| 01:14 | Bahman | Hi all! |
| 01:56 | vu3rdd | technomancy: ping |
| 01:57 | vu3rdd | technomancy: I am facing some problem with the lein if I compile the lein uberjar myself. |
| 01:58 | vu3rdd | any help to fix it will be great! I sent the error to the list a couple of days ago |
| 01:58 | daaku | technomancy: cool. that makes me hopeful :) |
| 02:00 | daaku | i just noticed i wrote this, and seemed like a common thing i write (the 3x get part): (nil? (get (get (get req :cookies) "fbc") :value)) -- is there a better way to write this? (things in the middle may be nil) |
| 02:02 | hiredman | (-> reg :cookies (get "fbc") :value nil?) |
| 02:02 | slyrus | vu3rdd: did you update lein recently? ISTR some uberjar bustage being fixed recently |
| 02:02 | daaku | hiredman: cool, thanks |
| 02:03 | OliverUv | (nil? (reduce #'get (req :cookies "fbc" :value))) |
| 02:03 | hiredman | OliverUv: this isn't common lisp |
| 02:04 | OliverUv | then implement reduce |
| 02:04 | hiredman | if you want to use a function in reduce you just use it |
| 02:04 | OliverUv | it is fairly straight forward |
| 02:04 | hiredman | (reduce get … |
| 02:04 | OliverUv | ah |
| 02:04 | hiredman | your list there at the end will be evaluated as a function call |
| 02:04 | OliverUv | oh yeah I just remembered, ? for scheme, p for cl |
| 02:05 | OliverUv | you are right about that too |
| 02:05 | hiredman | ,(macroexpand-1 '(-> reg :cookies (get "fbc") :value nil?)) |
| 02:05 | clojurebot | (clojure.core/-> (clojure.core/-> reg :cookies) (get "fbc") :value nil?) |
| 02:05 | OliverUv | oh damn, I was in #clojure, I thought I was in #lisp |
| 02:05 | OliverUv | sorry |
| 02:06 | hiredman | ,(macroexpand-1 '(clojure.core/-> (clojure.core/-> reg :cookies) (get "fbc") :value nil?)) |
| 02:06 | clojurebot | (clojure.core/-> (clojure.core/-> (clojure.core/-> reg :cookies) (get "fbc")) :value nil?) |
| 02:10 | cobol_expert | hi, what's the syntax for defn default parameter values? |
| 02:10 | cobol_expert | if there is one |
| 02:11 | dsantiago | There isn't one. |
| 02:12 | cobol_expert | dang |
| 02:12 | dsantiago | Though you could define multiple versions of the function with different arities that behave that way. |
| 02:13 | cobol_expert | thanks, for some reason I thought defn provided that |
| 02:33 | vu3rdd | slyrus: I am using the released lein version 1.2.0 to create a uberjar of the latest lein |
| 02:34 | vu3rdd | slyrus: I created a new uberjar of lein (current git master) and tried it. Still same problem |
| 02:34 | vu3rdd | it is something to do with maven-ant-tasks |
| 02:36 | vu3rdd | Ok, problem goes away if I change java invokation in lein with -noverify option. Very wierd.. |
| 02:41 | hiredman | why are you uberjaring lein? |
| 02:56 | vu3rdd | hiredman: I am trying to build lein itself. |
| 02:57 | vu3rdd | hiredman: The main goal is to create a debian package of lein. But debian has more recent versions of ant etc. So I wanted to create a workspace where I can play with lein itself |
| 03:20 | cais2002 | hi guys, for logging, is it recommended to use clojure.contrib.logging ? |
| 03:31 | Lajla | cais2002, not sure, but I recommend that you Worship His Shadow. |
| 03:31 | Lajla | cais2002, also, if I really asked you nicely and gave you a hug, would you eat my eyeball in front of me? |
| 03:38 | raek | cais2002: I haven't used c.c.logging myself, so I don't have any good pointers except for searching the google group |
| 03:39 | raek | maybe it can get you at least one a little bit on the way |
| 03:39 | raek | http://groups.google.com/group/clojure/search?group=clojure&q=logging |
| 03:40 | cais2002 | raek: thanks, I just used it and it is pretty intuitive to use |
| 07:13 | sergey_miryanov | hi clojurians! |
| 07:14 | sergey_miryanov | what heard about status of last-var-wins? it's very annoying to restart repl for each file reload :/ |
| 07:31 | zmyrgel | any idea what is wrong as I get IllegalArgumentException when I try to run default conjure site |
| 08:14 | aldebrn | So I can't add a docstring to defmulti's? |
| 08:16 | rhudson | ? (doc defmulti) says you can |
| 08:18 | aldebrn | Aha, sorry for the dumb question. Much appreciated rhudson |
| 10:26 | sid3k | hello clojure! |
| 10:37 | chouser | hello sid3k! |
| 10:43 | Raynes | chouser: PING! |
| 10:43 | chouser | Raynes: hello |
| 10:43 | Raynes | That is the 4th time I've pinged you in 4 days. :p |
| 10:43 | Raynes | chouser: Hold on, give me a second to remember what I wanted to whine about. |
| 10:43 | chouser | heh |
| 10:45 | Raynes | chouser: Found it. In the latest MEAP, section 8.1.4, first code example. |
| 10:46 | Raynes | The example does this: (:use (clojure set xml)) |
| 10:46 | Raynes | (:use [clojure.test :only (are is)]) |
| 10:46 | Raynes | Is there a particular reason for that? |
| 10:46 | Raynes | It could be (:use (clojure set xml) [clojure.test :only (are is)]) |
| 10:50 | chouser | Raynes: right, either would be fine. The indentation is perhaps a little cleaner this way. |
| 10:51 | chouser | we'll look at it. |
| 10:51 | fogus | Raynes: That specific example has an accompanying discussion that walks down the line explaining what each directive does. The separation sort of feel out of the discussion. |
| 10:52 | chouser | fwiw, you can report future things on the forum, rather than waiting for fogus or me to show up here |
| 10:52 | Raynes | I see. Do you demonstrate the single-use style anywhere else in the book? |
| 10:52 | chouser | http://www.manning-sandbox.com/thread.jspa?threadID=38170&tstart=0 |
| 10:52 | Raynes | If not, it's probably a good idea. |
| 10:52 | Raynes | I would, but it didn't really feel like a *report* and it certainly wasn't important. |
| 10:52 | Raynes | It was really just a question about whether there was a specific reason for it. |
| 10:52 | Raynes | :) |
| 10:53 | cais2002 | Raynes: still remember we talked about a replace-key functions the other day? I just realized that there is one pre-defineed function that does that |
| 10:53 | cais2002 | -> (doc clojure.set/rename-keys) |
| 10:53 | cais2002 | ,(doc clojure.set/rename-keys) |
| 10:53 | clojurebot | "([map kmap]); Returns the map with the keys in kmap renamed to the vals in kmap" |
| 10:53 | Raynes | cais2002: Oh, good. :) |
| 10:54 | Raynes | Hrm. |
| 10:54 | cais2002 | but the second param kmap has to be a real map |
| 10:54 | Raynes | Where oh where did my sexpbot go. |
| 10:54 | cemerick | chouser: wasn't there a ticket open for moving clojure.contrib.lazy-xml/emit to clojure.xml? |
| 10:55 | fogus | Raynes: We added much more about namespaces that is not included in the latest MEAP update, so yes. Although I do not know when you will see it. :O |
| 10:55 | Raynes | Methinks Licenser's server restarted or something. |
| 10:56 | chouser | cemerick: I've suggested it, but I'm not sure I've ever heard rhickey voice any support. |
| 10:58 | Raynes | Oh, it just dropped on freenode. Odd. I really need to add reconnection support to irclj. |
| 10:59 | Raynes | -> (clojure-version) |
| 10:59 | sexpbot | => "1.2.0-beta1" |
| 10:59 | cemerick | chouser: I remember there being concerns about more hosty dependencies getting into those "core" namespaces. clojure.java.xml coming soon, perhaps. |
| 10:59 | Bahman | Hi all! |
| 11:00 | Raynes | Bahman: Hello there! |
| 11:00 | Raynes | :) |
| 11:01 | Scriptor | hey Bahman |
| 11:01 | chouser | cemerick: hm, perhaps. though the api provided by c.c.lazy-xml is fully wrapped, I think, so could be implemented on other hosts without API change. |
| 11:01 | Bahman | Hi there Raynes and Scriptor! |
| 11:05 | cemerick | fogus: which changes? Last I see are from the 16th? |
| 11:07 | fogus | cemerick: saw some ticket updates about clojure.xml/emit earlier today. |
| 11:12 | slyrus | i don't suppose I can use recur and a lazy-seq together can I? |
| 11:13 | chouser | slyrus: depends on how. :-) |
| 11:16 | slyrus | fair enough... |
| 11:17 | chouser | 'range' for example uses both lazy-seq and loop/recur |
| 11:18 | slyrus | I see I can put the lazy-seq in the args of recur. I can't figure out how to get the lazy-seq around the recur call. not sure if that's even a good idea. |
| 11:18 | slyrus | the function in question is my breadth-first-traversal routine, or the bft-recur variant anyway: http://github.com/slyrus/shortcut/blob/master/src/shortcut/graph.clj#L163 |
| 11:19 | chouser | you can't have a recur inside a lazy-seq form that jumps to something outside the lazy-seq form. |
| 11:19 | chouser | or that tries, because it won't work. :-) |
| 11:19 | slyrus | that's what I thought :) |
| 11:20 | slyrus | now I have to decide which is worse, not using recur or not returning a lazy-seq... |
| 11:27 | chouser | slyrus: if what you're trying to do makes sense, there's probably a way to arrange the code so you can use both. |
| 11:28 | slyrus | yeah, I can put the lazy-seq call in the args to recur. not sure if that makes sense though! I'm going to punt for the moment. |
| 12:13 | lozh | Put my first reasonably big chunk of clojure at http://gist.github.com/490689 would welcome any feedback on style/simplfication etc |
| 12:16 | cemerick | lozh: the in-ns is superfluous (implied by ns). Put your imports in the ns declaration (e.g. (:import (java.awt Robot ...))). |
| 12:17 | lozh | thanks |
| 12:17 | cemerick | Without getting into what you're actually doing, those are the only obvious things. :-) |
| 12:22 | Raynes | lozh: Also, you can supply a docstring to your ns rather than make all of the above comments. |
| 12:23 | lozh | Ah, I was just copying clojure .core, didn't realise that, thanks |
| 12:23 | Raynes | You don't have to. It's usually something libraries do. Just an idea. :D |
| 12:24 | Raynes | lozh: Here is an example: http://github.com/Raynes/clj-github/blob/master/src/clj_github/gists.clj |
| 12:24 | edbond | 'lein deps' delete all in lib/ dir? |
| 12:25 | lozh | Raynes: I see what you mean, thanks |
| 12:25 | edbond | where is the safe place to put org.apache jars? |
| 12:25 | Raynes | edbond: In leiningen 1.2, I'm fairly certain Leiningen does an implicit clean beforehand. |
| 12:25 | Raynes | edbond: A maven repository. |
| 12:25 | Raynes | If you're using Leiningen for dependency management, you shouldn't be using jars that aren't in a maven repository. |
| 12:25 | Raynes | It kills the whole point. |
| 12:26 | Raynes | apache stuff is in maven central. If you run into some jar that you need, and it's open source, you can upload it to clojars if it isn't already in a maven repo. |
| 12:27 | edbond | Raynes: how to search for something in maven central? |
| 12:29 | Raynes | http://mvnrepository.com/ is a maven repository search engine. |
| 12:29 | Raynes | There are others. |
| 12:30 | edbond | Raynes: thanks a lot |
| 13:22 | janne | what's the easiest way to map [1 2 3] into [{:foo 1} {:foo 2} {:foo 3}] ? |
| 13:22 | KirinDave | Probably (map #({:foo %1}) [1 2 3]) |
| 13:23 | KirinDave | ,(map #({:foo %1}) [1 2 3]) |
| 13:23 | clojurebot | java.lang.IllegalArgumentException: Wrong number of args (0) passed to: PersistentArrayMap |
| 13:23 | janne | yeah, I tried that but it doesn't work |
| 13:23 | Nikelandjelo | ,(map (fn [a] {:foo a}) [1 2 3]) |
| 13:23 | clojurebot | ({:foo 1} {:foo 2} {:foo 3}) |
| 13:23 | janne | hmh |
| 13:24 | KirinDave | Weird. |
| 13:24 | janne | what's wrong with that |
| 13:24 | janne | yeah, really weird |
| 13:25 | hiredman | ,(macroexpand-1 '#({:foo %1})) |
| 13:25 | clojurebot | (fn* [p1__499900#] ({:foo p1__499900#})) |
| 13:25 | KirinDave | Ah |
| 13:25 | KirinDave | There's the problem. :) |
| 13:25 | KirinDave | #() isn't equipped. |
| 13:30 | Nikelandjelo | ,(map #(hash-map :foo %) [1 2 3]) |
| 13:30 | clojurebot | ({:foo 1} {:foo 2} {:foo 3}) |
| 13:35 | fogus | ,(for [i [1 2 3]] {:foo i}) |
| 13:35 | clojurebot | ({:foo 1} {:foo 2} {:foo 3}) |
| 13:38 | cddr | can leiningen be used to build projects which rely on non-jvm languages? |
| 14:18 | technomancy | cddr: well, it's turing-complete, so ... |
| 14:18 | technomancy | but I don't think anyone has done much of that so far. |
| 14:50 | akhudek | hm, I was going to take advantage of laziness of map, an almost got bit by chunked sequences |
| 14:51 | akhudek | it's not clear from the documentation that map will often grab chunks, and if you want true item at a time behaviour you need to pass in something like a list |
| 14:51 | LauJensen | akhudek: ouch |
| 14:52 | LauJensen | akhudek: And yea, the documentation isnt specific enough |
| 15:30 | cemerick | akhudek: that mattered to me recently as well -- (mapcat list some-chunked-seq) will ensure one-at-a-time behaviour, in case you hadn't determined that already. |
| 15:32 | akhudek | cemerick: yep, I discovered this. I just wanted to comment that it is important to have this documented at some point so people don't accidentally get tripped up. |
| 15:43 | cemerick | akhudek: I agree, though it's a tough documentation issue -- chunking behaviour is entirely automatic, and transparent in the overwhelmingly common use case (lazy seq processing). Anyway, see http://blog.fogus.me/2010/01/22/de-chunkifying-sequences-in-clojure/ for what might come along in 1.3. |
| 15:46 | akhudek | that looks promising! |
| 15:46 | chouser | it's also possible chunked seqs might just go away |
| 15:46 | akhudek | are they causing trouble elswhere? |
| 15:47 | chouser | not that I know of, but pods may allow better performance yet for similar pipelines |
| 15:47 | akhudek | ah |
| 15:48 | chouser | I haven't heard that stated recently, so I maybe mis-remembering or things may have changed again. |
| 16:01 | cemerick | I've been under a rock. Pods are cells, right? |
| 16:02 | TakeV | Are there any Clojure libraries for hash generation, or do we just use the Java APIs for that? |
| 16:02 | cemerick | TakeV: what are you trying to get a hash for? |
| 16:04 | TakeV | cemerick: Playing around with password stuff. I know it's pretty bad form to keep the password stored, so I want to do a hash of it to compare. |
| 16:05 | cemerick | ah |
| 16:05 | chouser | cemerick: I think so, yeah. |
| 16:05 | cemerick | TakeV: MessageDigest is pretty straightforward to use. |
| 16:05 | TakeV | Is that in contrib? |
| 16:06 | cemerick | TakeV: no, it's a JRE library. java.security.MessageDigest |
| 16:06 | cemerick | s/library/class |
| 16:07 | TakeV | Ah, alright. Thanks. :) |
| 16:09 | cemerick | TakeV: Here's my (pre-protocols) hash-of multimethod. It's SHA1-only, just because that's what we use overwhelmingly. |
| 16:09 | cemerick | https://gist.github.com/83ce26f6ad06d5bda025 |
| 16:10 | cemerick | man, that's some old code :-P |
| 16:10 | TakeV | SHA1 isn't bad. Could be worse. :P |
| 16:11 | cemerick | hrm, the MiscUtilities class is mine too -- replace that with (MessageDigest/getInstance "SHA1") |
| 16:11 | TakeV | Sure. |
| 16:12 | TakeV | Man, I love github... |
| 16:12 | cemerick | TakeV: 'course, that'd be a single fn given io/input-stream. I'm probably not doing you any favors by pasting that. |
| 16:13 | TakeV | It's enough to work off of. A nice seed. |
| 16:19 | seancron | How can I start a thread that runs, while the rest of the code executes? |
| 16:19 | mefesto | (doto (Thread. f) (.start)) |
| 16:20 | mefesto | where 'f is the function you want to run in that thread |
| 16:20 | mefesto | or you can use a thread pool using Executors |
| 16:21 | seancron | How would I use a thread pool? |
| 16:21 | cemerick | seancron: Read about agents and send/send-off. Starting new threads as mefesto is almost never necessary or desirable. |
| 16:21 | cemerick | s/mefesto/mefesto suggests |
| 16:21 | mefesto | oops, yeah, agents totally slipped my mind :-\ |
| 16:22 | seancron | Okay. I'm trying to show a GUI while I make network connections. |
| 16:22 | TakeV | Yeah, I was just about to ask if threads are really needed, given the existence of agents. |
| 16:22 | cemerick | seancron: take a look at c.c.http.agent |
| 16:23 | cemerick | (if you're doing http, that is) |
| 16:23 | seancron | I'm actually doing DNS right now |
| 16:24 | cemerick | seancron: then agents are the way to go, or maybe futures (though I suspect not) |
| 16:24 | arkh | what's wrong with the following?: (apply #(str %) ["one" "two" "three"]) |
| 16:24 | arkh | I know I'm missing something basic :( |
| 16:24 | mefesto | arkh: just (apply str ["one" "two" "three"]) |
| 16:24 | opqdonut | #(str %) takes only one argument |
| 16:24 | opqdonut | and what mefesto said |
| 16:25 | arkh | using str in an anonymous function is a placeholder for what I'd really like to do. Am I passing three arguments to #(str %) with the above? |
| 16:27 | mefesto | arkh: yeah, apply will call the passed function with the collection as it's arguments |
| 16:27 | technomancy | agents are value-oriented. sometimes you need Threads that don't necessarily revolve around a single identity |
| 16:27 | arkh | mefesto: , opqdonut: ok - thank you |
| 16:28 | TakeV | technomancy: What about, say, separating game logic and drawing in a video game? Would threads be better suited for that than agents? |
| 16:30 | duncanm | any of you use the netbeans platform? |
| 16:31 | technomancy | TakeV: I think drawing is a good candidate for a background Thread as it's pretty side-effecty. "game logic" is a little too vague to make the call. |
| 16:31 | TakeV | technomancy: I see. |
| 16:31 | arohner | TakeV: though you have to be careful with drawing in a separate thread. Many GUIs are picky about only doing drawing operations in a specific thread |
| 16:33 | lozh | I've not done much game programming, but the game loops I've seen normally manually interleave the update and the drawing, makes the locking easier, and both have to be pretty well time bounded for a smooth gameplay anyway |
| 16:34 | ordnungswidrig1 | aikido |
| 16:38 | arkh | if I have a seqence of strings, what's a good way to print them out, one string per line, with spit? |
| 16:38 | mefesto | arkh: doseq ? |
| 16:39 | mefesto | (doseq [l lines] (println l)) |
| 16:39 | arkh | mefesto: oh ... I didn't think to use println. That's java's isn't it? |
| 16:40 | arkh | mefesto: sorry and nvm (and thank you). A (doc println) says otherwise |
| 16:40 | clojurebot | defmulti doc is ugly |
| 16:50 | slyrus_ | not sure if this is a bug or a feature. but if I :use clojure.contrib.seq, I can't C-c C-k my clojure file without getting the following error: error: java.lang.IllegalStateException: partition-by already refers to: #'clojure.contrib.seq/partition-by in namespace: foo |
| 16:50 | slyrus_ | clojure.contrib.graph, on the other hand, for example, is fine. must be something about the :refer-clojure :exclude in seq's ns form |
| 16:51 | chouser | partition-by is defined in c.c.seq, but was promoted to clojure.core, so now it's in both places -- hence the error. |
| 16:52 | chouser | you shouldn't really be doing :use without naming the specific vars you want anyway. |
| 16:53 | slyrus_ | hmm... the fact that it compiles fine the first time through and breaks the second time makes me suspicious that this is the intended behavior. |
| 16:54 | slyrus_ | and do you really mean I should call out every function I plan to use from an ns when I :use an ns? that seems a bit tedious. |
| 16:59 | mefesto | slyrus_: you can also 'require :as something so you don't have to name each var you need |
| 17:02 | chouser | slyrus_: I highly recommend against naked :use. Either alias the namespace with :as or call out each function with :only |
| 17:02 | chouser | of course that's just my opinion, but it would help with situations like this, as well as others. |
| 17:09 | Nikelandjelo | chouser: It's inconvenient (for me) when exploring some clojure contrib libs in repl and don't know what I need :( Is there are a way to not load function, which already exist, to escape this error? |
| 17:10 | chouser | if it's a clojure.core function, that should only be a warning and you should be able to proceed. |
| 17:11 | qbg | Nikelandjelo: There is an :exclude and :rename option for use |
| 17:15 | djpowell | hmm - I think clojure.java.shell has got messed up |
| 17:17 | Raynes | Heh. You know your language is getting popular when articles starting with single-digit numbers and assertions begin to pop up. http://twoguysarguing.wordpress.com/2010/07/26/7-rules-for-writing-clojure-programs/ |
| 17:20 | chouser | heh |
| 17:28 | slyrus_ | chouser: I assume you wouldn't apply the same recommendations to things in the same umm... project, right? do you really explicitly call out things used in foo.core by foo.baz and vice versa? or just do a :use? |
| 17:29 | chouser | slyrus_: perhaps I'm a bit pedantic, but if it's not defined in the same file, I use a namespace alias prefix or list every function in the :use :only |
| 17:29 | slyrus_ | interesting. ok, thanks. |
| 17:30 | chouser | that always makes it easy to find the definition of every word in your code, as well as keeping strict control of your own namespace. |
| 17:38 | lpetit | woops, there's no 1.2-beta1 tag on git ? |
| 17:44 | slyrus_ | chouser: ok, I think I can used to that. |
| 17:44 | lozh | Does the slime-repl in emacs have something to refer to the previous result? |
| 17:45 | qbg | You still have *1 |
| 17:46 | lozh | thanks |
| 17:49 | lozh | Heh *1 is one of those things I just can't search for on google, any idea where it's documented? |
| 17:49 | qbg | ,(doc *1) |
| 17:49 | clojurebot | "; bound in a repl thread to the most recent value printed" |
| 17:50 | lozh | Oh, it's a clojure thing - thanks! |
| 17:52 | slyrus_ | chouser: as long as we're being pedantic, why don't we force namespaces to :use clojure.core? |
| 18:01 | somnium | once or twice I would've liked to be able to '(require [clojure.core :as core]) |
| 18:01 | chouser | that works |
| 18:02 | somnium | really? |
| 18:05 | somnium | ah, cool. this worked (ns ... (:refer-clojure :only []) (:require [clojure.core :as core])) |
| 18:40 | nickik | Can somebody help me with this: http://paste.lisp.org/display/112848 |
| 18:40 | nickik | why is it not working? |
| 18:40 | qbg | You should define the macro before use for one thing |
| 18:41 | nickik | evaluatet the macro first in my file |
| 18:41 | nickik | or repl |
| 18:41 | Raynes | Clojure isn't like Haskell. You can't use a function before it's defined unless you forward declare it with (declare) |
| 18:42 | qbg | (hash-map rest) looks wrong |
| 18:43 | qbg | (apply hash-map rest) would work |
| 18:43 | nickik | yeah |
| 18:43 | nickik | i was thinking (into {} rest) |
| 18:43 | qbg | You are also assuming something about the order of the seq returned by keys |
| 18:44 | qbg | (fn [a b] '(a b)) is probably not what you want |
| 18:44 | nickik | you mean in the (func .....) |
| 18:44 | qbg | Yes |
| 18:44 | nickik | it dont think it matters how they are orderd but i should change it for clarity |
| 18:46 | nickik | how else can i make a list of list like this ((key value) (key value)) |
| 18:46 | qbg | (seq {:a 1 :b 2}) |
| 18:46 | qbg | ,(seq {:a 1 :b 2}) |
| 18:46 | clojurebot | ([:a 1] [:b 2]) |
| 18:48 | tomoj | qbg: you mean we can't assume that keys and vals are in matching order? |
| 18:48 | tomoj | that would be strange |
| 18:49 | qbg | ,(into {} (for [x (range 26)] [(keyword (str (char (+ (int \a) x)))) x])) |
| 18:49 | clojurebot | {:r 17, :z 25, :y 24, :x 23, :a 0, :c 2, :b 1, :f 5, :g 6, :d 3, :e 4, :l 11, :k 10, :j 9, :m 12, :i 8, :n 13, :h 7, :o 14, :v 21, :w 22, :t 19, :u 20, :q 16, :p 15, :s 18} |
| 18:50 | nickik | i changed it to a sorted-map |
| 18:50 | qbg | ,(keys (into {} (for [x (range 26)] [(keyword (str (char (+ (int \a) x)))) x]))) |
| 18:50 | clojurebot | (:r :z :y :x :a :c :b :f :g :d :e :l :k :j :m :i :n :h :o :v :w :t :u :q :p :s) |
| 18:50 | qbg | nickik: Wouldn't an array-map be better here? |
| 18:51 | tomoj | ,(keys (into {} (for [x (range 26)] [(keyword (str (char (+ (int \a) x)))) x]))) |
| 18:51 | clojurebot | (:r :z :y :x :a :c :b :f :g :d :e :l :k :j :m :i :n :h :o :v :w :t :u :q :p :s) |
| 18:51 | tomoj | oops |
| 18:51 | tomoj | ,(vals (into {} (for [x (range 26)] [(keyword (str (char (+ (int \a) x)))) x]))) |
| 18:51 | clojurebot | (17 25 24 23 0 2 1 5 6 3 4 11 10 9 12 8 13 7 14 21 22 19 20 16 15 18) |
| 18:51 | tomoj | whew |
| 18:51 | qbg | keys and vals will always match |
| 18:52 | qbg | The order in which they are returned will not always be the same as the order they went into the map, of course |
| 18:52 | qbg | (which is what I was trying to point out) |
| 18:53 | nickik | if i do (let [body (sorted-map rest) func (map (fn [a b] '(a b)) (keys body) (vals body))]) should that be right too? |
| 18:54 | tomoj | ,(let [m {:foo 1 :bar 2}] (map (fn [a b] '(a b)) (keys m) (vals m))) |
| 18:54 | clojurebot | ((a b) (a b)) |
| 18:54 | tomoj | ,(let [m {:foo 1 :bar 2}] (seq m)) |
| 18:54 | clojurebot | ([:foo 1] [:bar 2]) |
| 18:54 | tomoj | much shorter, and it actually works, too! :D |
| 18:55 | tomoj | if you really want lists, how would you do it, though? |
| 18:55 | tomoj | maybe (map (partial apply list) {:foo 1 :bar 2}) ? |
| 18:56 | nickik | ah ok do it like this (fn [a b] '(~a ~b)) |
| 18:56 | tomoj | (map #(apply list %&) m) |
| 18:56 | nickik | or (fn [a b] (into '() [a b])) |
| 18:58 | brehaut | massive brain failure: whats the inverse to empty? |
| 18:58 | qbg | ,(hash-map [1 2 3] "a", :foo 2, "3" 6, 8 9, \a 2, '(1 4 3) 6, 'a 'b) |
| 18:58 | clojurebot | {\a 2, [1 2 3] "a", :foo 2, 8 9, a b, "3" 6, (1 4 3) 6} |
| 18:58 | qbg | brehaut: seq |
| 18:58 | brehaut | cheers |
| 18:58 | qbg | ,(source empty?) |
| 18:58 | clojurebot | java.lang.Exception: Unable to resolve symbol: source in this context |
| 18:58 | qbg | (empty? x) is (not (seq x)) |
| 18:58 | tomoj | oh, hmm |
| 18:59 | qbg | ,(sorted-map [1 2 3] "a", :foo 2, "3" 6, 8 9, \a 2, '(1 4 3) 6, 'a 'b) |
| 18:59 | clojurebot | java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to clojure.lang.Keyword |
| 18:59 | qbg | ,(array-map [1 2 3] "a", :foo 2, "3" 6, 8 9, \a 2, '(1 4 3) 6, 'a 'b) |
| 18:59 | clojurebot | {[1 2 3] "a", :foo 2, "3" 6, 8 9, \a 2, (1 4 3) 6, a b} |
| 18:59 | nickik | @brehaut (complement empty?) |
| 18:59 | qbg | ,(doc empty?) |
| 18:59 | nickik | but seq better |
| 18:59 | clojurebot | "([coll]); Returns true if coll has no items - same as (not (seq coll)). Please use the idiom (seq x) rather than (not (empty? x))" |
| 19:00 | nickik | if been doing that after someone mentions it in the mailinglist |
| 19:00 | tomoj | just (map #(apply list %1) {:foo 1 :bar 2}), not %& |
| 19:04 | nickik | @tomoj that is better thx |
| 19:05 | tomoj | er, don't even need the 1 |
| 19:06 | nickik | better is always posible :) |
| 19:10 | tomoj | I feel like there should be a cooler way than #(apply list %) |
| 19:11 | qbg | ,(map (partial apply list) {:foo 1 :bar 2}) |
| 19:11 | clojurebot | ((:foo 1) (:bar 2)) |
| 19:11 | hiredman | apply list is seq |
| 19:12 | hiredman | ,(map seq {:foo 1 :bar 2}) |
| 19:12 | clojurebot | ((:foo 1) (:bar 2)) |
| 19:12 | tomoj | great :) |
| 19:12 | hiredman | why are you doing that anyway? |
| 19:12 | tomoj | I'm not, nickik is |
| 19:13 | tomoj | macro, so maybe a good reason? |
| 19:14 | qbg | ,(list? `(5 ~2)) |
| 19:14 | clojurebot | false |
| 19:15 | hiredman | ,(doc list?) |
| 19:15 | clojurebot | "([x]); Returns true if x implements IPersistentList" |
| 19:15 | hiredman | ,(class `(5 ~2)) |
| 19:15 | clojurebot | clojure.lang.Cons |
| 19:15 | technomancy | list? is the black-sheep predicate. |
| 19:15 | hiredman | ,(supers clojure.lang.Cons) |
| 19:15 | clojurebot | #{java.io.Serializable clojure.lang.Sequential clojure.lang.Seqable java.util.Collection clojure.lang.IObj java.lang.Object java.util.List clojure.lang.ISeq clojure.lang.ASeq clojure.lang.IPersistentCollection clojure.lang.Obj java.lang.Iterable clojure.lang.IMeta} |
| 19:15 | hiredman | not a IPersistentList |
| 19:16 | KirinDave | Wait. |
| 19:16 | KirinDave | Waaiiiitt a minute. |
| 19:16 | KirinDave | http://twoguysarguing.wordpress.com/2010/07/26/7-rules-for-writing-clojure-programs/ |
| 19:16 | KirinDave | Rule 5 6 7 |
| 19:16 | qbg | I've used sequential? before once I know something is not a vector to see if something is list like |
| 19:16 | qbg | There should be a better way... |
| 19:16 | hiredman | seq? |
| 19:16 | clojurebot | @ splices in a seq and foo# is a symbol, not a seq |
| 19:16 | hiredman | ,(seq? (list 1 2)) |
| 19:16 | clojurebot | true |
| 19:17 | hiredman | if it prints in parens it's a seq |
| 19:17 | technomancy | even the queuefish? |
| 19:17 | KirinDave | I can't believe that -> and ->> are going to be demonized now. |
| 19:18 | hiredman | the queuefish is ineffable |
| 19:19 | tomoj | demonized? |
| 19:19 | tomoj | oh, I see, wow |
| 19:20 | tomoj | "Don’t be lazy" ? |
| 19:20 | hiredman | pretty sure he doesn't mean it |
| 19:20 | hiredman | ->> and -> are all about transformation |
| 19:20 | sexpbot | => #<core$_GT_ clojure.core$_GT_@11286929> |
| 19:20 | KirinDave | I guess that should be, "Don't do a lot of identical subfunctions when you really want a helper function |
| 19:20 | tomoj | oh, I see |
| 19:21 | KirinDave | hiredman: "Don’t use -> or ->>" is a nasty pullquote tho. |
| 19:21 | hiredman | *shrug* someone's wrong on the internet |
| 19:21 | KirinDave | Also, “Transformation is not recursion.” |
| 19:22 | tomoj | "Don't use -> or ->>" is right after "Use -> and ->> to make one liners easier to read" |
| 19:22 | nickik | the reason is that I build a function in a macro (cons 'fn .....) |
| 19:22 | KirinDave | I wonder if it really is 2 guys arguing. |
| 19:22 | tomoj | I think if you're calling things rules you should be somewhat careful about how you phrase them.. |
| 19:22 | nickik | the ........ are the key - value pairs |
| 19:23 | nickik | the key are the args |
| 19:23 | tomoj | so if two functions your macro would create happen to have the same arglist...? |
| 19:23 | nickik | so (fn ([n] (dosomething)) ([a b] (dosomething))) |
| 19:24 | tomoj | maybe that is not a concern for some reason for your macro? |
| 19:25 | KirinDave | fogus can't be serious about this. |
| 19:25 | nickik | its complicated to explain |
| 19:27 | nickik | ihas nothing to do with fogus |
| 19:27 | nickik | *it |
| 19:28 | tomoj | nickik: no one will ever do something like (def-contracted-fn foo :contract bar [a b] baz [a b] bing)? that's what I meant |
| 19:28 | tomoj | oh you're just passing them to fn, so it doesn't matter :) |
| 19:29 | nickik | why not its better then define contracts outside and then do the (def somename (with-contrains your-function your-contract)) |
| 19:30 | nickik | and you could use more then one contract for one function if you do :contract [contract-1 contract-2] |
| 19:30 | nickik | the name def-contracted-fn is just temp |
| 19:34 | tomoj | huh |
| 19:37 | nickik | I just dont want to defin a contract then a function and then a nother def to connect them both |
| 19:38 | tomoj | were you not responding to what I said? |
| 19:40 | slyrus_ | como se dice digit-char-p in clojurian? |
| 19:41 | slyrus_ | ,(int \3) |
| 19:41 | clojurebot | 51 |
| 19:42 | nickik | @tomoj only saw the second thing just now sry |
| 19:42 | tomoj | nickik: no problem, was just confused |
| 19:43 | tomoj | slyrus_: what would (int (char 3)) return? |
| 19:43 | tomoj | or, if that returns 3, what would (char 51) return? |
| 19:44 | slyrus_ | ^c doesn't represent an integer, throw an error. |
| 19:44 | slyrus_ | yeah, yeah... |
| 19:44 | slyrus_ | presumably there's some unicode char <--> char-code mapping going on somewhere, no? |
| 19:46 | mefesto | ,(map int (map char "123abc")) |
| 19:46 | clojurebot | (49 50 51 97 98 99) |
| 19:47 | mefesto | err strings are char seqs so... |
| 19:47 | mefesto | ,(map int "123abc") |
| 19:47 | clojurebot | (49 50 51 97 98 99) |
| 19:47 | nickik | thanks for the help. My first real macro works ... in some cases :) |
| 19:48 | slyrus_ | ,(int \a) |
| 19:48 | clojurebot | 97 |
| 19:49 | slyrus_ | who says that (int \a) is 97? the clojure language spec? latin-1? presumably the way characters are converted to ints is documented somewhere. |
| 19:49 | mefesto | slyrus_: i think ascii and beyond |
| 19:50 | somnium | slyrus_: could you do something like (when (<= 48 (int c) 57) (- (int c) 48))? or (Integer/parseInt (str \3)) |
| 19:50 | slyrus_ | sure, I _could_. I'm used to having a nice handy digit-char-p lying around which I found much more attractive and readable than either of those, thank you... |
| 19:51 | somnium | slyrus_: there's always that handy `defn' in a pinch :) |
| 19:51 | tomoj | slyrus_: do you care about the radix arg? |
| 19:51 | slyrus_ | not at the moment |
| 19:51 | tomoj | #(.isDigit %) would work, I think |
| 19:52 | tomoj | oh, no |
| 19:52 | tomoj | #(Character/isDigit %) |
| 19:53 | mefesto | slyrus_: fyi, http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters |
| 19:53 | mefesto | slyrus_: i think utf-8 is mostly backward compatible with that table |
| 19:54 | somnium | ,(Character/digit \3 9) |
| 19:54 | clojurebot | 3 |
| 19:55 | somnium | ,(Character/digit \a 9) |
| 19:55 | clojurebot | -1 |
| 19:55 | somnium | slyrus_: warmer? |
| 19:57 | slyrus_ | mefesto: I'm less interested in the ascii printable characters and more interested in knowing how clojure knows about that wikipedia page |
| 19:57 | slyrus_ | or at least the mapping contained therein |
| 19:57 | mefesto | slyrus_: i think it's less clojure and more how java does things |
| 19:57 | slyrus_ | does it just hand all of the string encoding stuff of to javaland? |
| 19:57 | mefesto | jvm using utf-8 i believe |
| 19:57 | mefesto | *uses |
| 19:58 | somnium | http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Character.html |
| 19:58 | slyrus_ | thanks somnium |
| 19:58 | arohner | slyrus: (int \a) is defined by the ascii spec, as implemented by Java |
| 19:59 | slyrus_ | ok. I'll use CL for all of my EBCDIC coding requirements then :) |
| 19:59 | mefesto | "A String represents a string in the UTF-16 format in which supplementary characters are represented by surrogate pairs (see the section Unicode Character Representations in the Character class for more information)" |
| 20:00 | mefesto | http://java.sun.com/javase/6/docs/api/java/lang/String.html |
| 20:01 | technomancy | I heard CL is _really_ good at EBCDIC |
| 20:04 | slyrus_ | ok, thanks for the help everyone. the important point, for me, is that Character/digit will handle the encoding for the code point and do the right thing. |
| 20:05 | slyrus_ | so Character/digit is the digit-char-p equivalent i was looking for |
| 20:05 | slyrus_ | which is much nicer than, say, subtracting 48 from (int the-char). |
| 20:13 | slyrus_ | ,(chars "moose") |
| 20:13 | clojurebot | java.lang.ClassCastException: java.lang.String cannot be cast to [C |
| 20:16 | tomoj | ,((juxt identity seq) (.toCharArray "moose")) |
| 20:16 | clojurebot | [#<char[] [C@184dc10> (\m \o \o \s \e)] |
| 20:16 | mefesto | ,(.toCharArray "moose") |
| 20:16 | clojurebot | #<char[] [C@1b995c2> |
| 20:17 | slyrus_ | tomoj, mefesto: thanks, but the error message could be a little nicer :) |
| 20:17 | mefesto | slyrus_: must it be a character array? a string is a seq of chars |
| 20:18 | slyrus_ | no, i was just surprised at that error, that's all |
| 20:18 | slyrus_ | and, yes, strings being seqs of chars is indeed very nice :) |
| 20:18 | tomoj | could be nicer by saying "char array" instead of "[C"? |
| 20:19 | slyrus_ | ah, that's what that means. thanks! |
| 20:21 | arohner | [C is java's .toString on an array |
| 20:22 | arohner | pprint'ing it is nicer |
| 20:22 | arohner | ,(clojure.pprint/pprint (into-array Character/TYPE [\a \b \c])) |
| 20:22 | clojurebot | [\a, \b, \c] |
| 20:23 | hiredman | [C is the jvm internal type of an array of characters |
| 20:23 | hiredman | [B is bytes |
| 20:23 | hiredman | etc |
| 20:24 | hiredman | [Ljava/lang/Object; is objects |
| 21:23 | reburg | why doesn't #({% 1}) work, while (fn [a] {a 1}) does? |
| 21:23 | cemerick | #({% 1}) is the equivalent of (fn [a] ({a 1})) |
| 21:24 | reburg | cemerick: but (#{% 1} :foo) throws an exception |
| 21:24 | reburg | oh wait |
| 21:24 | reburg | i see what you typed now |
| 21:24 | reburg | cemerick: thank you! |
| 21:25 | cemerick | reburg: #(hash-map % 1) is what you want (though that's a little odd :-) |
| 22:12 | Drakeson | technomancy: ping |