2008-10-08
| 02:41 | schlarf | (defmacro assoc! [map_ k v] |
| 02:41 | schlarf | `(def ~map_ (assoc ~map_ ~k ~v))) |
| 02:41 | schlarf | that cant be done woth a defn right? |
| 02:41 | schlarf | and oh yeah, ima sinner babY! |
| 02:41 | Chouser | yeah it can, and you do sin. |
| 02:41 | Chouser | :-) |
| 02:42 | Chouser | oh, sorry, no you're right. |
| 02:42 | Chouser | because you're passing in the name, I think it has to be a macro. |
| 02:43 | Chouser | if you just used a ref instead, you could do it in a defn and it would play nice with STM and threads. |
| 02:44 | schlarf | ok ill look into refs. and anywa, im not planning to really use assoc!, just assoc... |
| 03:13 | schlarf | clojure/ <- why is thta coming into my macro? |
| 03:23 | hoeck | schlarf: to prevent aliasing |
| 03:24 | hoeck | to avoid it, use ~'foo in backquotes |
| 04:12 | lisppaste8 | askl pasted "compress withr educe" at http://paste.lisp.org/display/68148 |
| 04:12 | schlarf | ^^ i posted a compress-function |
| 04:13 | schlarf | it it working using cond and recur but i want to use reduce |
| 04:13 | schlarf | but i cant get it to work |
| 04:45 | lisppaste8 | yangsx annotated #68148 with "reduce is functional" at http://paste.lisp.org/display/68148#1 |
| 04:47 | Lau_of_DK | Im making a Shortcut in Windows to launch a clojure script, but it requires a full path to start up properly, do you guys know of a %currendir% variable or something along those lines? |
| 04:49 | lisppaste8 | hoeck annotated #68148 with "filter or reduce" at http://paste.lisp.org/display/68148#2 |
| 04:50 | lisppaste8 | tWip pasted "Latest Slime + swank-clojure does not start" at http://paste.lisp.org/display/68150 |
| 04:51 | tWip | anyone experienced the same? clojure complains about symbol *1 in swank core.clj |
| 04:57 | yangsx | tWip: slime's using iso-latin-1-unix; you can try to use utf-8-unix |
| 05:00 | tWip | I'll try that. |
| 05:09 | hoeck | Lau_of_DK: `.' doesn't work? |
| 05:10 | Lau_of_DK | Unfortunately not |
| 05:10 | Lau_of_DK | %windir% works, but is not applicable :) |
| 05:14 | hoeck | Lau_of_DK: %cd% ? |
| 05:27 | Lau_of_DK | hoeck, %cd% works perfect, thanks alot |
| 06:00 | schlarf | is there no round function? |
| 06:01 | tWip | you can always use Math.round from Java |
| 06:04 | schlarf | i can import math but not round |
| 06:04 | schlarf | (import Math) |
| 06:04 | schlarf | (.Math.round 5.0) |
| 06:04 | schlarf | is the use right? |
| 06:04 | schlarf | not working... |
| 06:05 | tWip | it's in java.lang so no need to import |
| 06:05 | tWip | just (. Math (round 5.0)) |
| 06:15 | hoeck | schlarf: its even a static method, so (Math/round 5.0) works too |
| 06:15 | tWip | oh I didn't know about that syntax |
| 06:16 | tWip | is that new? or newish |
| 06:20 | hoeck | rather newsish, maybe about 2-3 months old |
| 06:20 | tWip | ok |
| 07:44 | schlarf | slurp |
| 07:44 | schlarf | nice to see a language deisgner with a sense of humour |
| 07:50 | cemerick | rhickey: do fns capture all lexical bindings, or does it capture only those bindings that are used in the fn body? (I ask knowing that the latter might be pretty difficult in a dynamic setting....) |
| 07:53 | rhickey | cemerick: not exactly sure what you're getting at, can only capture those used |
| 07:54 | rhickey | is there a specific scenario you're thinking of? |
| 07:55 | cemerick | rhickey: My brain may not yet be working right. However, given (let [foo (some-really-large-obj)] #(blah (:key foo))), it would be nice to know that the returned fn isn't holding a reference to foo. |
| 07:56 | rhickey | how could it not? |
| 07:56 | rhickey | the returned fn calls :key on it every time it is called |
| 07:57 | cemerick | rhickey: right, see, I'm not thinking straight yet; I meant something more like (let [foo (large-obj) val (:key foo)] #(blah val)) |
| 07:58 | rhickey | ok, in that case no reference to foo in the closure |
| 07:58 | cemerick | rhickey: OK, good to know. Thanks for your patience :-) |
| 07:58 | rhickey | np |
| 08:28 | gnuvince | Good morning |
| 08:28 | tWip | morning? surely not... it's time to go home soon. |
| 08:30 | H4ns | tWip: psst, he is in another time zone. |
| 08:31 | tWip | yes, I got that... just trying to make some (admittedly poor) humor |
| 08:31 | cemerick | nonsense, it's 8:28 *everywhere* :-) |
| 08:32 | H4ns | tWip: yeah, my remark was not really much better, apologies :) |
| 08:32 | cemerick | 45 people in #clojure -- anyone have any ideas on where the influx is coming from? |
| 08:32 | cemerick | I suppose the steady trickle of clojure posts on proggit don't hurt. |
| 08:32 | rhickey | cemerick: we hit 63+ yesterday |
| 08:32 | blackdog | i think the boston meeting did it |
| 08:32 | cemerick | yeah, I saw that -- good to see it |
| 08:33 | schlarf | ceemrick: all my bots |
| 08:33 | cemerick | ah, so other lisp ex-pats, then? |
| 08:33 | rhickey | blackdog: yes, seemed to have connected with a good pool of people through that |
| 08:33 | H4ns | cemerick: i got two passports |
| 08:34 | rhickey | we're about to lap 600 on the group |
| 08:34 | tWip | I think Clojure really brings something to lispers in the JVM enterprise land |
| 08:34 | blackdog | also, the jvm summit got quite a few writeups on various influential blogs, and there were only good things to say |
| 08:34 | tWip | I was using jscheme before clojure, which was quite nice also, but nowhere near as good performance |
| 08:34 | cemerick | rhickey: BTW, I made some contact with business-side people at Sun last week, talked them up on Clojure. Certainly piqued their interest. |
| 08:35 | gnuvince | rhickey: do you use Clojure for your work? |
| 08:35 | rhickey | cemerick: cool |
| 08:35 | rhickey | gnuvince: yes |
| 08:36 | gnuvince | That's good |
| 08:41 | aking | hi donald - yup |
| 08:41 | aking | oppss |
| 08:54 | schlarf | how do i get parenthesis around < x 10: (list 'fn '[x] (hd xs) 'x (nth xs 1)) |
| 08:54 | schlarf | (def xs '(< 10)) |
| 08:56 | rhickey | schlarf: what are you trying to do? |
| 08:56 | schlarf | lol i posted it a few days ago but forgot |
| 08:57 | rhickey | #(< % 10) |
| 08:57 | rhickey | ? |
| 08:57 | schlarf | yes |
| 08:57 | schlarf | where is the definition of #? its a macro right? in boot.clj? |
| 08:58 | rhickey | #() is reader syntax |
| 08:58 | schlarf | ok |
| 09:01 | schlarf | is clojure lazy throughout? |
| 09:01 | schlarf | everything is lazy? |
| 09:01 | rhickey | schlarf: no |
| 09:01 | schlarf | for some reason i dont get the same difficulty predicitng stuff as in haskell |
| 09:01 | schlarf | oh ok |
| 09:01 | rhickey | Clojure is strict, most of the sequence functions are lazy |
| 09:02 | schlarf | ah, strict by default, lazy where it makes sense |
| 09:02 | rhickey | and even there the notion of lazy is looser than Haskell's |
| 09:03 | schlarf | will you kill me if i post a message-passing-OO-system to comp.lang.clojure? |
| 09:03 | rhickey | i.e. args are still eagerly evaluated and the existence of a return seq is eagerly determined, but only as much of the consumed seqs are produced as are required |
| 09:04 | rhickey | schlarf: there is no comp.lang.clojure - you mean the google group? |
| 09:05 | schlarf | yes |
| 09:05 | rhickey | schlarf: I'm all for experimentation |
| 09:06 | schlarf | cool |
| 09:15 | schlarf | http://groups.google.de/group/comp.lang.lisp/browse_thread/thread/dbd4b63f41e11e40# |
| 09:15 | schlarf | ^^clojure review |
| 09:30 | cemerick | schlarf: thanks for that, interesting stuff; here's an english link, btw: http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/dbd4b63f41e11e40# |
| 09:30 | cemerick | The German UI labels were puzzling to me :-) |
| 09:35 | schlarf | why cant i list % |
| 09:41 | tWip | you mean? #(list %)? |
| 10:26 | Chouser | rhickey: I working on a response to your regex question, on the assumption that a breaking change doesn't completely rule out the proposal. |
| 10:26 | Chouser | s/I/I'm/ |
| 10:27 | schlarf | (def inst (gensym)) ; (assoc inst "graph" 0) .> symbol cannot be cast to assoc |
| 10:27 | rhickey | Chouser: ok |
| 10:28 | Chouser | um, I mean -- does the fact that it will break some old regex literals completely rule out the proposal? |
| 10:28 | schlarf | i want a unique name for my hash-map, cant i get that? |
| 10:29 | schlarf | (def (gensym) (hash-map x y)) |
| 10:29 | Chouser | schlarf: are you writing a macro? |
| 10:29 | schlarf | no but mayeb i should |
| 10:29 | rhickey | Chouser: I hope not, I just want to know what the story will be |
| 10:29 | Chouser | rhickey: ok, I'll keep working. |
| 10:30 | wwmorgan | schlarf: you can do (var-get (resolve symbol)) |
| 10:45 | schlarf | is it impossible to modify a Map passed as an argument inside the function and have it keep it ouside? |
| 10:46 | wwmorgan | schlar: in general you want to return the changed map from the function |
| 10:46 | wwmorgan | *schlarf |
| 10:46 | schlarf | well imtrying to create an object-system with Maps |
| 10:46 | schlarf | using Maps |
| 10:47 | schlarf | and i want mutability for it |
| 10:47 | jgracin | schlarf: Clojure's map or Java's? In Clojure use refs |
| 10:47 | schlarf | not (def a = (update a)) |
| 10:47 | schlarf | jgracin: ok |
| 10:49 | blackdog | you can just use alter on your ref of map to change the values |
| 10:55 | schlarf | but how do i use refs without any transactiosn going? i get that complaint when using alter ona ref |
| 10:55 | schlarf | and how do i get values from a ref? |
| 10:55 | blackdog | dosync round the alter |
| 10:55 | schlarf | (def a (ref (hash-map))); how can i change that map? |
| 10:55 | wwmorgan | schlarf: http://clojure.org/refs |
| 10:55 | blackdog | @a |
| 10:55 | schlarf | im reading there |
| 10:56 | blackdog | (dosync (alter a assoc :x 1)) |
| 10:56 | schlarf | seems like im really not meant to do this in clojure? is it easier in other lisps? |
| 10:56 | rhickey | schlarf: an object system for Clojure should be either transactional (using refs) or async (using agents) |
| 10:57 | schlarf | ok |
| 10:57 | rhickey | the resulting OO system will be multicore ready, unlike almost all others |
| 10:57 | schlarf | cool |
| 10:58 | schlarf | very cool actually. so that would a huge problem for say, a python-program |
| 10:58 | schlarf | ? |
| 10:58 | schlarf | to run it on mutliple cores |
| 10:58 | blackdog | probably as they have global interpreter lock which i guess is for one core?? |
| 10:58 | schlarf | how do i get the value of ref? |
| 10:58 | blackdog | @a |
| 10:59 | schlarf | ah |
| 11:04 | schlarf | can i still use def? and it can satisfy transactionality or asynchronisity? |
| 11:09 | blackdog | yes, you can do (def x (ref (hash-map))) |
| 11:10 | blackdog | works just the same |
| 11:11 | rhickey | schlarf: but you wouldn't want an object system that required every object to have a global name, would you? |
| 11:14 | Chouser | hm, that sounds like a system I've used. This was the least of its problems. |
| 11:14 | schlarf | rhickey: and with def i force it to? |
| 11:15 | rhickey | schlarf: what languages do you know? |
| 11:18 | schlarf | python |
| 11:23 | rhickey | schlarf: when you create an instance of a class in Python that instance has no name, only the variable to which you assign it has a name |
| 11:24 | rhickey | so variables and objects are separate ideas |
| 11:25 | rhickey | def is about (global) variables, in which you can put anything, including instances of any objects you invent |
| 11:25 | rhickey | but you object system should be independent of def |
| 11:27 | schlarf | yes i see |
| 11:34 | schlarf | woot |
| 11:34 | schlarf | i think i just had a spark of enlightenment |
| 11:34 | schlarf | for programming in general |
| 11:34 | schlarf | ty clojure-channel |
| 11:38 | scottj | rhickey: on http://clojure.org/getting_started under Debugging it might be useful to mention where the -Xdebug flags should go in the java init command. I tried putting it at the end. |
| 11:40 | rhickey | scottj: doen |
| 11:40 | rhickey | done |
| 12:17 | fogus | Damn dirty lazy seqs! ;) |
| 12:17 | rhickey | You mean damn dirty side effects? |
| 12:18 | fogus | well, that too |
| 12:19 | Chouser | file closed too early? |
| 12:20 | fogus | Nah. My issue was that I was accumulating a "best |
| 12:20 | fogus | var from a seq |
| 12:20 | fogus | then trying to return the acculmulator |
| 12:21 | fogus | but it was always the 1st value |
| 12:21 | fogus | (of course) |
| 12:21 | Chouser | sure. what looping construct did you use? I would reach for "reduce" first, which is non-lazy. |
| 12:21 | rhickey | fogus: (doc max-key) |
| 12:23 | fogus | this was my first version http://pastebin.com/m2ae471a0 |
| 12:24 | Chouser | very reasonable attempt! But yes, for is lazy, and you're trying to use it for side-effects. |
| 12:24 | fogus | (best > '(1 2 3 4 5)) => 5 in reality, but 1 with my defn |
| 12:25 | fogus | So then when it hit me that the for returned a lazy seq it became http://pastebin.com/d4832b6ee |
| 12:27 | fogus | But it still smells like a hack to me |
| 12:27 | Chouser | yep, I'd agree. |
| 12:30 | scottj | What is the idiom for looping while a condition is true, changing counter to rest of a list each time and collecting results? Example: http://pastebin.com/m250d5e94 |
| 12:31 | gnuvince | scottj: not sure if Clojure has it, but take-while would be appropriate I think |
| 12:34 | scottj | gnuvince: but the predicate in take-while can only be a specific item in the list, not the rest of the list, right? |
| 12:34 | gnuvince | Right. |
| 12:34 | scottj | function of a specific item I mean |
| 12:34 | gnuvince | Hmmm |
| 12:34 | wwmorgan | scottj: is that one of the euler problems you're trying to solve? |
| 12:35 | scottj | wwmorgan: yep, solved it, but I was hoping there was a more concise, idiomatic way |
| 12:35 | wwmorgan | there is. Look at partition |
| 12:36 | rhickey | (defn best [f xs] (reduce #(if (f %1 %2) %1 %2) xs)) |
| 12:37 | fogus | (humbled) |
| 12:37 | gnuvince | scottj: something in Haskell (don't have Clojure installed right now): |
| 12:37 | gnuvince | > takeWhile (\xs -> length xs == 5) (map (take 5) (tails [1..10])) |
| 12:37 | gnuvince | [[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7],[4,5,6,7,8],[5,6,7,8,9],[6,7,8,9,10]] |
| 12:38 | wwmorgan | gnuvince: that's (partition 5 1 (range 1 10)) |
| 12:41 | gnuvince | wwmorgan: nice |
| 12:42 | Chouser | Rich wrote a "tails" as well (for cases where you want the sort lists at the end, for example) ... but I always have trouble finding it. |
| 12:44 | scottj | thanks, partition definitely solves that problem much better |
| 12:46 | Chouser | oh, maybe it was "inits" |
| 12:48 | scottj | Is there a better way to convert an integer to a list of integers representing its digits than (map #(Integer/parseInt %) (map str (str n))) ? |
| 12:48 | schlarf | it would be possible to implement optional parameters with a macro right? |
| 12:48 | schlarf | because i dont want & rest |
| 12:49 | wwmorgan | schlarf: can you give an example of what you're looking for? |
| 12:51 | schlarf | (def-class [name &optional parent]...) |
| 12:51 | schlarf | i could ofc dp &rest and check if rest==nil |
| 12:52 | Chouser | schlarf: you can do destructuring on &rest: (let [[& [a b c]] [1 2]] (list a b c)) |
| 12:52 | wwmorgan | right. Which in your case might look like (defmaco def-class [name & [parent & _]] ...) |
| 13:15 | schlarf | if using list in macro, should i then quote things i dont want to eval at compile time |
| 13:16 | schlarf | im getting: clojure.lang.LispReader$Unquote@af8b32 when macro-expanding |
| 13:17 | schlarf | instead of the should-be generated list |
| 13:17 | cemerick | rhickey: I don't remember if I suggested this in the past, but it would be nice to be able to determine whether a Delay has been forced yet. delayed? perhaps, with a corresponding public static fn on the Java side... |
| 13:24 | scottj | Is there a function that takes a series of collections (same size) and returns all possible combinations of the top level items in those collections? |
| 13:36 | Chouser | scottj: for does that |
| 13:41 | Chouser | schlarf: Unquote is generated by ~, which is meant to be used inside backticks: `(prn 1 2 ~(- 5 3)) |
| 13:41 | aperotte | Is anyone having a problem with enclojure not recognizing certain names? The REPL in netbeans doesn't recognize "format" as a defined function. |
| 13:42 | schlarf | works with emacs |
| 13:42 | Chouser | aperotte: "format" is new-ish. |
| 13:44 | aperotte | oh ok, thanks |
| 13:51 | lisppaste8 | schlarf pasted "dosync-macro" at http://paste.lisp.org/display/68176 |
| 13:52 | lisppaste8 | schlarf annotated #68176 with "what to geenerate" at http://paste.lisp.org/display/68176#1 |
| 13:52 | schlarf | ^^ can someone help me with that macro ^^ |
| 13:53 | TommyOnMac | hi |
| 13:53 | schlarf | user=> (list 'dosync '(alter x assoc y z)) -> (dosync (alter x assoc y z)) is a start but how do i replace x y z with the params passed? |
| 13:54 | alec | schlarf: use list interpolation, don't build your own lists |
| 13:54 | alec | `(dosync (alter ~x assoc ~y ~z)) or something |
| 13:54 | Chouser | TommyOnMac: hi |
| 13:56 | schlarf | java.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.Ref |
| 13:56 | schlarf | when i use that alex |
| 13:57 | alec | schlarf: when I have trouble with macros, I run (macroexpand '(<code>)) and look at the output |
| 14:01 | schlarf | when i have troubales with macos macroexpand never works |
| 14:01 | schlarf | Caused by: java.lang.Exception: Unable to resolve symbol: macro-expand-1 in this context |
| 14:02 | Chouser | macroexpand-1 or macroexpand |
| 14:03 | schlarf | with both |
| 14:04 | schlarf | oh wait i used macro-expand |
| 14:04 | Chouser | heh, sorry, I mean "macro-expand-1" with two dashes is incorrect. please use either "macroexpand-1" or "macroexpand" |
| 14:51 | schlarf | if i want to (dosync (alter obj assoc :methods method_name)) but :methods is a vector and i wanto to conj to it |
| 14:51 | schlarf | i canr figure out how to write to it |
| 14:56 | Chouser | schlarf: you might want assoc-in |
| 15:30 | schlarf | assoc-in only seem to wor with numbers, not strings |
| 15:32 | schlarf | waitno |
| 18:34 | aperotte | Hello everyone. I was interested in adding the clojure-contrib files to my classpath, but it seems like I'm doing something wrong. |
| 18:34 | aperotte | I put the contents of the src folder from clojure-contrib into ~/clojure |
| 18:35 | aperotte | then I set the environment variable CLOJURE_CLASSPATH=~/clojure |
| 18:36 | aperotte | I then load clojure and try to run (use 'clojure.contrib.duck-streams) |
| 18:36 | aperotte | and errors fly |
| 18:36 | Chouser | clojure doesn't have it's own classpath |
| 18:36 | Chouser | you need to set java's classpath to include the clojure-contrib/src directory. |
| 18:37 | aperotte | ohh ok |
| 18:37 | Chouser | instead of copything that around I run clojure like this: java -cp ~/build/clojure/clojure.jar:/home/chouser/proj/clojure-contrib/src clojure.lang.Repl |
| 18:38 | aperotte | ok, I see |
| 18:40 | aperotte | Chouser: beautiful ... thank you |
| 18:45 | Chouser | np |
| 19:38 | gnuvince_ | What would be a clear way to test if the elements of a collection are all equal? |
| 19:40 | gnuvince_ | (every? #(= (first x) %) (rest x)) |
| 19:40 | gnuvince_ | Clear enough? |
| 19:42 | Chouser | (apply = x) |
| 19:44 | gnuvince_ | ... |
| 19:45 | Chouser | it's just an idea. There's probably a better way. |
| 19:45 | Chouser | ok, maybe not |
| 19:46 | gnuvince_ | It's perfect. |
| 22:09 | ChibaPet | Hey, all. A quick question. I'm new to all this, but I'm wondering if the JVM does anything to distribute threads across multiple cores/CPUs, since Clojure uses Java threads... I'm looking at options for functional/concurrent programming, and was curious. |
| 22:10 | walters | java threads usually map to OS threads which the OS scheduler will distribute across cores |
| 22:10 | walters | unless you're using a broken VM or a broken OS it will Just Work |
| 22:10 | ChibaPet | hm, ok, cool |
| 22:11 | ChibaPet | Thank you. |