#clojure logs

2008-10-08

02:41schlarf(defmacro assoc! [map_ k v]
02:41schlarf `(def ~map_ (assoc ~map_ ~k ~v)))
02:41schlarfthat cant be done woth a defn right?
02:41schlarfand oh yeah, ima sinner babY!
02:41Chouseryeah it can, and you do sin.
02:41Chouser:-)
02:42Chouseroh, sorry, no you're right.
02:42Chouserbecause you're passing in the name, I think it has to be a macro.
02:43Chouserif you just used a ref instead, you could do it in a defn and it would play nice with STM and threads.
02:44schlarfok ill look into refs. and anywa, im not planning to really use assoc!, just assoc...
03:13schlarfclojure/ <- why is thta coming into my macro?
03:23hoeckschlarf: to prevent aliasing
03:24hoeckto avoid it, use ~'foo in backquotes
04:12lisppaste8askl pasted "compress withr educe" at http://paste.lisp.org/display/68148
04:12schlarf^^ i posted a compress-function
04:13schlarfit it working using cond and recur but i want to use reduce
04:13schlarfbut i cant get it to work
04:45lisppaste8yangsx annotated #68148 with "reduce is functional" at http://paste.lisp.org/display/68148#1
04:47Lau_of_DKIm 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:49lisppaste8hoeck annotated #68148 with "filter or reduce" at http://paste.lisp.org/display/68148#2
04:50lisppaste8tWip pasted "Latest Slime + swank-clojure does not start" at http://paste.lisp.org/display/68150
04:51tWipanyone experienced the same? clojure complains about symbol *1 in swank core.clj
04:57yangsxtWip: slime's using iso-latin-1-unix; you can try to use utf-8-unix
05:00tWipI'll try that.
05:09hoeckLau_of_DK: `.' doesn't work?
05:10Lau_of_DKUnfortunately not
05:10Lau_of_DK%windir% works, but is not applicable :)
05:14hoeckLau_of_DK: %cd% ?
05:27Lau_of_DKhoeck, %cd% works perfect, thanks alot
06:00schlarfis there no round function?
06:01tWipyou can always use Math.round from Java
06:04schlarfi can import math but not round
06:04schlarf(import Math)
06:04schlarf(.Math.round 5.0)
06:04schlarfis the use right?
06:04schlarfnot working...
06:05tWipit's in java.lang so no need to import
06:05tWipjust (. Math (round 5.0))
06:15hoeckschlarf: its even a static method, so (Math/round 5.0) works too
06:15tWipoh I didn't know about that syntax
06:16tWipis that new? or newish
06:20hoeckrather newsish, maybe about 2-3 months old
06:20tWipok
07:44schlarfslurp
07:44schlarfnice to see a language deisgner with a sense of humour
07:50cemerickrhickey: 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:53rhickeycemerick: not exactly sure what you're getting at, can only capture those used
07:54rhickeyis there a specific scenario you're thinking of?
07:55cemerickrhickey: 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:56rhickeyhow could it not?
07:56rhickeythe returned fn calls :key on it every time it is called
07:57cemerickrhickey: right, see, I'm not thinking straight yet; I meant something more like (let [foo (large-obj) val (:key foo)] #(blah val))
07:58rhickeyok, in that case no reference to foo in the closure
07:58cemerickrhickey: OK, good to know. Thanks for your patience :-)
07:58rhickeynp
08:28gnuvinceGood morning
08:28tWipmorning? surely not... it's time to go home soon.
08:30H4nstWip: psst, he is in another time zone.
08:31tWipyes, I got that... just trying to make some (admittedly poor) humor
08:31cemericknonsense, it's 8:28 *everywhere* :-)
08:32H4nstWip: yeah, my remark was not really much better, apologies :)
08:32cemerick45 people in #clojure -- anyone have any ideas on where the influx is coming from?
08:32cemerickI suppose the steady trickle of clojure posts on proggit don't hurt.
08:32rhickeycemerick: we hit 63+ yesterday
08:32blackdogi think the boston meeting did it
08:32cemerickyeah, I saw that -- good to see it
08:33schlarfceemrick: all my bots
08:33cemerickah, so other lisp ex-pats, then?
08:33rhickeyblackdog: yes, seemed to have connected with a good pool of people through that
08:33H4nscemerick: i got two passports
08:34rhickeywe're about to lap 600 on the group
08:34tWipI think Clojure really brings something to lispers in the JVM enterprise land
08:34blackdogalso, the jvm summit got quite a few writeups on various influential blogs, and there were only good things to say
08:34tWipI was using jscheme before clojure, which was quite nice also, but nowhere near as good performance
08:34cemerickrhickey: BTW, I made some contact with business-side people at Sun last week, talked them up on Clojure. Certainly piqued their interest.
08:35gnuvincerhickey: do you use Clojure for your work?
08:35rhickeycemerick: cool
08:35rhickeygnuvince: yes
08:36gnuvinceThat's good
08:41akinghi donald - yup
08:41akingoppss
08:54schlarfhow do i get parenthesis around < x 10: (list 'fn '[x] (hd xs) 'x (nth xs 1))
08:54schlarf(def xs '(< 10))
08:56rhickeyschlarf: what are you trying to do?
08:56schlarflol i posted it a few days ago but forgot
08:57rhickey#(< % 10)
08:57rhickey?
08:57schlarfyes
08:57schlarfwhere is the definition of #? its a macro right? in boot.clj?
08:58rhickey#() is reader syntax
08:58schlarfok
09:01schlarfis clojure lazy throughout?
09:01schlarfeverything is lazy?
09:01rhickeyschlarf: no
09:01schlarffor some reason i dont get the same difficulty predicitng stuff as in haskell
09:01schlarfoh ok
09:01rhickeyClojure is strict, most of the sequence functions are lazy
09:02schlarfah, strict by default, lazy where it makes sense
09:02rhickeyand even there the notion of lazy is looser than Haskell's
09:03schlarfwill you kill me if i post a message-passing-OO-system to comp.lang.clojure?
09:03rhickeyi.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:04rhickeyschlarf: there is no comp.lang.clojure - you mean the google group?
09:05schlarfyes
09:05rhickeyschlarf: I'm all for experimentation
09:06schlarfcool
09:15schlarfhttp://groups.google.de/group/comp.lang.lisp/browse_thread/thread/dbd4b63f41e11e40#
09:15schlarf^^clojure review
09:30cemerickschlarf: thanks for that, interesting stuff; here's an english link, btw: http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/dbd4b63f41e11e40#
09:30cemerickThe German UI labels were puzzling to me :-)
09:35schlarfwhy cant i list %
09:41tWipyou mean? #(list %)?
10:26Chouserrhickey: I working on a response to your regex question, on the assumption that a breaking change doesn't completely rule out the proposal.
10:26Chousers/I/I'm/
10:27schlarf(def inst (gensym)) ; (assoc inst "graph" 0) .> symbol cannot be cast to assoc
10:27rhickeyChouser: ok
10:28Chouserum, I mean -- does the fact that it will break some old regex literals completely rule out the proposal?
10:28schlarfi want a unique name for my hash-map, cant i get that?
10:29schlarf(def (gensym) (hash-map x y))
10:29Chouserschlarf: are you writing a macro?
10:29schlarfno but mayeb i should
10:29rhickeyChouser: I hope not, I just want to know what the story will be
10:29Chouserrhickey: ok, I'll keep working.
10:30wwmorganschlarf: you can do (var-get (resolve symbol))
10:45schlarfis it impossible to modify a Map passed as an argument inside the function and have it keep it ouside?
10:46wwmorganschlar: in general you want to return the changed map from the function
10:46wwmorgan*schlarf
10:46schlarfwell imtrying to create an object-system with Maps
10:46schlarfusing Maps
10:47schlarfand i want mutability for it
10:47jgracinschlarf: Clojure's map or Java's? In Clojure use refs
10:47schlarfnot (def a = (update a))
10:47schlarfjgracin: ok
10:49blackdogyou can just use alter on your ref of map to change the values
10:55schlarfbut how do i use refs without any transactiosn going? i get that complaint when using alter ona ref
10:55schlarfand how do i get values from a ref?
10:55blackdogdosync round the alter
10:55schlarf(def a (ref (hash-map))); how can i change that map?
10:55wwmorganschlarf: http://clojure.org/refs
10:55blackdog@a
10:55schlarfim reading there
10:56blackdog(dosync (alter a assoc :x 1))
10:56schlarfseems like im really not meant to do this in clojure? is it easier in other lisps?
10:56rhickeyschlarf: an object system for Clojure should be either transactional (using refs) or async (using agents)
10:57schlarfok
10:57rhickeythe resulting OO system will be multicore ready, unlike almost all others
10:57schlarfcool
10:58schlarfvery cool actually. so that would a huge problem for say, a python-program
10:58schlarf?
10:58schlarfto run it on mutliple cores
10:58blackdogprobably as they have global interpreter lock which i guess is for one core??
10:58schlarfhow do i get the value of ref?
10:58blackdog@a
10:59schlarfah
11:04schlarfcan i still use def? and it can satisfy transactionality or asynchronisity?
11:09blackdogyes, you can do (def x (ref (hash-map)))
11:10blackdogworks just the same
11:11rhickeyschlarf: but you wouldn't want an object system that required every object to have a global name, would you?
11:14Chouserhm, that sounds like a system I've used. This was the least of its problems.
11:14schlarfrhickey: and with def i force it to?
11:15rhickeyschlarf: what languages do you know?
11:18schlarfpython
11:23rhickeyschlarf: 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:24rhickeyso variables and objects are separate ideas
11:25rhickeydef is about (global) variables, in which you can put anything, including instances of any objects you invent
11:25rhickeybut you object system should be independent of def
11:27schlarfyes i see
11:34schlarfwoot
11:34schlarfi think i just had a spark of enlightenment
11:34schlarffor programming in general
11:34schlarfty clojure-channel
11:38scottjrhickey: 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:40rhickeyscottj: doen
11:40rhickeydone
12:17fogusDamn dirty lazy seqs! ;)
12:17rhickeyYou mean damn dirty side effects?
12:18foguswell, that too
12:19Chouserfile closed too early?
12:20fogusNah. My issue was that I was accumulating a "best
12:20fogusvar from a seq
12:20fogusthen trying to return the acculmulator
12:21fogusbut it was always the 1st value
12:21fogus(of course)
12:21Chousersure. what looping construct did you use? I would reach for "reduce" first, which is non-lazy.
12:21rhickeyfogus: (doc max-key)
12:23fogusthis was my first version http://pastebin.com/m2ae471a0
12:24Chouservery reasonable attempt! But yes, for is lazy, and you're trying to use it for side-effects.
12:24fogus(best > '(1 2 3 4 5)) => 5 in reality, but 1 with my defn
12:25fogusSo then when it hit me that the for returned a lazy seq it became http://pastebin.com/d4832b6ee
12:27fogusBut it still smells like a hack to me
12:27Chouseryep, I'd agree.
12:30scottjWhat 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:31gnuvincescottj: not sure if Clojure has it, but take-while would be appropriate I think
12:34scottjgnuvince: but the predicate in take-while can only be a specific item in the list, not the rest of the list, right?
12:34gnuvinceRight.
12:34scottjfunction of a specific item I mean
12:34gnuvinceHmmm
12:34wwmorganscottj: is that one of the euler problems you're trying to solve?
12:35scottjwwmorgan: yep, solved it, but I was hoping there was a more concise, idiomatic way
12:35wwmorganthere is. Look at partition
12:36rhickey(defn best [f xs] (reduce #(if (f %1 %2) %1 %2) xs))
12:37fogus(humbled)
12:37gnuvincescottj: something in Haskell (don't have Clojure installed right now):
12:37gnuvince> takeWhile (\xs -> length xs == 5) (map (take 5) (tails [1..10]))
12:37gnuvince[[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:38wwmorgangnuvince: that's (partition 5 1 (range 1 10))
12:41gnuvincewwmorgan: nice
12:42ChouserRich 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:44scottjthanks, partition definitely solves that problem much better
12:46Chouseroh, maybe it was "inits"
12:48scottjIs 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:48schlarfit would be possible to implement optional parameters with a macro right?
12:48schlarfbecause i dont want & rest
12:49wwmorganschlarf: can you give an example of what you're looking for?
12:51schlarf(def-class [name &optional parent]...)
12:51schlarfi could ofc dp &rest and check if rest==nil
12:52Chouserschlarf: you can do destructuring on &rest: (let [[& [a b c]] [1 2]] (list a b c))
12:52wwmorganright. Which in your case might look like (defmaco def-class [name & [parent & _]] ...)
13:15schlarfif using list in macro, should i then quote things i dont want to eval at compile time
13:16schlarfim getting: clojure.lang.LispReader$Unquote@af8b32 when macro-expanding
13:17schlarfinstead of the should-be generated list
13:17cemerickrhickey: 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:24scottjIs 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:36Chouserscottj: for does that
13:41Chouserschlarf: Unquote is generated by ~, which is meant to be used inside backticks: `(prn 1 2 ~(- 5 3))
13:41aperotteIs anyone having a problem with enclojure not recognizing certain names? The REPL in netbeans doesn't recognize "format" as a defined function.
13:42schlarfworks with emacs
13:42Chouseraperotte: "format" is new-ish.
13:44aperotteoh ok, thanks
13:51lisppaste8schlarf pasted "dosync-macro" at http://paste.lisp.org/display/68176
13:52lisppaste8schlarf annotated #68176 with "what to geenerate" at http://paste.lisp.org/display/68176#1
13:52schlarf^^ can someone help me with that macro ^^
13:53TommyOnMachi
13:53schlarfuser=> (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:54alecschlarf: use list interpolation, don't build your own lists
13:54alec`(dosync (alter ~x assoc ~y ~z)) or something
13:54ChouserTommyOnMac: hi
13:56schlarfjava.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.Ref
13:56schlarfwhen i use that alex
13:57alecschlarf: when I have trouble with macros, I run (macroexpand '(<code>)) and look at the output
14:01schlarfwhen i have troubales with macos macroexpand never works
14:01schlarfCaused by: java.lang.Exception: Unable to resolve symbol: macro-expand-1 in this context
14:02Chousermacroexpand-1 or macroexpand
14:03schlarfwith both
14:04schlarfoh wait i used macro-expand
14:04Chouserheh, sorry, I mean "macro-expand-1" with two dashes is incorrect. please use either "macroexpand-1" or "macroexpand"
14:51schlarfif i want to (dosync (alter obj assoc :methods method_name)) but :methods is a vector and i wanto to conj to it
14:51schlarfi canr figure out how to write to it
14:56Chouserschlarf: you might want assoc-in
15:30schlarfassoc-in only seem to wor with numbers, not strings
15:32schlarfwaitno
18:34aperotteHello everyone. I was interested in adding the clojure-contrib files to my classpath, but it seems like I'm doing something wrong.
18:34aperotteI put the contents of the src folder from clojure-contrib into ~/clojure
18:35aperottethen I set the environment variable CLOJURE_CLASSPATH=~/clojure
18:36aperotteI then load clojure and try to run (use 'clojure.contrib.duck-streams)
18:36aperotteand errors fly
18:36Chouserclojure doesn't have it's own classpath
18:36Chouseryou need to set java's classpath to include the clojure-contrib/src directory.
18:37aperotteohh ok
18:37Chouserinstead 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:38aperotteok, I see
18:40aperotteChouser: beautiful ... thank you
18:45Chousernp
19:38gnuvince_What would be a clear way to test if the elements of a collection are all equal?
19:40gnuvince_(every? #(= (first x) %) (rest x))
19:40gnuvince_Clear enough?
19:42Chouser(apply = x)
19:44gnuvince_...
19:45Chouserit's just an idea. There's probably a better way.
19:45Chouserok, maybe not
19:46gnuvince_It's perfect.
22:09ChibaPetHey, 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:10waltersjava threads usually map to OS threads which the OS scheduler will distribute across cores
22:10waltersunless you're using a broken VM or a broken OS it will Just Work
22:10ChibaPethm, ok, cool
22:11ChibaPetThank you.