2009-01-06
| 00:40 | zakwilson | Slime is evaluating expressions from a file (via C-x C-e and C-c C-c) in the user namespace instead of the file's namespace. I've eval'd the ns form and set the ns in the repl. Am I missing something obvious? |
| 00:43 | dhaya | zakwilson: are you sure it is evaluating in the user namespace? try evaluating *ns* and see what that returns. |
| 00:44 | zakwilson | I did. It returns #<Namespace user> |
| 00:47 | zakwilson | dhaya: it only returns the correct ns in the repl. |
| 00:50 | dhaya | strange. i don't seem to have that problem. |
| 00:54 | zakwilson | And now that I've updaded everything to the bleeding edge, the repl doesn't come up properly - just the *inferior-lisp* buffer. |
| 00:54 | dhaya | any error messages? |
| 00:56 | zakwilson | Yes: Exception in thread "Call-on-write Stream" java.lang.RuntimeException: java.lang.IllegalArgumentException: No matching method found: sleep for class java.lang.Class |
| 00:56 | dhaya | did you update swank clojure? IIRC that was fixed a while back. |
| 00:56 | zakwilson | Though I seem to remember seeing an exception when Slime started before, as well as some discussion to the effect that it isn't a problem. |
| 00:57 | zakwilson | Yes. I just now updated it - it didn't do that until I did. |
| 01:05 | dhaya | FWIW, I am on the bleeding edge now and I don't have any trouble starting slime/swank. |
| 01:07 | zakwilson | java.lang.Exception: No such namespace: clojure (swank.clj:11) |
| 01:08 | zakwilson | Though I don't see where it's getting that, looking at the file. |
| 01:08 | danlarkin | yeah you're probably pulling in an old swank-clojure, since clojure hasn't been a namespace for a while |
| 01:13 | zakwilson | danlarkin: It looks like it might be pointing to an old file I forgot was there. Working on it. |
| 01:17 | zakwilson | I've eliminated any references to old files that don't work anymore, but I'm still not getting a repl. |
| 01:17 | zakwilson | No more exceptions though. |
| 01:18 | danlarkin | I'm also on bleeding edge and everything is working okay for me |
| 01:18 | danlarkin | but now I'm off to bed |
| 01:18 | danlarkin | goodnight all |
| 01:28 | durka | i'm working on a program to help with missing imports |
| 01:28 | durka | => (lookup "Ref") |
| 01:28 | durka | ["java.sql.Ref" "sun.misc.Ref" "com.sun.xml.internal.bind.v2.model.core.Ref" "com.sun.xml.internal.bind.v2.runtime.reflect.opt.Ref" "com.sun.xml.internal.xsom.impl.Ref" "clojure.lang.Ref"] |
| 01:28 | durka | this only works after a time-consuming scan of the classpath |
| 02:49 | fffej | if I apply map to a hash-map, what should be the structure I return so as to keep the returned collection working with assoc / get etc? |
| 02:53 | cmvkk | map just returns a list i guess |
| 02:54 | fffej | is there a way I can return that list that is easily converted back into a hash-map? |
| 02:54 | cmvkk | yeah, if you use pairs in vectors |
| 02:54 | cmvkk | (into {} '([:a 1] [:b 2] [:c 3])) will return a map as you expect |
| 02:55 | fffej | sweet - pairs in vectors was the magic I was looking for, thanks! |
| 03:12 | fmeza | quit |
| 03:12 | fmeza | exit |
| 03:58 | Lau_of_DK | Ola 'el Kota' |
| 03:59 | kotarak | Hola, se�or. |
| 05:05 | AWizzArd | Moin |
| 05:07 | AWizzArd | How can I make POST requests in Clojure? |
| 05:12 | kotarak | AWizzArd: HttpURLConnection has a setRequestMethod.... |
| 05:17 | Lau_of_DK | AWizzArd: Theres a http-client in Contrib which handles that stuff very nicely |
| 05:20 | AWizzArd | yes, and I wanted to use this http-client in the past for get requests and got the suggestion to better use duck-streams reader. |
| 05:20 | AWizzArd | And is there already something for xml-rpc in Clojure? |
| 05:21 | Lau_of_DK | Check out lazy-xml in contrib :) |
| 05:21 | Lau_of_DK | That might be it |
| 05:46 | knapr | how do I break a line in a string without adding a \n or \r ? |
| 05:52 | AWizzArd | knapr: inside the quotes press enter |
| 05:53 | AWizzArd | Lau_of_DK: I think lazy-xml is more for parsing than doing xml-rpc requests via http post. |
| 07:20 | AWizzArd | If I have a directory with 10 .jar files, is there then a way to add them all to the classpath by specifying a placeholder or something like that? "classpath=/home/user/lib/*" |
| 07:21 | Lau_of_DK | java -cp . |
| 07:21 | Lau_of_DK | will add all files in current directory to cp |
| 07:26 | AWizzArd | oki, I will try the dot as placeholder instead of the star for the windows env var |
| 07:32 | StartsWithK | AWizzArd: There is no wildcard substitution for -cp |
| 07:32 | StartsWithK | what you can do is write small shell script, like: CP=lib/* java -cp $CP ... |
| 07:33 | StartsWithK | and bash will expand lib/* for you |
| 07:33 | Lau_of_DK | StartsWithK: I heard people say that, but wildcards work fine here |
| 07:33 | StartsWithK | Lau_of_DK: Is that only a windows thing then? |
| 07:34 | Lau_of_DK | Might be, Im on Linux |
| 07:34 | StartsWithK | java -cp lib/* clojure.lang.Repl |
| 07:34 | AWizzArd | StartsWithK: I want to put the 10-20 .jars into the environment variable in Windows. |
| 07:35 | StartsWithK | this will fail |
| 07:35 | StartsWithK | java -cp "lib/*" clojure.lang.Repl |
| 07:35 | StartsWithK | this will work |
| 07:35 | StartsWithK | form prompt |
| 07:35 | StartsWithK | from* |
| 07:35 | StartsWithK | AWizzArd: maybe this quoted form will work? "lib/*" |
| 07:36 | AWizzArd | I will try some variations |
| 07:36 | Lau_of_DK | ah thats right K, its got to be quoted |
| 07:36 | StartsWithK | it works for me on linux |
| 07:36 | Lau_of_DK | but I think everything needs to be quoted in Windows anyway |
| 07:36 | Lau_of_DK | /clojure$ java -cp "./*" clojure.lang.Repl |
| 07:36 | Lau_of_DK | Clojure |
| 07:36 | Lau_of_DK | user=> (+ 2 2) |
| 07:36 | Lau_of_DK | 4 |
| 07:36 | Lau_of_DK | |
| 07:38 | StartsWithK | i always used small launcher script so didn't even notice this quoted form |
| 07:38 | StartsWithK | can it be used like "lib/**/*.jar"? |
| 07:48 | knapr | can I say "select avg(cast(grade as double)) from reviews for customerid in customers"? |
| 07:48 | knapr | sql that is |
| 07:48 | knapr | something like that |
| 07:48 | knapr | I have a bunch fo moviereviews and want to find the highest average reviewers and lowest |
| 07:48 | knapr | I have 3 tables, customers(:customerid), reviews(:customerid, :grade, :review-date, :movieid) and movies(:title, :releasedate, :movieid) |
| 07:52 | knapr | group by? |
| 07:57 | knapr | how do I set primary key with contrib/sql? |
| 08:01 | AWizzArd | How do you want to "set" a primary key? |
| 08:01 | AWizzArd | When you insert you just specify a value... |
| 08:02 | AWizzArd | Or in the case of mysqls auto-increment even that is not needed. |
| 08:08 | knapr | (query "select avg(cast(reviews.grade as double)), customers.customerid |
| 08:08 | knapr | from reviews join customers on reviews.customerid = customers.customerid |
| 08:08 | knapr | group by customerid") |
| 08:08 | knapr | java.sql.SQLSyntaxErrorException: Column name 'CUSTOMERID' is in more than one table in the FROM list. (db.clj:0) |
| 08:08 | knapr | user=> |
| 08:08 | knapr | uh? |
| 08:10 | StartsWithK | group by reviews.customerid |
| 08:12 | knapr | ah |
| 08:29 | knapr | http://paste.pocoo.org/show/98246/ |
| 08:30 | knapr | ^^ anyone can help me with tis fairly complex sql-statement |
| 08:30 | knapr | code and sql error ^^ |
| 08:31 | Lau_of_DK | :) Well, I could, if you used a proper lib :) |
| 08:34 | knapr | ok |
| 08:34 | knapr | im pulling uit |
| 08:38 | cgrand | knapr, try replacing customers.customerid by reviews.customerid |
| 08:38 | Lau_of_DK | Ok, review the demos, ask me or kota tonight if you need help, im at work, he's offline I believe. the run macro will feed you a resultset-seq, you can cast values on their way out of that |
| 08:38 | knapr | yeah wait |
| 08:39 | knapr | why am i even joining lol? |
| 08:40 | knapr | (query "select avg(cast(grade as double)), customerid |
| 08:40 | knapr | from reviews group by customerid") |
| 08:40 | knapr | but does this calc the average grade for all customers? |
| 08:45 | knapr | is defn like pythons _thisisprivate_ ? |
| 08:46 | knapr | is defn- like pythons _thisisprivate_ ? |
| 08:46 | knapr | not enforced privacy, just "dont touch this t is internal k thanks" |
| 08:50 | knapr | how do I require clojure-ql? |
| 08:51 | lisppaste8 | gnuvince pasted "defn-" at http://paste.lisp.org/display/73180 |
| 08:51 | gnuvince_ | knapr: see this link |
| 08:54 | knapr | thanks |
| 08:57 | knapr | where is condp Lau? |
| 08:58 | knapr | is condp in a new clojure-version? im using december |
| 09:03 | Chousuke | knapr: I think condp is SVN-only right now. |
| 09:05 | Lau_of_DK | knapr: Its in the latest SVN, you must update |
| 09:08 | knapr | what does condp do? |
| 09:08 | Lau_of_DK | Its a clever way of nesting cond's |
| 09:08 | Lau_of_DK | (doc condp) |
| 09:08 | clojurebot | No entiendo |
| 09:08 | Lau_of_DK | its similar to a switch statement |
| 09:10 | knapr | ah |
| 09:10 | Chousuke | wow, condp is pretty complex. |
| 09:10 | Chousuke | :>> seems pretty useful though |
| 09:52 | knapr | anyone doing the netflix prize? |
| 09:55 | gnuvince_ | When I use SLIME at work (no GUI), I can start slime just fine, but I just get the *inferior lisp* buffer, not the *clojure repl* one where typing a function name displays the arguments in the mini buffer. Anyone had this problem before? |
| 09:56 | gnuvince_ | The config file is the same than the one at home and so are the versions of Clojure, slime and swank-clojure. |
| 09:58 | gnuvince_ | Ah, I caught billc's message about breaking changes |
| 09:58 | Lau_of_DK | :) |
| 10:00 | gnuvince_ | That's sad :( |
| 10:01 | Chousuke | sad? |
| 10:01 | gnuvince_ | Yeah |
| 10:02 | Chousuke | in the new slime you just need to enable the fancy repl manually |
| 10:02 | Chousuke | it's pretty easy. |
| 10:04 | gnuvince_ | How is that done? |
| 10:04 | gnuvince_ | (slime-setup '(fancy-repl)? |
| 10:05 | Chousuke | http://github.com/Chousuke/dotfiles/tree/master/Aquamacs-customizations.el#L59 |
| 10:06 | knapr | when using drop-table from contrib.sql doesnt that delete the table forever? |
| 10:06 | Chousuke | yes. |
| 10:06 | Chousuke | well, drop table usually dpes that :P |
| 10:06 | Chousuke | does* |
| 10:07 | gnuvince_ | great |
| 10:07 | gnuvince_ | thanks |
| 10:07 | gnuvince_ | Chousuke++ |
| 10:11 | gnuvince_ | hmmm |
| 10:11 | gnuvince_ | it worked before I restarted Emacs... |
| 10:13 | Chouser | I enjoy having an environment that doesn't break when I upgrade things. |
| 10:14 | Chousuke | gnuvince_: is your clojure-swank also recent? :/ |
| 10:15 | gnuvince_ | yes |
| 10:15 | gnuvince_ | It's a git submodule |
| 10:15 | gnuvince_ | I seem to have it... |
| 10:15 | Chousuke | submodules are one feature of git I have no clue about :/ |
| 10:15 | gnuvince_ | I'm clueless about most git features |
| 10:16 | gnuvince_ | I dislike it |
| 10:16 | Chousuke | I would probably like most of the DVCS systems. |
| 10:17 | Chousuke | but I'm familiar with git so obviously I like it the best. |
| 10:17 | gnuvince_ | argh... |
| 10:17 | gnuvince_ | stupid submodules... |
| 10:17 | gnuvince_ | they're the cause of my problem |
| 10:18 | Chousuke | one thing is certain though. I will never again use SVN for any of my projects :P |
| 10:18 | Chousuke | it's too... restrictive. |
| 10:19 | gnuvince_ | I like Mercurial myself. It makes a whole lot of sense, but it seems that git is poised to become the de facto DVCS for open source projects, so I make an effort to use and learn it. |
| 10:19 | Chousuke | mercurial and git are probably not too different. |
| 10:20 | Chousuke | I wonder if there's a hg equivalent to the "git magic" tutorial :/ |
| 10:21 | gnuvince_ | Dunno what that is. |
| 10:21 | gnuvince_ | But Hg feels less disparate than git |
| 10:23 | Chousuke | git magic is this: http://www-cs-students.stanford.edu/~blynn/gitmagic/ |
| 10:23 | Chousuke | clojurebot: git? |
| 10:23 | clojurebot | git is http://www.github.com |
| 10:23 | Chousuke | hm |
| 10:27 | gnuvince_ | Fuck this sucks... |
| 10:27 | gnuvince_ | I do git submodule update and slime breaks |
| 10:54 | triddell | In case anyone is interested, I just posted (to the google group) a pretty print function for xml/xhtml which uses the javax.xml classes in the JDK. |
| 11:17 | Chouser | pretty print is marked as done on the clojure todo, but I'm not aware of any complete (non-xml) pretty printer. Did I miss it somewhere? |
| 11:27 | danlarkin | news to me |
| 11:36 | triddell | Chouser: so was there a clojure-based pretty print for xml that I missed before writing this function? I asked on here and searched yesterday but didn't find one. |
| 11:40 | Chouser | triddell: not really. clojure.xml/emit adds newlines, but doesn't indent |
| 11:44 | triddell | Chouser: ok, well the function I wrote is a big hammer for this problem but solved the issue for me for now |
| 11:44 | Chouser | sure, thanks for sharing it. |
| 11:45 | AWizzArd | Does anyone here use the xml-rpc lib from http://ws.apache.org/xmlrpc/ from time to time? I am having a problem when I say (def client (XmlRpcClient.)) |
| 11:46 | AWizzArd | This throws a NoClassDefFound exception for org.apache.xmlrpc.common.TypeFactoryImpl. |
| 11:46 | rhickey | Chouser: pprint is done as far as the todo list - moved to issues - http://code.google.com/p/clojure/issues/detail?id=16 |
| 11:46 | rhickey | todo list is soon to be no more |
| 11:46 | AWizzArd | But when I type org.apache.xmlrpc.common.TypeFactoryImpl into the repl it returns the class. So, the class is in the classpath. |
| 11:47 | Chouser | rhickey: ah! very good. |
| 11:53 | triddell | AWizzArd: I haven't seen any issues with importing classes and name resolution |
| 11:57 | AWizzArd | I also didn't have this problem before. |
| 12:54 | sulo_ | hi folks... can anyone tell me.. is there a clojure tutorial or something like that around? on the webpage i couldn't find anything |
| 13:00 | vogelrn | tutorial as in how to use it or how to install it? |
| 13:00 | meredydd | What happened to clojure.contrib.def? Specifically, how do I get 'defvar- back, or something like it? |
| 13:01 | technomancy | sulo_: the book is definitely the best resource for that. there's not anything else that's well-organized and canonical. |
| 13:01 | technomancy | although you could try the wikibook |
| 13:01 | technomancy | clojurebot: wikibook? |
| 13:01 | clojurebot | I don't understand. |
| 13:01 | danlarkin | clojurebot: wiki |
| 13:01 | clojurebot | wiki is http://en.wikibooks.org/wiki/Clojure_Programming |
| 13:10 | danlarkin | sulo_: I will still recommend the videos at http://clojure.blip.tv |
| 13:14 | zargon_ | how can I (take ) n values from a seq and later take another n values from the now "shortened" seq? |
| 13:14 | technomancy | the videos are great for getting excited. not sure if they're so good for coding though. |
| 13:16 | danlarkin | (doc drop) |
| 13:16 | clojurebot | Returns a lazy seq of all but the first n items in coll.; arglists ([n coll]) |
| 13:16 | danlarkin | zargon_: ^ |
| 13:16 | hoeck | zargon_: maybe look at split-at |
| 13:16 | hoeck | too |
| 13:16 | danlarkin | (doc partition) |
| 13:16 | clojurebot | Returns a lazy sequence of lists of n items each, at offsets step apart. If step is not supplied, defaults to n, i.e. the partitions do not overlap.; arglists ([n coll] [n step coll]) |
| 13:16 | Chousuke | or partition |
| 13:16 | Chousuke | right |
| 13:17 | zargon_ | aha, ok |
| 13:20 | zargon_ | I guess (drop n) on a seq is O(n), right? So dropping in a loop is a bad idea ... |
| 13:21 | danlarkin | if you tell us what you're trying to achieve perhaps we can help suggest a good way to accomplish it |
| 13:22 | zargon_ | I just wondered how to consecutively take n values from a seq without too much of a performance hit, but i think (partition ) would be the solution |
| 13:23 | danlarkin | just be careful of the following: |
| 13:23 | danlarkin | (take 2 [1 2 3 4 5]) |
| 13:23 | danlarkin | ,(take 2 [1 2 3 4 5]) |
| 13:23 | clojurebot | (1 2) |
| 13:23 | danlarkin | err |
| 13:23 | danlarkin | well my point is that 5 is left dangling |
| 13:24 | zargon_ | ? |
| 13:24 | danlarkin | ,(partition 2 [1 2 3 4 5]) |
| 13:24 | clojurebot | ((1 2) (3 4)) |
| 13:24 | danlarkin | sorry, that is what I meant to write |
| 13:24 | zargon_ | ok i see |
| 13:37 | knapr | how can I set primary key and foreign key in contrib.sql? |
| 13:37 | knapr | (defn create-reviews-table [] (sql/create-table :reviews [:customerid :int] |
| 13:37 | Lau_of_DK | knapr: May I recommend to you, the Google Group, for those question that do not get answered here, even after posting them 5+ times |
| 13:37 | knapr | [:foreignkey =? |
| 14:03 | duck1123 | Lau_of_DK: would you recommend ClojureQL for use yet, or is it still unstable? |
| 14:04 | Lau_of_DK | duck1123: It depends on the scope I'd say. The function that are currently implemented, are all stable as far as we have been able to test, but admittedly, we have not tested it sufficiently |
| 14:04 | Lau_of_DK | For common use (select, insert, update) I wouldnt hestitate to use it myself |
| 14:07 | duck1123 | I was looking at it last night when I was getting frustrated at using format to create queries. It still needs a bit more documentation. I would have to play with it a bit before trying to replace c.contrib.sql |
| 14:08 | Lau_of_DK | Point taken, we do need to invest some time documentating the features, however if you review the demo files included in the repo, you should be able to catch on pretty quickly |
| 14:08 | Lau_of_DK | And if you have questions, shoot |
| 14:10 | duck1123 | quick question, do the results come back as a struct or a hash-map, or other? |
| 14:11 | Lau_of_DK | Currently all queries return as resultset-seq's, which are available while the connection is open only, they are sort of lazy |
| 14:12 | Lau_of_DK | @ duck1123 |
| 14:12 | technomancy | is the SQL lib in contrib lazy? |
| 14:12 | Lau_of_DK | dunno |
| 14:12 | Lau_of_DK | I think so |
| 14:13 | technomancy | so the main advantage is decent syntax rather than constructing SQL strings |
| 14:14 | Lau_of_DK | technomancy: Its more than just syntax, the queries themselves become qualitifed for standard clojure set operations like union, intersect, concat and so on, so you can perform clojure-code on them |
| 14:14 | duck1123 | Lau_of_DK: contrib requires the connection to be open as well, so that's no big deal |
| 14:14 | technomancy | cool |
| 14:15 | Lau_of_DK | duck1123: I didnt say it was, you just asked how the results were returned |
| 14:16 | duck1123 | I ran into an issue last night when trying to dissoc the results from a contrib.sql query, so I was wondering if the same would apply with clojureql |
| 14:17 | kotarak | duck1123: what do you mean by dissoc? |
| 14:17 | Chouser | if each result row is a structmap, you can't dissoc any basis key |
| 14:18 | Chouser | you can set the value to nil, but not dissoc |
| 14:18 | duck1123 | I was trying to remove a key-val from the results of a query, but since it's a struct, you can't dissoc the base keys |
| 14:18 | Chouser | you could copy into a new map, though, and dissoc from that. |
| 14:18 | kotarak | Ah. Ok. For now we also use struct-maps. |
| 14:18 | Chouser | I think struct-maps are probably the right solution |
| 14:19 | duck1123 | Chouser: I tried that, but I don't think I was getting the syntax right. |
| 14:19 | Lau_of_DK | duck1123: For what purpose did you want to filter data ? |
| 14:19 | Chouser | (dissoc (into {} result-row) :col-to-remove) |
| 14:20 | Chouser | seems like an odd use-case, those. I don't think I'd warp an API to support it any better than that. |
| 14:20 | duck1123 | Chouser: thanks. That was not what I was trying. Much better |
| 14:20 | Lau_of_DK | duck1123: If there are features you want in result-handling, now's the time to make your case |
| 14:21 | duck1123 | Lau_of_DK: I am joining tables, and I was trying to convert the last column into a vector of maps of the values of the second table |
| 14:22 | duck1123 | There's probably a much better sollution, but it was late when I was working on this |
| 14:25 | Lau_of_DK | duck1123: Yea there might be a better way to construct that query, but I'll think it over. Im not bent on the resultset-seq solution, but for what we support now it makes a very good fit |
| 14:25 | duck1123 | I'm trying to produce something like: {:id 1, :name "duck1123", :identities [{:url "http://duck1123.myopenid.com/", :primary false}, {:url "http://kronkltd.net/", :primary true}]} |
| 14:25 | whidden | Are there any examples of clojure.contrib.Monad laying around? If so a gentle pointer to their locaction would be nice. |
| 14:26 | Chouser | whidden: did you search the google group? |
| 14:27 | whidden | nope.. not yet... just saw the new checkins, did a google search on Monad, and got a bucket full of Haskel. |
| 14:27 | Chouser | heh |
| 14:27 | whidden | i don't grok haskel, not sure if this is good or bad at the moment. |
| 14:27 | kotarak | duck1123: (let-query [result1 (query ...) result2 (query ...)] (do-something-arbitrary with result1 and result2) ; should return a seq) |
| 14:28 | Chouser | there are a couple threads on monads in the group. I'm not sure, but I think the contrib is based on one of those, and there may be examples in the discussion. |
| 14:28 | kotarak | duck1123: The return value of let-query is again a query, which can be passed to run or whatever. |
| 14:29 | duck1123 | kotarak: thanks. I think I'll play with clojureql when I get home tonight |
| 14:29 | kotarak | duck1123: be warned! docs? nope stable? nope |
| 14:30 | duck1123 | Then it'll fit in nicely with the rest of my site. :) |
| 14:30 | kotarak | hehe :) |
| 14:31 | Lau_of_DK | kotarak: Why do you say not stable? |
| 14:32 | duck1123 | Lau_of_DK: so I wouldn't be disappointed if I find a problem |
| 14:32 | kotarak | well. we are not a rekease,yet. So maybe something may change in the interface. Or maybe not. But one should not rely on it for now. |
| 14:32 | Lau_of_DK | You shouldnt be, you should report the bug. But I just havent come across anything that was buggy yet in the current form |
| 14:32 | Lau_of_DK | Though, that form may change in the next couple of hours :) |
| 14:33 | kotarak | There are specialities how to use it, which are not documented, yet. |
| 14:38 | Chousuke | it's kind of confusing that even though rng is a function, in the domonad syntax in one of your examples, there are no parens around rng, so it looks like you're simply taking its value :/ |
| 14:43 | whidden | ok back from reading about monads in google groups.. not a lot, saw the parser, will play with that tonight and see how my groking goes. Thanks for the pointer. |
| 14:46 | Chousuke | kotarak: what's the status of your parser btw? |
| 14:47 | Chousuke | kotarak: your page on it is outdated at least. In your example, you have a #(.isLetter Character %) which is no longer valid :) |
| 14:47 | kotarak | Chousuke: Currently fiddling around with my multimethod monads. I spent some time on the monad transformer part, but I can't say, that I understand this. |
| 14:47 | kotarak | Chousuke: yes it's very outdaten. |
| 14:48 | kotarak | Chousuke: Have to bring it up-to-date, but Lau interrupted me with ClojureQL. ;) |
| 14:52 | danlarkin | oh speaking of parser |
| 14:53 | danlarkin | http://github.com/joshua-choi/fnparse/tree/master |
| 14:54 | kotarak | danlarkin: yeah. I'm still unsure on how to represent the parser result. |
| 14:54 | hiredman | oooo |
| 14:56 | danlarkin | it's not a parser combinator, but it's definitely interesting work |
| 14:57 | kotarak | danlarkin: yeah, definitively. There so much going on around Clojure at the moment! :) Nice pointer. :D |
| 14:57 | duck1123 | see, this is why we need an EBNF for Clojure. We'll be able to parse Clojure in Clojure. :) |
| 14:58 | danlarkin | duck1123: I see what you did there... |
| 14:59 | gnuvince_ | Is it not possible to give meta data to a function? (def y (with-meta (fn [] :y) {:foo :bar})) |
| 14:59 | gnuvince_ | ? |
| 15:00 | kotarak | No. |
| 15:00 | Lau_of_DK | kotarak: sure? I think something changed in that regard in one of the recent revisions |
| 15:00 | gnuvince_ | Is there a way to carry around additional information about a function then? |
| 15:01 | kotarak | Namespaces have know meta-data. |
| 15:01 | kotarak | s/know/now/ |
| 15:03 | gnuvince_ | Ok |
| 15:03 | gnuvince_ | Weird thing |
| 15:03 | gnuvince_ | This works: (defn #^{:foo :bar} y [] :y) |
| 15:03 | mfredrickson | Lau_of_DK: is this what you want? |
| 15:03 | mfredrickson | http://gist.github.com/43965 |
| 15:03 | kotarak | gnuvince_: that attaches the metadata to y, the symbol. |
| 15:03 | Chousuke | gnuvince_: that attaches the metadata into the var. |
| 15:04 | Chousuke | hm? was it the symbol? |
| 15:04 | kotarak | #^ works on follows, that is the symbol y. From there it's probably transferred to the Var by def. |
| 15:05 | Chousuke | nope, you need to do (meta #'y) |
| 15:05 | gnuvince_ | This doesn't work however: (defmacro x [] (let [name 'y] `(defn #^{:foo :bar} ~name [] :y))) |
| 15:06 | Lau_of_DK | mfredrickson: gnuvince_ wants :) |
| 15:06 | kotarak | Chousuke: it is attached to the Var, but #^ is a reader macro. At that moment there is no Var. So it is attached to the Symbol y. From there it's transferred to the meta-data of the Var. |
| 15:07 | mfredrickson | i must admit I still don't have a great understanding of the Var vs. Symbol difference in clj |
| 15:07 | mfredrickson | vs. keywords |
| 15:07 | Chousuke | vars hold values |
| 15:07 | kotarak | gnuvince_: (defmacro x [] (let [name 'y] `(defn ~(with-meta name {:foo :bar}) [] :y))) |
| 15:08 | technomancy | a symbol is a name; nothing more |
| 15:08 | technomancy | all code is made up of symbols |
| 15:08 | Chousuke | mfredrickson: keywords are symbols that resolve to themselves |
| 15:08 | Chousuke | mfredrickson: symbols normally resolve to vars. |
| 15:08 | technomancy | Chousuke: keywords are mostly like in CL right? except for additionally being functions? |
| 15:09 | technomancy | and the colon isn't used to mean "no package" |
| 15:09 | Chousuke | I'm not sure what they are like in CL |
| 15:09 | Chousuke | well, single-colon keywords have no namespace .) |
| 15:09 | mfredrickson | ,(macroexpand-1 #'foo) |
| 15:09 | clojurebot | java.lang.Exception: Unable to resolve var: foo in this context (NO_SOURCE_FILE:0) |
| 15:09 | kotarak | :foo/bar |
| 15:10 | Chousuke | except wehn like that yeah |
| 15:10 | technomancy | in CL you use the notation package-name:symbol to refer to a symbol in a different package in a way that evals to itself. leaving out package-name becomes just :symbol, which IIRC is like being in a null package |
| 15:10 | mfredrickson | ,(macroexpand-1#'+) |
| 15:10 | clojurebot | java.lang.Exception: Unable to resolve symbol: macroexpand-1# in this context (NO_SOURCE_FILE:0) |
| 15:10 | mfredrickson | ,(macroexpand-1 #'+) |
| 15:10 | clojurebot | #'clojure.core/+ |
| 15:10 | Chousuke | mfredrickson: I don't think macroexpand works with reader macros. |
| 15:11 | Chousuke | ,(macroexpand-1 '#'+) |
| 15:11 | clojurebot | (var +) |
| 15:11 | mfredrickson | Chousuke: i think you are correct |
| 15:11 | Chousuke | ah, they do. |
| 15:11 | Chousuke | :P |
| 15:12 | mfredrickson | interesting |
| 15:12 | mfredrickson | ,(meta (var +)) |
| 15:12 | clojurebot | {:ns #<Namespace clojure.core>, :name +, :arglists ([] [x] [x y] [x y & more]), :file "core.clj", :doc "Returns the sum of nums. (+) returns 0.", :line 546, :inline #<core$fn__2956 clojure.core$fn__2956@1e21f52>, :inline-arities #{2}} |
| 15:13 | knapr | anyone good with statistics and math? i need to calculate rmse(root mean square error). but i dont get form wikipedia exactly how i do it. lets say a simple example is. correct is 4 3 3 and I guess 4 2 3, what would the rmse be then? sq(sqrt((4-4)+(3-2)+(3-3)) / 3) ? |
| 15:13 | knapr | and is the closer to 1 the better=? |
| 15:18 | mfredrickson | knapr: take the difference of all predictions with observed. square them. sum them. take the square root |
| 15:20 | mfredrickson | oops: finally divide by the square root of the number of pairs |
| 15:21 | whidden | knapr: and the closer to zero better. |
| 15:21 | wlr | whidden, monads.clj in the Google Group's Files section is a monolithic file with examples included |
| 15:22 | whidden | that would mean your predictions and results matched perfectly. |
| 15:22 | whidden | wlr: thanks.. I'll look at that. |
| 15:24 | Chouser | (/ (apply + (map #(* % %) (map - obs prd))) (Math/sqrt (count obs))) |
| 15:24 | Chouser | based on mfredrickson's description |
| 15:24 | whidden | wlr: I did not realize there was a files section for groups.. Thanks for the pointer. |
| 15:27 | rhickey | Chouser: thanks for comments patch! |
| 15:28 | whidden | Chouser: wouldn't it be (Math/sqrt (/ (apply + (map #(* % %)(map - obs prd))) (count obs))? |
| 15:28 | mfredrickson | whidden: yes. |
| 15:29 | wlr | whidden, np |
| 15:31 | gnuvince_ | I have *another* question about metadata (sorry) |
| 15:32 | gnuvince_ | If I have this function: |
| 15:32 | gnuvince_ | (defn #^{:foo :bar} f [] :f) |
| 15:33 | Lau_of_DK | gnuvince_: If we have to start appologizing for asking questions, I have a big backlog :( |
| 15:33 | Chouser | rhickey_: heh. sure. |
| 15:33 | gnuvince_ | is it possible to "copy" the meta-data to another instance? |
| 15:33 | gnuvince_ | For instance: |
| 15:33 | gnuvince_ | (let [x f] (:foo (meta x)) |
| 15:34 | Chouser | gnuvince_: the metadata from your defn is on the Var named f, not it's value (which is a fn) |
| 15:34 | kotarak | (defn f (meta #'g) [] :f) like that? |
| 15:35 | gnuvince_ | Chouser: so if I pass f as a parameter to another function, I don't have access to the meta-data, right? |
| 15:35 | Chouser | gnuvince_: so the moment you say (let [x f] ...), the Var f gets dereferenced to its current value (the fn) which is then bound to the local x. There's no way to get to f's metadata from x. |
| 15:35 | Chouser | gnuvince_: right. |
| 15:35 | gnuvince_ | meh |
| 15:35 | Chouser | you could choose to pass the Var |
| 15:36 | gnuvince_ | That would be ugly for the user |
| 15:36 | gnuvince_ | I'll have to think of something else. |
| 15:37 | Chouser | I do think it'd be nice to be able to put metadata on fns, but I think there's something about what they really are in the JVM that makes that a bit tricky to do. |
| 15:43 | gnuvince_ | There we go |
| 15:44 | gnuvince_ | I used a map instead. {:fn (fn [] ...), :the-meta-data-i-want [foo, bar]} |
| 15:45 | knapr | mfredrickson: [4 3 4] and [4 2 2] -> ((4-4)^2 + (3-2)^2 + (4-2)^2) / (sqrt 3) ? |
| 15:45 | knapr | http://paste.pocoo.org/show/98364/ |
| 15:45 | stuarthalloway | what should a function that alters multiple refs return? |
| 15:46 | stuarthalloway | there is something dissatisfying about returning the last modified thing, when conceptually everything happens at once |
| 15:46 | mfredrickson | knapr: see whidden's version -- take the sqrt of (/ (sum diff) (count diff)) |
| 15:46 | stuarthalloway | but on the other hand it seems ridiculous to write extra code when nobody is expected to look at the return value |
| 15:53 | Chouser | stuarthalloway: this is a function with a dosync in it? Or one that is expected to be used in a dosync? |
| 15:53 | stuarthalloway | reset-game from snake |
| 15:53 | pao | is anyone using vim for clojure? |
| 15:53 | pao | is it viable? |
| 15:53 | stuarthalloway | it has a dosync in it |
| 15:53 | stuarthalloway | it updates two things |
| 15:53 | kotarak | pao: yep |
| 15:54 | stuarthalloway | and returns (coincidentally) the last thing listed |
| 15:54 | Chouser | pao: absolutely |
| 15:54 | pao | kotarak: thx |
| 15:54 | durka_ | pao: yes |
| 15:54 | stuarthalloway | I find myself wanting to add a "nil" form at the end |
| 15:54 | durka | thanks largely to kotarak |
| 15:54 | stuarthalloway | vim is as viable for Clojure as for anything :-) |
| 15:54 | kotarak | pao: http://kotka.de/projects/clojure/vimclojure.html |
| 15:54 | pao | what reading list would you suggest for a completely lisp ignorant (I'm familiar with python/haskell) |
| 15:55 | pao | kotarak: thanks |
| 15:55 | pao | stuarthalloway: vim rocks... :-) |
| 15:55 | stuarthalloway | pao: practical common lisp by Seibel |
| 15:55 | red_fish | pao: http://books.pragprog.com/titles/shcloj/programming-clojure |
| 15:55 | pao | stuarthalloway: I'm inclined to abandon a language if it's not "vim friendly" ;-) |
| 15:55 | knapr | oops: finally divide by the square root of the number of pairs |
| 15:55 | kotarak | + stuarthalloway's blog about practical common lisp -> clojure |
| 15:55 | red_fish | i am reading it now |
| 15:55 | knapr | just so there is no misconception, ^^ that staement was wrong? |
| 15:56 | Chouser | stuarthalloway: I would leave it alone -- let dosync return what it does. I suppose you could wrap [] around the ref-set's, but it hardly seems worth it. |
| 15:56 | stuarthalloway | seibel book is all online: http://www.gigamonkeys.com/book/ |
| 15:56 | stuarthalloway | Chouser: my concern is leaking implementation detail |
| 15:56 | knapr | it is square root of the average? |
| 15:56 | stuarthalloway | or possibly having a consumer of the code, not looking at the source, think that the return value is meaningful |
| 15:56 | Chouser | stuarthalloway: oh, then maybe explicitly return nil? |
| 15:56 | stuarthalloway | right |
| 15:56 | Chouser | that's not too terrible |
| 15:57 | stuarthalloway | I hate the extra work |
| 15:57 | stuarthalloway | was thinking about writing a macro around dosync that returns nil |
| 15:57 | Chouser | there are a couple places in clojure code where you end up with a separate return value at the end of a 'do' block of some sort |
| 15:57 | Chouser | like agent action functions that are meant for side-effects and want to return their first arg unchanged. |
| 15:58 | pao | stuarthalloway: kotarak: thanks for the help |
| 15:58 | Chouser | pao: my only real lisp knowledge pre-clojure was from PG's "on lisp" |
| 15:59 | kotarak | pao: no problem |
| 15:59 | pao | Chouser: PG? |
| 15:59 | kotarak | Paul Graham |
| 15:59 | Chouser | http://www.paulgraham.com/onlisp.html |
| 15:59 | pao | kotarak: ops... ashamed |
| 16:00 | stuarthalloway | pao: PG is terrific |
| 16:00 | stuarthalloway | but I think Seibel is better suited for hands-on tutorial |
| 16:00 | pao | stuarthalloway: is a good sense I suppose :-) |
| 16:00 | pao | *in |
| 16:00 | stuarthalloway | the real right answer is to read both of them |
| 16:01 | pao | stuarthalloway: PG + siebel, right? |
| 16:01 | stuarthalloway | pao: yes, plus Norvig, Dybvig, and Friedman/Felleisen :-) |
| 16:02 | pao | stuarthalloway: wack! :-) |
| 16:03 | pao | stuarthalloway: that doesn't sound like lisp in 24 h ;-) |
| 16:03 | stuarthalloway | Chouser: I posted the return value question on the mailing list |
| 16:03 | stuarthalloway | pao: http://norvig.com/21-days.html |
| 16:03 | kotarak | pao: though it's a bit old and for Scheme: "Teach yourself Scheme in Fixnum days" might also help |
| 16:04 | stuarthalloway | and while I am posting random "Norvig rocks" links: http://norvig.com/Gettysburg/making.html |
| 16:06 | lisppaste8 | gnuvince pasted "lame quickcheck attempt" at http://paste.lisp.org/display/73202 |
| 16:07 | pao | is it reasonable to use clojure for trying out material from siebel&PG or is better to stick to clisp? |
| 16:07 | gnuvince_ | pao: better stick to clisp |
| 16:08 | pao | gnuvince_: thanx |
| 16:08 | Chousuke | there are translations of some of the examples to clojure though. |
| 16:09 | gnuvince_ | Anyone got comments on that quickcheck thing? |
| 16:10 | kotarak | gnuvince_: you could use classes for the arbitrary methods. (arbitrary Integer) |
| 16:10 | pao | is it difficult to migrate from clisp to clojure? |
| 16:10 | stuarthalloway | gnuvince_: have you looked at Fact? |
| 16:11 | gnuvince_ | stuarthalloway: I have not. Link? |
| 16:11 | stuarthalloway | http://groups.google.com/group/clojure/browse_thread/thread/193023afbf87698d |
| 16:12 | stuarthalloway | gnuvince_: Fact is also embedded in Compojure, which uses it for its tests: http://github.com/weavejester/compojure/tree/master |
| 16:12 | gnuvince_ | Hmmm |
| 16:12 | gnuvince_ | That's pretty cute |
| 16:12 | gnuvince_ | Oh well |
| 16:13 | gnuvince_ | at least I got to learn a little about metadata and symbols and macros :) |
| 16:13 | Chousuke | pao: well, immutability kind of forces you to rethink some algorithms :) |
| 16:13 | kotarak | gnuvince_: then there clojurecheck. But I have a hard time at the moment to work on it. |
| 16:14 | stuarthalloway | kotarak: I was just looking for a link to that |
| 16:14 | gnuvince_ | I think I saw that |
| 16:14 | kotarak | I haven't put up a site, yet. But the repo is online. |
| 16:14 | gnuvince_ | stuarthalloway: didn't you actually write that? |
| 16:15 | gnuvince_ | http://groups.google.com/group/clojure/browse_thread/thread/2cfdd49dace71125 |
| 16:15 | stuarthalloway | gnuvince: I wrote a few suggestions, but kotarak ran with it |
| 16:15 | gnuvince_ | ok |
| 16:15 | stuarthalloway | I have to keep reminding myself that my day job is writing prose, not code, at least for a few more weeks |
| 16:15 | gnuvince_ | ;) |
| 16:16 | gnuvince_ | How's the book coming? |
| 16:18 | kotarak | gnuvince_: if you are interested: http://www.bitbucket.org/kotarak/clojurecheck/overview/, but Fact and the others are probably farther down the road... |
| 16:18 | gnuvince_ | I like how Fact is looking |
| 16:18 | gnuvince_ | I'll look at clojurecheck |
| 16:19 | gnuvince_ | Although you have extra points for using Mercurial ;) |
| 16:19 | kotarak | hehe :) |
| 16:20 | danlarkin | I was sighing at bitbucket :) |
| 16:21 | gnuvince_ | danlarkin: why? |
| 16:24 | danlarkin | Mmmm |
| 16:25 | durka | i thought all of the #= were supposed to be gone from the repl? |
| 16:25 | stuarthalloway | gnuvince_: slow but steady. The Snake example will complete the "tour of libraries" chapter |
| 16:25 | danlarkin | it's a *lot* like github, but some of the ways it differs I do not like |
| 16:25 | stuarthalloway | which I have been thinking about renaming "Pandora's box" Having all of Java to choose from is a mixed bag |
| 16:27 | gnuvince_ | danlarkin: so what if it's similar? |
| 16:27 | gnuvince_ | stuarthalloway: I'll probably buy it when it comes out. I got enough stuff to read these days, I don't want to have a beta book as well ;) |
| 16:31 | knapr | Im noobish to a lot of CS-stuff. are there general parsing packages where you could define a few attributes to a parser and then it would construct one for you? |
| 16:33 | hiredman | danlarkin just pointed out http://github.com/joshua-choi/fnparse/tree/master |
| 16:33 | zakwilson | knapr: the short answer is yes. |
| 16:36 | Chouser | that looks nice |
| 16:36 | Chousuke | clojurebot: parser? |
| 16:36 | clojurebot | Pardon? |
| 16:36 | Chousuke | clojurebot: parser is http://github.com/joshua-choi/fnparse/tree/master |
| 16:36 | clojurebot | Ok. |
| 16:36 | durka | that makes sense... |
| 16:36 | durka | the major version of class files in java 1.5 is 49 |
| 16:42 | kotarak | clojurebot: #() |
| 16:42 | clojurebot | #() is not a replacement for fn |
| 16:43 | hiredman | clojurebot: monads? |
| 16:43 | clojurebot | I don't understand. |
| 16:43 | hiredman | clojurebot: monad? |
| 16:43 | clojurebot | Pardon? |
| 16:43 | hiredman | clojurebot: monads is http://www.bolour.com/papers/monads-through-pictures.html |
| 16:43 | clojurebot | Ok. |
| 16:43 | RSchulz | No one does. |
| 16:44 | RSchulz | (Understand monads, that is) |
| 16:44 | technomancy | kotarak: it's not a replacement for fn just because it has the implied parens? |
| 16:45 | kotarak | yes and because the doc says so. |
| 16:45 | danlarkin | technomancy: it's not a replacement because it has a subset of the functionality |
| 16:45 | kotarak | and it can't be nested. |
| 16:45 | Chousuke | RSchulz: After much meditation I finally feel like I understand them enough to see why they're useful. |
| 16:45 | RSchulz | Congratulations! |
| 16:45 | Chousuke | many of the details still escape me though. |
| 16:45 | RSchulz | I'm still working on it. |
| 16:47 | technomancy | I always felt like lambdas in other lisps were just a bit too verbose after being spoiled by Ruby's {} block syntax, but clojure's #() is even more succinct |
| 16:48 | Chousuke | arc has pretty nice shorthand too |
| 16:48 | Chousuke | that is, [] |
| 16:48 | Chousuke | with _ for the arg IIRC :/ |
| 16:49 | Chousuke | #() is just as nice though. saves the brackets for something even more useful :) |
| 16:56 | zakwilson | The Clojure version also allows for multiple args - Arc's bracket syntax does not. |
| 16:58 | Chousuke | zakwilson: IIRC it was expanded in anarki to support multiple args though |
| 17:01 | zakwilson | Chousuke: that may be. |
| 17:01 | zakwilson | I really wanted to like Arc, and I didn't want to like Clojure. |
| 17:02 | Chouser | I wanted to like Arc too. |
| 17:02 | hiredman | clojurebot: arc? |
| 17:02 | clojurebot | Huh? |
| 17:02 | Chouser | exactly |
| 17:03 | hiredman | clojurebot: Paul Graham? |
| 17:03 | clojurebot | Paul Graham is the creator of the other new lisp |
| 17:04 | zakwilson | Even if it had taken off like Clojure did, I don't like the feel of it as much. |
| 17:04 | ehird | ew, arc |
| 17:09 | technomancy | I think enough time has passed that "heh, arc" is an appropriate response |
| 17:09 | technomancy | or "heh; remember arc?" |
| 17:10 | ehird | arc is now an adjective |
| 17:10 | ehird | "Clojure is totally unarc." |
| 17:18 | pjb3 | So I was at a haskell meeting yesterday, saw something that was pretty cool, so I'm going to discuss it in here :) |
| 17:18 | pjb3 | In #haskell, and in the other room we were in, #novalang, they have a lambdabot |
| 17:18 | knapr | the whole idea of a 100-year language seems very self-masturbating and somewhat ridiculous |
| 17:19 | knapr | clojure wins heavily on being awesome now |
| 17:19 | knapr | best language + best platform |
| 17:19 | pjb3 | lambdabot is pretty cool, it does a bunch of stuff, but the best is that it can eval haskell expressions |
| 17:19 | hiredman | ,(println "lambdabot envy") |
| 17:19 | clojurebot | nil |
| 17:19 | clojurebot | lambdabot envy |
| 17:19 | hiredman | hmmmm |
| 17:19 | Raynes | #Scala has a lambdabot. |
| 17:19 | pjb3 | clojurebot: You can eval expressions? |
| 17:19 | clojurebot | No entiendo |
| 17:19 | pjb3 | ,(+ 2 3) |
| 17:19 | clojurebot | 5 |
| 17:20 | hiredman | lambdabot is in #freebsd too for some reason |
| 17:20 | pjb3 | Hey! |
| 17:20 | pjb3 | So, ok, I'll be the asshole, how do you deal with this: |
| 17:20 | gnuvince | pjb3: some might consider that a feature of lambdabot: access to IO is completely restricted |
| 17:20 | pjb3 | ,(System/exit 0) |
| 17:20 | clojurebot | java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.0) (NO_SOURCE_FILE:0) |
| 17:20 | pjb3 | AH! |
| 17:20 | pjb3 | very cool |
| 17:21 | technomancy | hiredman: did you have to do much to sandbox stuff like that, or are there built-in mechanisms for it? |
| 17:21 | pjb3 | That was part of the discussion, saying how haskell is awesome because as long as the expression gets evaled outside of a monad, you know it can't do anything malicious |
| 17:21 | hiredman | clojurebot: sandbox? |
| 17:21 | clojurebot | sandbox is http://calumleslie.blogspot.com/2008/06/simple-jvm-sandboxing.html |
| 17:21 | hiredman | is the main thing |
| 17:21 | technomancy | cool |
| 17:22 | hiredman | and I use tree-seq to weed out certain expressions |
| 17:22 | hiredman | ,(def a nil) |
| 17:22 | clojurebot | DENIED |
| 17:23 | pjb3 | What happens if I do (iterate inc 1) |
| 17:23 | hiredman | ,(interate inc 1) |
| 17:23 | clojurebot | java.lang.Exception: Unable to resolve symbol: interate in this context (NO_SOURCE_FILE:0) |
| 17:23 | hiredman | ,(iterate inc 1) |
| 17:23 | hiredman | only one way to find out |
| 17:24 | pjb3 | Hey, you did it, not me :) |
| 17:24 | pjb3 | clojurebot: still there? |
| 17:24 | hiredman | *sigh* |
| 17:24 | clojurebot | Gabh mo leithsc�al? |
| 17:24 | pjb3 | so don't ask clojurebot to eval an infinite lazy sequence |
| 17:24 | pjb3 | clojurebot: you're back? |
| 17:24 | clojurebot | I don't understand. |
| 17:24 | hiredman | anyway, after ten seconds the thread the expression is eval'ed in gets killed |
| 17:25 | pjb3 | ah |
| 17:26 | gnuvince | ,(.toUpper "j�r�me") |
| 17:26 | clojurebot | java.lang.IllegalArgumentException: No matching field found: toUpper for class java.lang.String (NO_SOURCE_FILE:0) |
| 17:26 | gnuvince | ,(.toUpperCase "j�r�me") |
| 17:26 | clojurebot | J�R�ME |
| 17:26 | technomancy | nice i10n, clojurebot! |
| 17:26 | technomancy | or is it i18n? |
| 17:27 | pjb3 | I think it;s i18n and l10n |
| 17:27 | hiredman | it's unicode |
| 17:27 | Chousuke | hmm |
| 17:28 | gnuvince | i18n is internationalization: translating an app |
| 17:28 | Chousuke | wonder what toupper does to something that has no such operation defined. |
| 17:28 | Chousuke | probably leaves it as is. |
| 17:28 | gnuvince | Chousuke: yes |
| 17:28 | gnuvince | ,(.toUpperCase "33") |
| 17:28 | clojurebot | 33 |
| 17:29 | Chousuke | ,(.toUpperCase "???") |
| 17:29 | clojurebot | ??? |
| 17:29 | clojurebot | Excuse me? |
| 17:29 | Chousuke | :D |
| 17:29 | Chousuke | it does not understand japanese. |
| 17:29 | gnuvince | Is there such a thing as uppercase in japanese? |
| 17:30 | Chousuke | nah. |
| 17:30 | hiredman | well, I was just mucking with the sandbox |
| 17:30 | Chousuke | hiredman: does the sandbox kill things launched in subthreads now too? |
| 17:30 | hiredman | and I broke something and fixed it, so you may have hit a broken window |
| 17:30 | hiredman | Chousuke: nope |
| 17:30 | hiredman | ,(throwsome and exception) |
| 17:30 | clojurebot | java.lang.Exception: Unable to resolve symbol: throwsome in this context |
| 17:30 | Chousuke | so I can still run an infinite loop in a new thread, right? |
| 17:30 | gnuvince | ,(.toUpperCase "? |
| 17:30 | clojurebot | Eval-in-box threw an exception:EOF while reading string |
| 17:30 | gnuvince | ,(.toUpperCase "?") |
| 17:30 | clojurebot | ? |
| 17:31 | Chousuke | cool. |
| 17:31 | hiredman | Chousuke: yes (sshhh) |
| 17:31 | danlarkin | to late! secret's out! bahhah |
| 17:31 | RSchulz | So why are we using this (fn ...) business when we could use a real lambda?? |
| 17:31 | hiredman | no ? key |
| 17:32 | hiredman | ,(let [x ?] x) |
| 17:32 | clojurebot | java.lang.Exception: Unable to resolve symbol: ? in this context |
| 17:32 | hiredman | ,(let [x '?] x) |
| 17:32 | clojurebot | ? |
| 17:32 | Chousuke | ,(clojure.core/def ? fn) |
| 17:32 | danlarkin | RSchulz: the fortress channel is thataway -------> |
| 17:32 | clojurebot | java.lang.Exception: No such var: clojure.core/def |
| 17:32 | Chousuke | oh. hmm |
| 17:32 | technomancy | RSchulz: I have Emacs render (fn as (? |
| 17:32 | RSchulz | Eh? |
| 17:32 | technomancy | it's pretty nice |
| 17:32 | technomancy | but rendering javascript's "function" as "?" saves a lot more chars |
| 17:32 | Chousuke | ,(eval '(def ? fn)) |
| 17:32 | clojurebot | DENIED |
| 17:33 | Chousuke | ,(eval '((symbol "def") ? fn)) |
| 17:33 | clojurebot | DENIED |
| 17:33 | Chousuke | gah |
| 17:33 | RSchulz | I sense the presence of Mac-o-philes... |
| 17:33 | danlarkin | I love "DENIED" |
| 17:33 | RSchulz | Anybody ever use MPW? |
| 17:33 | Chouser | RSchulz: in what way is fn not a "real lambda"? |
| 17:33 | RSchulz | I loved that thing. |
| 17:33 | RSchulz | I mean the letter. The glyph. |
| 17:33 | Chousuke | Chouser: it's not ? |
| 17:33 | technomancy | Chouser: I think he meant typographically |
| 17:33 | Chouser | oh! sorry. My IRC client renders all these as ? |
| 17:33 | hiredman | Chousuke: btw java.lang.Exception: Can't take value of a macro: #'clojure.core/fn (NO_SOURCE_FILE:1) |
| 17:34 | Chouser | I suppose I should try to fix that. |
| 17:34 | knapr | cant i just (alter a (fn [x] 100)) to set the ref a to 100? i get "no transaction running" |
| 17:34 | Chouser | knapr: wrap (dosync ...) around it |
| 17:34 | RSchulz | Then you can get the snowman glyph, too. |
| 17:34 | knapr | dosync |
| 17:34 | knapr | ah |
| 17:35 | Chousuke | ,(clojure.core/defmacro mydef [& rest] `(~(symbol "def") ~@rest)) |
| 17:35 | clojurebot | nil |
| 17:36 | Chousuke | ,(mydef x 1) |
| 17:36 | clojurebot | #'sandbox/x |
| 17:36 | Chousuke | hooray. |
| 17:36 | RSchulz | Security Schmecurity. |
| 17:37 | kotarak | maybe we need (ns #^{:read-only true} sandbox), now that we can have metadata with namespaces? |
| 17:37 | Chousuke | ,(clojure.core/defmacro ? [& rest] `(~(symbol "clojure.core" "fn") ~@rest)) |
| 17:37 | clojurebot | nil |
| 17:37 | Chousuke | there we go. |
| 17:37 | hiredman | oooo |
| 17:38 | technomancy | ,((? [x] (+ 2 x)) 8) |
| 17:38 | clojurebot | 10 |
| 17:38 | technomancy | clojurebot: high-five! |
| 17:38 | hiredman | :( |
| 17:38 | clojurebot | I don't understand. |
| 17:40 | Chousuke | I don't think defn and defmacro are that dangerous in the sandbox though. |
| 17:40 | Chousuke | or hmm |
| 17:40 | Chousuke | (mydef clojure.core/+ -) |
| 17:40 | Chousuke | ,(mydef clojure.core/+ -) |
| 17:40 | clojurebot | java.lang.Exception: Can't create defs outside of current ns |
| 17:41 | Chousuke | ,(clojure.core/require 'hiredman.clojurebot-core) |
| 17:41 | clojurebot | Pardon? |
| 17:41 | Chousuke | no access outside :( |
| 17:43 | hiredman | Chousuke: you can use def to make new names for things, and use that to get around checks for stuff that breaks Thread.stop |
| 17:44 | hiredman | specifically (catch ...) |
| 17:44 | Chousuke | well, yeah |
| 17:44 | Chousuke | the blacklist is rather ineffective. |
| 17:44 | Chousuke | but blacklists always are. |
| 17:44 | Chousuke | need to figure out something different. |
| 17:45 | Chousuke | wonder if it's possible to modify the clojure.core namespace so that those operations are nops |
| 17:45 | gnuvince | Maybe we could have a data structure into which we could wrap IO stuff to prevent bad thigns from happening. We could call those "Gonads" |
| 17:45 | hiredman | you can do stuff like (binding [defn nil] stuff) |
| 17:46 | hiredman | but all the cool stuffs are special forms |
| 17:46 | hiredman | so binding doesn't work |
| 17:46 | Chousuke | yeah |
| 17:46 | Chousuke | so it'd need reader hackery :/ |
| 17:47 | hiredman | or delving more into the jvm security stuff |
| 17:47 | Chousuke | I don't think it can help us anymore. |
| 17:47 | Chousuke | the default sandbox is a minimum permission sandbox :/ |
| 17:47 | hiredman | no |
| 17:47 | Chousuke | as far as I know anyway |
| 17:48 | hiredman | the default is the applet permission set |
| 17:49 | knapr | bah i must be stupid today, http://paste.pocoo.org/show/98383/, isnt there a very simple way to parse that? i included some of the file, it is a complete example |
| 17:49 | knapr | i mean completely representative |
| 17:49 | hiredman | clojurebot: sandbox |
| 17:49 | clojurebot | sandbox is http://calumleslie.blogspot.com/2008/06/simple-jvm-sandboxing.html |
| 18:09 | hiredman | ,(java.security.AccessController/getContext) |
| 18:09 | clojurebot | java.security.AccessControlContext@eed4d3 |
| 18:10 | hiredman | ,(bean (java.security.AccessController/getContext)) |
| 18:10 | clojurebot | {:class java.security.AccessControlContext, :domainCombiner nil} |
| 18:10 | hiredman | pfft |
| 18:10 | hiredman | useless |
| 18:13 | knapr | bah i must be stupid today, http://paste.pocoo.org/show/98383/, isnt there a very simple way to parse that? i included some of the file, it is a completely representative example. anyone could simplify it? |
| 18:13 | Chouser | what are you trying to produce? {1 (30878 ...), 10 (1952305 ..)} ? |
| 18:18 | Chouser | knapr: (second (reduce (fn [[k m] [_ n c]] (let [i (Integer. n), k (if c i k)] [k (if c (assoc m k []) (assoc m k (conj (m k) i)))])) [nil {}] (re-seq #"(\d+)(:)?\s+" x))) |
| 18:21 | hiredman | how evil is it to make an object whose hashCode method always returns 1? |
| 18:22 | technomancy | I'd rate that at a Mugabe-level evil. |
| 18:23 | danlarkin | that's pretty high up! |
| 18:23 | technomancy | less than Hitler-level or Cthulu-level, but worse than anyone should have to deal with on a regular basis. |
| 18:26 | hiredman | ugh |
| 18:30 | powr-toc | Hi all, does Stuart Halloway frequent here often? :-) |
| 18:30 | durka | yes |
| 18:30 | durka | not at present apparently, but his username is surprisingly stuarthalloway |
| 18:32 | powr-toc | durka: ok... was just wondering if he was in... A clojure example on his blog doesn't appear to work with the latest version... I've got a trivial fix for him, but his blog comments are closed. |
| 18:35 | knapr | clojurebot: is_rhickey_a_minor_god? |
| 18:35 | clojurebot | Excuse me? |
| 18:35 | knapr | clojurebot: is_rhickey_is_a_minor_god? is yes |
| 18:35 | clojurebot | Ik begrijp |
| 18:35 | knapr | clojurebot: is_rhickey_a_minor_god? |
| 18:35 | clojurebot | No entiendo |
| 18:36 | knapr | why doesnt that work? |
| 18:36 | durka | clojurebot: rhickey? |
| 18:36 | clojurebot | he works hard so you don't have to |
| 18:36 | durka | clojurebot: is_rhickey_a_minor_god is yes |
| 18:36 | clojurebot | Ik begrijp |
| 18:37 | durka | clojurebot: is_rhickey_a_minor_god? |
| 18:37 | clojurebot | is_rhickey_a_minor_god is yes |
| 18:38 | dreish | ,'#=(eval (def x-ploit "myvalueforx")) |
| 18:38 | billc1 | Is yes |
| 18:38 | dreish | ,#=(eval 'x) |
| 18:39 | dreish | Hmm. I wonder how they prevent that. |
| 18:39 | dreish | ,(+ 1 2) |
| 18:39 | clojurebot | 3 |
| 18:39 | hiredman | clojurebot: where are you? |
| 18:39 | clojurebot | http://github.com/hiredman/clojurebot/tree/master |
| 18:39 | dreish | Ah, you're here. |
| 18:40 | dreish | So, did you think of that one already, or did I screw something up? |
| 18:40 | hiredman | ,(identity #=(eval 'x)) |
| 18:40 | clojurebot | 1 |
| 18:40 | dreish | I read the code earlier today and couldn't see anything ... |
| 18:40 | hiredman | ,(identity #=(eval x)) |
| 18:40 | clojurebot | Eval-in-box threw an exception:java.lang.Exception: Unable to resolve symbol: x in this context |
| 18:40 | hiredman | dreish: magic I guess |
| 18:41 | hiredman | it throws away anything that does not start with a ( |
| 18:41 | dreish | Oh, duh. |
| 18:41 | hiredman | which I explicit coded in, then removed, but it still does it for some reason |
| 18:41 | dreish | ,(identity #=(eval (def x-test "test2"))) |
| 18:41 | clojurebot | #'clojure.core/x-test |
| 18:41 | dreish | Hmm. |
| 18:41 | hiredman | :( |
| 18:41 | dreish | So it does have that problem. |
| 18:41 | hiredman | yeah |
| 18:41 | dreish | I think the fix is easy, though: just scan the string for "#=" |
| 18:42 | dreish | Not much else you can do, unless you want to implement a special reader. |
| 18:42 | hiredman | I really wish I could make sense of the jvm security stuff |
| 18:48 | dreish | It might be worth having a LispReader.readWithoutEval(). |
| 18:49 | dreish | ,(identity #=(eval (def plea-to-rhickey "Can we have a LispReader.readWithoutEval()?"))) |
| 18:49 | clojurebot | #'clojure.core/plea-to-rhickey |
| 18:50 | rhickey | dreish: this for security? |
| 18:50 | dreish | Yeah. Is it a lost cause? |
| 18:50 | rhickey | not at all - planned |
| 18:50 | rhickey | necessary |
| 18:50 | dreish | Awesome, thanks. |
| 18:50 | rhickey | will be some sort of flag |
| 18:50 | dreish | Right. |
| 18:51 | danlarkin | oh that will open up a lot of neat possibilities |
| 18:52 | rhickey | dreish: might as well call it *read-eval* a la CL, want to make an enhancement request in the issue system? |
| 18:52 | rhickey | http://code.google.com/p/clojure/issues/list |
| 18:52 | dreish | rhickey: Okay, but it'll mean learning two things in one day. |
| 18:52 | knapr | how an for what do I use with-open? |
| 18:53 | hiredman | rhickey: I dunno how plausable this would be, because catch is special, but it would be nice if I could thread local bind catch to nil somehow |
| 18:53 | hiredman | knapr: anything with a .close method |
| 18:54 | hiredman | (with-open [file (java.io.FileWriter "foo")] (.write file "bar")) |
| 18:54 | knapr | i see now, it worked |
| 19:00 | dreish | Would *read-eval* be binding-able? |
| 19:01 | dreish | I guess it would have to be. |
| 19:16 | ole3 | hello |
| 19:16 | ole3 | can i ask some questions about packages |
| 19:16 | ole3 | ok, i simply ask |
| 19:17 | rhickey | dreish: yes, that's how it would work - defaults to true |
| 19:17 | ole3 | how do i define a package, or where can i get info about how to do it |
| 19:17 | Chousuke | clojurebot: namespace? |
| 19:17 | clojurebot | Huh? |
| 19:17 | Chousuke | hm |
| 19:18 | Chousuke | ole3: anyway: you need to define a namespace, using the (ns) macro |
| 19:18 | dreish | clojure.contrib has several examples. |
| 19:18 | ole3 | ok, i look it up |
| 19:18 | Chousuke | ole3: the name of a namespace must match the layout of files in a certain way similar to java. |
| 19:19 | Chousuke | examples are best I suppose. :) |
| 19:19 | ole3 | thank you, i found the ns macro |
| 19:20 | ole3 | i got no idea about the java files layout |
| 19:23 | Chousuke | ole3: well, if you have ~/mycode/ in your classpath, and want a namespace net.ole.myprog, the ns declaration must be in the file ~/mycode/net/ole/myprog.clj |
| 19:23 | ole3 | Chousuke: that means i have a directory structure like /src/main/resources etc. ? |
| 19:23 | powr-toc | ole3: I think Chousuke is referring to how in Java classes are organised into packages e.g. foo.bar.BazClass and tend to be stored in a matching directory tree e.g. /foo/bar/BazClass.(java|class) |
| 19:24 | ole3 | ok, thank you |
| 19:25 | technomancy | my co-worker jokes about how he gets paid by the directory for writing Java |
| 19:25 | Chousuke | ole3: there's one catch with the naming though: if you have dashes ("-") in the namespace name, the corresponding file must have an underscore, due to a java limitation :/ |
| 19:25 | walters | i wonder if that one is fixed in jdk7 |
| 19:25 | technomancy | Chousuke: that's weird; I haven't run into that problem |
| 19:25 | walters | jrose did a blog about symbolic freedom |
| 19:26 | technomancy | I have a test-models.clj file that works fine |
| 19:26 | technomancy | oh... nm; the namespace doesn't match up for that and I load it only via slime |
| 19:27 | ole3 | ok, i have a file named project.clj, which includes a ns definition that says (:require foo bar) |
| 19:28 | walters | http://blogs.sun.com/jrose/entry/symbolic_freedom_in_the_vm |
| 19:28 | ole3 | means that that i need to have a dir named foo with a file named bar.clj ? |
| 19:28 | hiredman | (doc require) |
| 19:28 | clojurebot | Loads libs, skipping any that are already loaded. Each argument is either a libspec that identifies a lib, a prefix list that identifies multiple libs whose names share a common prefix, or a flag that modifies how all the identified libs are loaded. Use :require in the ns macro in preference to calling this directly. Libs A 'lib' is a named set of resources in classpath whose contents define a library of |
| 19:29 | hiredman | ole3: generally . is used as a directory seperator |
| 19:30 | hiredman | I think (:require foo bar) would require foo.clj and bar.clj, but that would not work because namespaces need at least two segments |
| 19:30 | hiredman | so (:require foo.bar foo.baz) |
| 19:31 | hiredman | which would need foo/bar.clj and foo/baz.clj to be in the classpath |
| 19:31 | ole3 | ok, so namespace = path + filename |
| 19:31 | ole3 | thank you |
| 19:31 | ole3 | i will try |
| 19:33 | ole3 | ah, i find the doc |
| 19:34 | ole3 | last question: is there a way to perform an operation after a lib has been loaded? |
| 19:34 | blbrown | does anyone have tips for this question. http://groups.google.com/group/clojure/browse_thread/thread/88d7f7b706ebf62f?hl=en |
| 19:34 | ole3 | like cl asdf:oos :after? |
| 19:37 | ole3 | hiredman: thanks for your help, sometimes i can't thing straight |
| 19:37 | ole3 | good night |
| 19:44 | technomancy | but I guess html generation is pretty much the same in any lisp. =) |
| 19:44 | technomancy | just used to some really ugly stuff in Ruby |
| 19:48 | Nafai | technomancy: Is it basically just some sexp representation of the html? |
| 19:48 | technomancy | yeah, in vectors |
| 19:48 | Nafai | Cool |
| 19:48 | technomancy | at the bottom: http://github.com/weavejester/compojure/tree/master |
| 19:49 | Nafai | Nice |
| 19:56 | Chouser | blbrown: It'll be a lot of work to allow a config.clj to set some things and not others if you're trying to block malicious intent. |
| 19:56 | Chouser | but if you want to have it default to 'def'ing vars in a particular namespace (like my-app.config), that shouldn't be too hard. |
| 19:57 | blbrown | Chouser, that is goal. I don't like java properties files, I wanted something a little bit more customizable |
| 19:59 | Chouser | (binding [*ns* (create-ns 'my-app.config)] (load-file "/tmp/config.clj")) |
| 20:00 | amagee | hey if i have a list, say '(\a \b \c), how can i convert it to a string "abc"? |
| 20:00 | Chousuke | I think (str yourlist) should do |
| 20:01 | amagee | no that gives "(\\a \\b \\c)" |
| 20:01 | Chousuke | ,(apply str '(\a \b \c)) |
| 20:01 | clojurebot | abc |
| 20:01 | Chousuke | right, apply to the rescue |
| 20:01 | amagee | ah cool |
| 20:02 | amagee | how come that is different? |
| 20:02 | Chouser | ,(str \a \b \c) |
| 20:02 | clojurebot | abc |
| 20:02 | Chousuke | apply expands the seq(s) to be the arglist of the function |
| 20:02 | amagee | ah i see |
| 20:02 | amagee | thanks |
| 20:03 | ole3 | is there an argument limit to apply? |
| 20:03 | Chousuke | I don't know. |
| 20:03 | Chouser | ole3: no |
| 20:03 | ole3 | wow |
| 20:03 | Chouser | infinite seqs are ok |
| 20:04 | Chousuke | ... how does that work? |
| 20:04 | ole3 | infinite ...? |
| 20:04 | Chousuke | is the function required to treat its argument as infinite? |
| 20:04 | Chousuke | possibly infinite* |
| 20:04 | Chousuke | I think I might be asking stupid questions. |
| 20:05 | Chouser | ,(apply (fn [& args] (take 3 args)) 1 (iterate inc 10)) |
| 20:05 | clojurebot | (1 10 11) |
| 20:05 | ole3 | ,(* 123 123) |
| 20:05 | clojurebot | 15129 |
| 20:05 | ole3 | ah |
| 20:05 | Chousuke | ole3: infinite seqs like (iterate inc 1) |
| 20:06 | Chouser | Chousuke: sorta -- you'd have to have a & rest part to take advantage of it. |
| 20:06 | Chouser | kinda hard to provide an infinite number of named args. :-) |
| 20:06 | Chousuke | heh |
| 20:06 | ole3 | so i do not evaluate the whole seq |
| 20:06 | Chousuke | wasn't there some limit to named args though? |
| 20:06 | Chousuke | 20 or something. |
| 20:07 | ole3 | in cl, yes, in bash, yes, in clojure, who knows |
| 20:07 | Chousuke | more than enough in any case |
| 20:07 | Chousuke | if you have a function that takes even 10 args, it's getting too big :P |
| 20:07 | Chousuke | 10 named args that is. |
| 20:08 | ole3 | and & body args? |
| 20:08 | ole3 | do they not count as named? |
| 20:08 | Chousuke | I think so. |
| 20:09 | Chousuke | doesn't really matter to me. |
| 20:09 | Chouser | java.lang.Exception: Can't specify more than 20 params |
| 20:09 | Chousuke | 20 was the number of overloads rhickey bothered to write I guess :) |
| 20:10 | ole3 | :) |
| 20:14 | ole3 | i did start to write a little toy webserver to learn clojure and java, if someone is interested to join, please contact me oruppert@googlemail.com, project page http://code.google.com/p/clojure-web/, thanks |
| 20:15 | ole3 | good night |
| 20:23 | knapr | what time-complexity does "select grade from reviews where movieid = 12 and customerid = 100" have? |
| 20:23 | knapr | if the primary key is over customerid and movieid |
| 20:24 | Chousuke | rather fast. |
| 20:24 | Chousuke | the exact complexity depends on the DBMS I guess. |
| 20:26 | danlarkin | knapr: what does time-complexity mean? |
| 20:27 | Chousuke | in any case, a query like that is not something you should worry about, on any system :) |
| 20:32 | knapr | yes it is already slow for 500 movies and 300K users |
| 20:32 | knapr | and in the end i have 17770 movies and 500K users... |
| 20:40 | vogelrn | select should be linear |
| 20:41 | vogelrn | given a large enough N, however, that doesn't mean it will be fast :P |
| 20:41 | Chousuke | you're using something that doesn't automatically index by primary keys? :/ |
| 20:58 | falconair | When I instantiate an object from a third party jar like such: (SGRectangle.) (or (new SGRectangle)), I get the following result: |
| 20:58 | falconair | #<SGRectangle null com.sun.scenario.scenegraph.SGRectangle@b76fa> |
| 20:59 | falconair | note the "null" ... when I try to use this object, I get a null pointer error...object is clearly found by clojre, howcome instantiation returns null? |
| 20:59 | falconair | In java I can instantiate it as "new SGRectangle()" and it works fine |
| 21:00 | MarkVolkmann | What does this error message mean? |
| 21:00 | MarkVolkmann | java.lang.IllegalStateException: Var my-function-name is unbound |
| 21:01 | Chousuke | MarkVolkmann: you have no function named my-function-name :/ |
| 21:01 | Chousuke | MarkVolkmann: that is, someplace where you're trying to use it. |
| 21:02 | MarkVolkmann | I do have a function with that name before any calls to it. However, it's a function that takes either 1 or 4 parameters. |
| 21:02 | MarkVolkmann | The 1 parameter part calls the part that takes 4. |
| 21:02 | MarkVolkmann | I verified that all calls to it pass either 1 or 4 arguments. |
| 21:03 | arbscht | can you paste a snippet somewhere? |
| 21:05 | Chousuke | MarkVolkmann: has the defn actually been evaled? |
| 21:05 | Chousuke | MarkVolkmann: for example, if you're doing this in emacs or something. |
| 21:05 | MarkVolkmann | I'm running it as a script from a Terminal window. |
| 21:06 | MarkVolkmann | I'll try to simplify things to isolate the problem. Thanks for the tips! |
| 21:08 | dreish | ,(time (count (range 1000000))) |
| 21:08 | clojurebot | 1000000 |
| 21:08 | clojurebot | "Elapsed time: 156.434 msecs" |
| 21:08 | dreish | ,(time (count (range 999999 -1 -1))) |
| 21:08 | clojurebot | 1000000 |
| 21:08 | clojurebot | "Elapsed time: 6667.267 msecs" |
| 21:08 | dreish | Isn't that odd? |
| 21:09 | Chousuke | somewhat. |
| 21:09 | dreish | I'd take longer to count backwards too, but I'm not a computer. |
| 21:10 | dreish | Oh, I see. With 1 arg or 2, it uses a clojure.lang.Range, and with 3 args it calls iterate, which uses lazy-cons. |
| 21:10 | falconair | any idea why my instantiation is returning a null? |
| 21:13 | arohner | dreish: so then does (time (count (range 1 1000000 1))) take the same amount of time? |
| 21:13 | dreish | Same as the -1, yes. |
| 21:14 | Chousuke | sounds like Range should be extended to support a step /: |
| 21:14 | dreish | Maybe someday. |
| 21:15 | Chousuke | did you already post an issue? |
| 21:15 | dreish | I think it might also be nice to have ASeq implement an nthRest() method, to speed up nth on seqs on randomly-accessible data structures. |
| 21:16 | dreish | I posted one issue today, yes. :) |
| 21:16 | Chousuke | sounds like another thing worthy of an issue |
| 21:16 | dreish | I don't really need it myself. |
| 21:17 | rhickey | issues is not a wish list |
| 21:17 | Chousuke | they're easy to discard, but as long as you post them there's a single place for people to look for ideas and such :) |
| 21:17 | Chousuke | hm |
| 21:17 | Chousuke | then there should be a wish list :/ |
| 21:17 | dreish | Where's the wish list? |
| 21:17 | rhickey | there's a user wiki |
| 21:25 | yangsx | hi, do you agree it's a but that (merge-with '({:a 1, :b 2})) returns nil instead of the single map? |
| 21:25 | yangsx | bug |
| 21:34 | dreish | No, because the first arg is supposed to be a combining function. |
| 21:35 | falconair | ...so...any one have a clue what this message means: #<SGRectangle null com.sun.scenario.scenegraph.SGRectangle@b76fa> ? it seems to find the object, but null is returned |
| 21:40 | Chouser | you're not getting a null, you're getting a SGRectangle instance with id (or at memory location?) b76fa |
| 21:40 | Chouser | The 'null' is most like a datamember, but I'm not quite sure yet. |
| 21:40 | Chouser | most likely |
| 21:43 | falconair | hm...i guess if it actuall was null, clojure would call it "nil" correct? |
| 21:51 | yangsx | dreish: I know the first arg is to be a function, but (apply merge-with list-of-maps) works exactly as I'd expect: add up the values of same keys in all maps, like magic |
| 21:51 | yangsx | and a map is a function |
| 21:52 | Chouser | falconair: yes |
| 21:53 | yangsx | so I guess if the test (when (some identity maps) ...) can be changed to just return the first arg if it's a map |
| 21:53 | yangsx | if the test fails |
| 21:53 | Chouser | ,(apply merge-with '({:a 1} {:b 2})) |
| 21:54 | clojurebot | {:b 2} |
| 21:54 | Chouser | perhaps you want just 'merge'? |
| 21:54 | cmvkk | something interesting: when I run 'count' on a large enough seq it will generate a StackOverflowError...is this known/normal? |
| 21:55 | Chouser | cmvkk: what kind of seq were you trying it on? |
| 21:56 | cmvkk | hard to say...when i print it it looks like a list of maps but it's supposed to be a vector? |
| 21:56 | Chouser | falconair: try running (.toString foo) where foo is your SGRectangle object. |
| 21:56 | cmvkk | if you run cons on a vector will the result still be a vector? |
| 21:57 | Chouser | cmvkk: the function(s) that are producing the seq may be overflowing the stack. |
| 21:57 | Chouser | cmvkk: no |
| 21:57 | Chouser | cmvkk: cons operates on seqs, so you'll get back a seq |
| 21:57 | cmvkk | it's a list then. anyway i can print the seq out (although it goes beyond my scroll capabilities) |
| 21:57 | yangsx | Chouser: you're right, I didn't noticed merge-with discard key-value pairs in the first map, but work correctly with the rest maps |
| 21:57 | cmvkk | but trying to (count) it gives a stack overflow. |
| 21:58 | Chouser | yangsx: it doesn't discard the first arg, it uses it to resolve conflicts in keys of the following maps. |
| 21:58 | yangsx | ,(apply merge-with '({:a 1} {:b 2} {:a 2 :b1})) |
| 21:58 | clojurebot | Eval-in-box threw an exception:No value supplied for key: :b1 |
| 21:58 | Chouser | cmvkk: when you print it, it prints to the end of the seq? |
| 21:58 | cmvkk | if i run (take ## foo) where ## is some number much larger than the size of the seq, well, that I can count. |
| 21:58 | cmvkk | yes, it prints to the end of the seq. |
| 21:58 | yangsx | ,(apply merge-with '({:a 1} {:b 2} {:a 2 :b 1})) |
| 21:58 | clojurebot | {:a 2, :b 1} |
| 22:00 | Chouser | cmvkk: can you paste the code that errors out? |
| 22:00 | Chouser | lisppaste8: url |
| 22:00 | lisppaste8 | To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste. |
| 22:00 | cmvkk | not feasable with the current code, which is 400 lines long or so and requires jumping through some hoops...let me see if i can't come up with a small test case first. |
| 22:01 | Chouser | cmvkk: great |
| 22:02 | Chouser | cmvkk: It's not more than a million items? |
| 22:02 | Chouser | ,(count (map identity (range 1000000))) |
| 22:03 | clojurebot | 1000000 |
| 22:03 | cmvkk | the problem with using range is that it's a lazy seq, right? |
| 22:03 | cmvkk | my example case is one line long, can i just write it in here? |
| 22:03 | Chouser | cmvkk: if long is < 256 or so chars |
| 22:04 | cmvkk | (count (loop [c 0 x [0]] (if (< c 4601) (recur (inc c) (cons 0 x)) x))) |
| 22:04 | Chouser | cmvkk: laziness isn't the issue. range by itself knows its length and would return instantly. by running it through 'map' it loses knowledge of its length, and 'count' has to walk it. |
| 22:04 | cmvkk | hmm, okay. |
| 22:05 | cmvkk | anyway, my code above only generates a list that's 4601 elements long... |
| 22:05 | cmvkk | but it errors for me... it might take a larger number for someone else? |
| 22:05 | cmvkk | note that if you do (count (take 10000 (loop ...))) that works |
| 22:06 | Chouser | cmvkk: I'm reproducting the error here. interesting. |
| 22:06 | falconair | Chouser: running toString returns "null com.sun.scenario.scenegraph.SGRectangle@c26ede" ... so I think I'm not getting a null object back, the prob is somewhere else |
| 22:06 | falconair | thanks! |
| 22:07 | Chouser | falconair: you're welcome. |
| 22:07 | Chouser | cmvkk: Cons.count() is recursive |
| 22:09 | Chouser | that's the problem. |
| 22:09 | cmvkk | i see. |
| 22:12 | Chouser | I'm not sure how best to solve it. |
| 22:13 | cmvkk | other than changing how count works? |
| 22:13 | cmvkk | as far as a workaround goes, this doesn't affect anything i'm doing anyway, i just thought it was interesting |
| 22:14 | Chouser | cmvkk: it is interesting, thanks. |
| 22:16 | Chouser | oh! Range objects do not know their length |
| 22:19 | Chouser | but PersistentList objects do. |
| 22:22 | gnuvince | Ranges don't know their lengths? |
| 22:22 | gnuvince | Can't you call count on them? |
| 22:23 | Chouser | (count (range n)) is O(n) not O(1) |
| 22:23 | gnuvince | ah |
| 22:23 | gnuvince | that's weird... |
| 22:23 | cmvkk | yeah, that's definitely the case |
| 22:23 | Chouser | heh, yeah. |
| 22:23 | cmvkk | but it won't overflow the stack either |
| 22:23 | Chouser | but this works fine: (count (reduce #(cons %2 %) '(0) (range 4601))) |
| 22:23 | gnuvince | It seems it would be a pretty simple arithmetic thing to find it with the start, end and step |
| 22:24 | cmvkk | what, what's the difference between that and my example? |
| 22:24 | Chouser | '(0) vs [0] |
| 22:25 | Chouser | in the former, it's cons'ing onto a PersistentList, creating new PersistentLists for which 'count' is O(1) |
| 22:26 | Chouser | in the latter, it's cons'ing on (seq [0]), so you're getting back Cons objects, for which 'count' is O(n) and blows the stack |
| 22:27 | cmvkk | I see. on a semi-related note, what i was basically doing was creating stack behavior, and using 'cons', 'first' and 'rest' to accomplish this, starting with an empty vector []. is it better to do it some other way? |
| 22:28 | Chouser | cmvkk: start with an empty list () |
| 22:28 | cmvkk | okay |
| 22:39 | Chouser | (count (cons :a big-vector)) ; nearly constant time |
| 22:40 | Chouser | Cons.count() being recursive allows it to go from linear (for counting the Cons chain) to constant time for the vector seq. |
| 22:43 | cmvkk | but the price is that you have to handle conses in a different way than for a list? |
| 22:45 | Chouser | well, each class can provide it's own class() method |
| 22:45 | Chouser | count() I mean |
| 22:46 | Chouser | Cons delegates to the "rest" object, whatever it is. |
| 22:47 | arohner | I have a CA. how do I get commit access to contrib? |
| 22:47 | arohner | (or do I?) |
| 22:48 | Chouser | arohner: I guess you ask rhickey_ -- he's the only one who can grant commit privs, I think. |
| 22:51 | arohner | Chouser: thanks |
| 22:59 | jacky | what is the best source to see some idiomatic clojure code? Most of the real life code that I have seen seems to be rehash of java in clojure |
| 23:01 | Chouser | jacky: there's a book on the way -- the examples are available for free |
| 23:01 | jacky | chouser: do you mean stuart H's book? |
| 23:01 | Chouser | jacky: clojure-contrib is good, and the projecteuler wiki isn't bad. |
| 23:01 | Chouser | jacky: yes |
| 23:02 | jacky | projecteuler has clojure code? |
| 23:02 | Chouser | no, there's a wiki of clojure solutions to their problems. |
| 23:02 | Chouser | clojurebot: project euloer |
| 23:02 | clojurebot | excusez-moi |
| 23:02 | Chouser | clojurebot: project euler |
| 23:02 | clojurebot | project euler is http://ProjectEuler.net |
| 23:02 | Chouser | clojurebot: projecteuler |
| 23:02 | clojurebot | Pardon? |
| 23:02 | Chouser | hmph. |
| 23:03 | Chouser | jacky: http://clojure-euler.wikispaces.com/ |
| 23:03 | jacky | Cool. The best one that I have seen so far is the context free art thingy |
| 23:05 | jacky | chouser: clojure-euler looks cool. Thanks. |
| 23:06 | Chouser | jacky: If you have the time, I'd recommend trying to solve them yourself, then checking your work against the wiki |
| 23:06 | Chouser | it's more fun that way 'round. |
| 23:07 | jacky | sure, that is what I plan to do.. I basically want to know the best way to express ideas in clojure |
| 23:08 | Chouser | sure. I have no better advice than practice, and projecteuler is good for that |
| 23:17 | cmvkk | is there a way to use 'apply' with a static class method? |
| 23:17 | cmvkk | i.e. (apply java.lang.Math/hypot some-list) |
| 23:18 | cmvkk | oh wait, i guess i can just wrap it in an fn |
| 23:18 | Chouser | not directly. |
| 23:18 | Chouser | right |
| 23:18 | Chouser | (apply #(Math/hypot %1 %2) some-list) |
| 23:21 | cmvkk | how come you can't use numbers to index into a list? |
| 23:22 | cmvkk | i.e. (get '(1 2) 0) |
| 23:22 | cmvkk | i'm full of questions this evening |
| 23:22 | Chouser | because 'get' promises O(1), and lists can't deliver |
| 23:22 | cmvkk | I see. |
| 23:22 | Chouser | you can use 'nth' |
| 23:22 | cmvkk | aha. |
| 23:29 | Chouser | cmvkk: http://groups.google.com/group/clojure/msg/a24abca88ae1af1e |
| 23:30 | cmvkk | ooh, neat. |
| 23:30 | Chouser | :-) |
| 23:36 | Chouser | and thus I've avoided for another evening doing what I ought to do, by doing Clojure instead. |
| 23:36 | Chouser | g'night, all. |
| 23:37 | cmvkk | goodnight! |
| 23:44 | arohner | do ref validators take the ref, or the deref'd new state? |
| 23:45 | cmvkk | i believe they take the state. |
| 23:45 | cmvkk | "will be passed the intended new state on any state change" from the api |
| 23:46 | arohner | that's what I thought, but it's blowing up for me, saying 'invalid state', and I can't figure out why |
| 23:46 | arohner | passing the @ref to the validator fn manually works fine |
| 23:48 | arohner | nm, returning nil is not acceptable |