#clojure log - Oct 08 2008

The Joy of Clojure
Main Clojure site
Google Group
IRC
List of all logged dates

2:41 schlarf: (defmacro assoc! [map_ k v]

2:41 `(def ~map_ (assoc ~map_ ~k ~v)))

2:41 that cant be done woth a defn right?

2:41 and oh yeah, ima sinner babY!

2:41 Chouser: yeah it can, and you do sin.

2:41 :-)

2:42 oh, sorry, no you're right.

2:42 because you're passing in the name, I think it has to be a macro.

2:43 if you just used a ref instead, you could do it in a defn and it would play nice with STM and threads.

2:44 schlarf: ok ill look into refs. and anywa, im not planning to really use assoc!, just assoc...

3:13 clojure/ <- why is thta coming into my macro?

3:23 hoeck: schlarf: to prevent aliasing

3:24 to avoid it, use ~'foo in backquotes

4:12 lisppaste8: askl pasted "compress withr educe" at http://paste.lisp.org/display/68148

4:12 schlarf: ^^ i posted a compress-function

4:13 it it working using cond and recur but i want to use reduce

4:13 but i cant get it to work

4:45 lisppaste8: yangsx annotated #68148 with "reduce is functional" at http://paste.lisp.org/display/68148#1

4: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?

4:49 lisppaste8: hoeck annotated #68148 with "filter or reduce" at http://paste.lisp.org/display/68148#2

4:50 tWip pasted "Latest Slime + swank-clojure does not start" at http://paste.lisp.org/display/68150

4:51 tWip: anyone experienced the same? clojure complains about symbol *1 in swank core.clj

4:57 yangsx: tWip: slime's using iso-latin-1-unix; you can try to use utf-8-unix

5:00 tWip: I'll try that.

5:09 hoeck: Lau_of_DK: `.' doesn't work?

5:10 Lau_of_DK: Unfortunately not

5:10 %windir% works, but is not applicable :)

5:14 hoeck: Lau_of_DK: %cd% ?

5:27 Lau_of_DK: hoeck, %cd% works perfect, thanks alot

6:00 schlarf: is there no round function?

6:01 tWip: you can always use Math.round from Java

6:04 schlarf: i can import math but not round

6:04 (import Math)

6:04 (.Math.round 5.0)

6:04 is the use right?

6:04 not working...

6:05 tWip: it's in java.lang so no need to import

6:05 just (. Math (round 5.0))

6:15 hoeck: schlarf: its even a static method, so (Math/round 5.0) works too

6:15 tWip: oh I didn't know about that syntax

6:16 is that new? or newish

6:20 hoeck: rather newsish, maybe about 2-3 months old

6:20 tWip: ok

7:44 schlarf: slurp

7:44 nice to see a language deisgner with a sense of humour

7: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....)

7:53 rhickey: cemerick: not exactly sure what you're getting at, can only capture those used

7:54 is there a specific scenario you're thinking of?

7: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.

7:56 rhickey: how could it not?

7:56 the returned fn calls :key on it every time it is called

7: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))

7:58 rhickey: ok, in that case no reference to foo in the closure

7:58 cemerick: rhickey: OK, good to know. Thanks for your patience :-)

7:58 rhickey: np

7:59 * cemerick returns to nursing his caffeine-rich tea

7:59 * rhickey does too

8:28 gnuvince: Good morning

8:28 tWip: morning? surely not... it's time to go home soon.

8:30 H4ns: tWip: psst, he is in another time zone.

8:31 tWip: yes, I got that... just trying to make some (admittedly poor) humor

8:31 cemerick: nonsense, it's 8:28 *everywhere* :-)

8:32 H4ns: tWip: yeah, my remark was not really much better, apologies :)

8:32 cemerick: 45 people in #clojure -- anyone have any ideas on where the influx is coming from?

8:32 I suppose the steady trickle of clojure posts on proggit don't hurt.

8:32 rhickey: cemerick: we hit 63+ yesterday

8:32 blackdog: i think the boston meeting did it

8:32 cemerick: yeah, I saw that -- good to see it

8:33 schlarf: ceemrick: all my bots

8:33 cemerick: ah, so other lisp ex-pats, then?

8:33 rhickey: blackdog: yes, seemed to have connected with a good pool of people through that

8:33 H4ns: cemerick: i got two passports

8:33 * cemerick is just a stranger in a strange land

8:34 rhickey: we're about to lap 600 on the group

8:34 tWip: I think Clojure really brings something to lispers in the JVM enterprise land

8:34 blackdog: also, the jvm summit got quite a few writeups on various influential blogs, and there were only good things to say

8:34 tWip: I was using jscheme before clojure, which was quite nice also, but nowhere near as good performance

8: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.

8:35 gnuvince: rhickey: do you use Clojure for your work?

8:35 rhickey: cemerick: cool

8:35 gnuvince: yes

8:36 gnuvince: That's good

8:41 aking: hi donald - yup

8:41 oppss

8:54 schlarf: how do i get parenthesis around < x 10: (list 'fn '[x] (hd xs) 'x (nth xs 1))

8:54 (def xs '(< 10))

8:56 rhickey: schlarf: what are you trying to do?

8:56 schlarf: lol i posted it a few days ago but forgot

8:57 rhickey: #(< % 10)

8:57 ?

8:57 schlarf: yes

8:57 where is the definition of #? its a macro right? in boot.clj?

8:58 rhickey: #() is reader syntax

8:58 schlarf: ok

9:01 is clojure lazy throughout?

9:01 everything is lazy?

9:01 rhickey: schlarf: no

9:01 schlarf: for some reason i dont get the same difficulty predicitng stuff as in haskell

9:01 oh ok

9:01 rhickey: Clojure is strict, most of the sequence functions are lazy

9:02 schlarf: ah, strict by default, lazy where it makes sense

9:02 rhickey: and even there the notion of lazy is looser than Haskell's

9:03 schlarf: will you kill me if i post a message-passing-OO-system to comp.lang.clojure?

9: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

9:04 schlarf: there is no comp.lang.clojure - you mean the google group?

9:05 schlarf: yes

9:05 rhickey: schlarf: I'm all for experimentation

9:06 schlarf: cool

9:15 http://groups.google.de/group/comp.lang.lisp/browse_thread/thread/dbd4b63f41e11e40#

9:15 ^^clojure review

9: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#

9:30 The German UI labels were puzzling to me :-)

9:35 schlarf: why cant i list %

9: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 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 (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 *schlarf

10:46 schlarf: well imtrying to create an object-system with Maps

10:46 using Maps

10:47 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 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 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 very cool actually. so that would a huge problem for say, a python-program

10:58 ?

10:58 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 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 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 so variables and objects are separate ideas

11:25 def is about (global) variables, in which you can put anything, including instances of any objects you invent

11:25 but you object system should be independent of def

11:27 schlarf: yes i see

11:34 woot

11:34 i think i just had a spark of enlightenment

11:34 for programming in general

11:34 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 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 var from a seq

12:20 then trying to return the acculmulator

12:21 but it was always the 1st value

12:21 (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 So then when it hit me that the for returned a lazy seq it became http://pastebin.com/d4832b6ee

12:27 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 > takeWhile (\xs -> length xs == 5) (map (take 5) (tails [1..10]))

12:37 [[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 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 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 im getting: clojure.lang.LispReader$Unquote@af8b32 when macro-expanding

13:17 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 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 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 `(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 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 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 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 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 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 I put the contents of the src folder from clojure-contrib into ~/clojure

18:35 then I set the environment variable CLOJURE_CLASSPATH=~/clojure

18:36 I then load clojure and try to run (use 'clojure.contrib.duck-streams)

18:36 and errors fly

18:36 Chouser: clojure doesn't have it's own classpath

18:36 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 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 (every? #(= (first x) %) (rest x))

19:40 Clear enough?

19:42 Chouser: (apply = x)

19:44 gnuvince_: ...

19:44 * gnuvince_ feels dumb all of a sudden :)

19:45 Chouser: it's just an idea. There's probably a better way.

19:45 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 unless you're using a broken VM or a broken OS it will Just Work

22:10 ChibaPet: hm, ok, cool

22:11 Thank you.

Logging service provided by n01se.net