#clojure log - Sep 24 2009

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

0:10 mabes: can anyone explain to me why I'm getting this error?

0:10 ,(def l '(1 2 3)) (defn look_at_first (first l))

0:10 clojurebot: DENIED

0:10 mabes: hrm.. well the error is: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Symbol (NO_SOURCE_FILE:22)

0:11 I can say (first l) but I can't say than in a function

0:11 it seems like l doesn't resolve to a sequence in the function for some reason

0:12 hiredman: ok

0:12 ,(doc defn)

0:12 clojurebot: "([name doc-string? attr-map? [params*] body] [name doc-string? attr-map? ([params*] body) + attr-map?]); Same as (def name (fn [params* ] exprs*)) or (def name (fn ([params* ] exprs*)+)) with any doc-string or attrs added to the var metadata"

0:13 hiredman: defn is for defining functions

0:13 mabes: right, which is what I want to do.. I see what I am doing wrong though.. I need to have an empty vector

0:13 even if I don't have any args

0:13 hiredman: yes

0:15 I recommend looking at example code, of which there is some on clojure.org, some on core.clj, and some in the pastebin

0:16 http://delicious.com/clojurebot/pastbin <-- not all of the code here is good, but there is some good code there

0:17 mabes: ok thanks, I actually have the book by Stuart Holloway I was just playing around in the REPL and ran into that.. I forgot about needing to always pass a vector

0:18 hiredman: http://delicious.com/clojurebot/pastbin+chouser should all be good

8:29 chouser: http://n01se.net/paste/4CK -- Currying

8:57 hamza: hey guys, i have a question regarding memoize call i have a function that reads a directory and returs a list of files in it. can memonize be used in this situation to cache directory listing?

8:57 Fossi: if you don't want to find new files or directoriess

8:58 hamza: that would be my second question files will only be updated by the application is there a way to tell memoize to reset when i edit the files?

9:02 Chouser: you'd have to re-run memoize itself and start over with a completely empty cache.

9:03 hamza: kk thx.

9:04 Chouser: or write your own memoize so that you can delete subsets of the cache as needed

9:06 hamza: is there a restriction for memoize or can i use it on any funtion i want?

9:10 Chouser: nothing will stop you from using it on any clojure function, but of course it may behave weirdly if used on non-pure functions.

9:11 hamza: kk thx. all the functions i am planning to use on disk io functions.

9:11 Chouser: I would generally consider those non-pure, so use with care.

9:12 ,(let [p (memoize println)] (doseq [i [1 2 3 2 1 0 1 2]] (p i)))

9:12 clojurebot: 1 2 3 0

9:13 hamza: files wont change i only don't want to hit the disks on every read. i'll know when files change do still think it will cause trouble?

9:14 Chouser: I guess if you know when the files change and clear caches as appropriate, that would count as using with care.

9:14 hamza: kk thx.

9:50 vy: Hi! I've downloaded the shcloj-code.tgz of Programming Clojure and extracted the archive to /tmp/code. Despite I (add-classpath "file:///tmp/code"), (require 'examples.snake) complains that "Could not locate examples/snake__init.class or examples/snake.clj on classpath:". What might I be missing?

9:51 triyo: Was thinking, is there a way to interface clojurebot with a web front-end? I was thing to build a 'try clojure' page that allows user to try clojure online.

9:52 Any suggestions welcome pls.

9:54 crios: hello vy

9:54 I also donwloaded those examples, but never used (add-classpath

9:55 triyo: vy: Where you running the example from? Was you command?

9:56 *what's your command you use to run example

9:57 vy: crios: triyo: I don't use the REPL supplied by shcloj-code.tgz, I've my own emacs+SLIME setup for Clojure. I just want to introduce the related classpath on the fly.

9:57 triyo: Here is the related ps afx line: "/home/vy/usr/java/jdk/1.6.0_16/bin/java -server -classpath /home/vy/projects/clojure/clojure.jar:/home/vy/elisp/swank-clojure/:/home/vy/.clojure/clojure-contrib.jar clojure.main"

9:59 crios: exist file:///tmp/code/examples/snake ?

10:00 Chouser: in general, add-classpath is unreliable, though I don't know if that is the problem in this specific case.

10:01 vy: crios: `ls -l /tmp/code/examples/snake.clj' returns right stuff.

10:04 dnolen: vy: you need to add paths to your swank-clojure-extra-classpaths in your .emacs file.

10:04 triyo: That should work, perhaps try load-file

10:05 dnolen: vy: unfortunately this is not dynamic you'll have to edit your .emacs file and restart Emacs.

10:05 vy: dnolen: Restarting current clojure session is what I was trying to avoid...

10:05 triyo: ,(doc load-file)

10:05 clojurebot: "([name]); Sequentially read and evaluate the set of forms contained in the file."

10:06 dnolen: vy: add-classpath probably needs to absolute, did you try that?

10:07 vy: absolute?

10:08 triyo: You dont have to restart emacs after changing .emacs, you can eval the changes in emacs buffer

10:08 dnolen: vy: on my machine when I've add-classpath it always "/full/path/to/my/project/folder"

10:08 triyo: no for that particular var, it's a design problem.

10:08 triyo: vy: try without file:// protocol

10:09 vy: dnolen: (add-classpath "/tmp/code") => no protocol: /tmp/code

10:09 triyo: Hehe

10:10 vy: dnolen: You sure add-classpath works with strings without a protocol?

10:10 rsynnott: ah, classpaths

10:10 dnolen: vy: pretty sure at one point I worked on a halfbaked Clojure project management tool and use it that way.

10:11 triyo: ,(doc add-classpath)

10:11 clojurebot: "([url]); Adds the url (String or URL object) to the classpath per URLClassLoader.addURL"

10:11 * rsynnott has been using java sporadically since 1996 or so, and classpaths have always been a little irritating

10:11 Chouser: rsynnott: yes

10:11 dnolen: vy: OOPS. just check my code, you do need the protocol.

10:12 when in doubt check the code :)

10:13 ngoc: hi, does clojure have light-weight thread? or does it use normal java's thread? I heard that agent uses some kind of thread pool

10:14 Chouser: ngoc: Clojure uses Java threads which are usually full OS threads.

10:14 triyo: rsynnott: Totally agree. I've worked on java ee and app specs never defined the way classloaders should load classes. So all app servers picked their own way of dealing with classloadig concerns.

10:15 Chouser: ngoc: but an agent is not a thread -- agents are assigned to threads from a pool as needed to get work done. So having a very large number of agents is cheap.

10:17 ngoc: I come to clojure from erlang. it seems that clojure focuses on data, while erlang focuses on processes

10:18 Chouser: ngoc: that's an interesting summary.

10:19 ngoc: in erlang I can wrap a variable inside a process (like state in gen_server), then when I want to create an instance of the variable, I will create an instance of the process

10:19 Chouser: one might also argue that Clojure focuses on functions.

10:19 ngoc: is there any way to create instance of agent in clojure? in the feeling of erlang's gen_server?

10:20 Chouser: an agent is a "variable". That is, an agent has a state, and you can change that state by sending it an action or task.

10:21 but especially since you're coming from Erlang, beware or over-using agents. Clojure has several other concurrency mechanisms that may work better in certain cases.

10:24 dnolen: vy: for what it's worth I just tried a quick test myself of add-classpath and it just worked.

10:24 ngoc: For example, I want to create a tictactoe game. A game has many rooms. In Erlang I would model the game room into a gen_server which has state. When I want to create a new room I would spawn a gen_server instance. This way each room's state is wrapped inside a gen_server.

10:24 How can I do this in Clojure?

10:26 I think I will have to create a thread and wrap an agent inside that thread. Is this the right way to do?

10:26 stuartsierra: I would just use a function that returns a new agent each time it's called.

10:27 Chouser: ngoc: each room is an identifiable thing regardless of its state, right? So those would be some kind of reference object, probably a ref or agent. The state of a room at any moment would be the current board, whose turn it is, etc. all stored in a collection object, probably a map

10:29 Fossi: having done my share of erlang and clojure, i don't see where gen-server or agents come into play

10:29 ngoc: Ah, then all room should be put to a map of :room-id => agent, right?

10:30 Fossi: then, i don't really understand what a 'room' is, so that might be the problem

10:30 Chouser: ngoc: sure, and if you want that map to be global and change over time, that whole map could also be in a reference type

10:31 (def all-rooms (ref {:the-first-room (ref {:turn :player-1 :board '[x o o, o x - ...] ...

10:31 ngoc: That's what I mean "data". How about code? When a player make a move, how to make the room "react"?

10:33 Fossi: a room is a thing that has a state and some code attached to it

10:34 Chouser: (alter (:the-first-room @all-rooms) apply-players-move the-move)

10:34 Fossi: i'd argue that that's a bad (unpure) construct in most cases

10:34 Chouser: where the-move would be the user's input, and apply-players-move a function that takes an old room-state and the player's input and returns a new room-state

10:34 Fossi: i understand it from a message passing point of view, but i rarely find myself modelling things like that in clojure.

10:35 might be related to my clojure problem-domain though

10:35 Chouser: that function could also do end-of-game checking and such. That's where most of your logic will live and should be a pure function.

10:35 As such, apply-players-move will be easy to test at the repl or in unit tests, etc.

10:36 ...and completely thread safe, so you can spawn as many threads as needed to process incoming player moves.

10:39 ngoc: Can the pattern be generalized like this: (1) create a central variable, (2) when some event happens, call a central code to modify the central variable?

10:41 Does the central variable become the bottle neck: all threads must do some kind of locking on this variable?

10:41 If there are tens of thousands of players, the variable will become the bottle neck?

10:42 Chouser: (1) design a structure of data to hold the kind of data your app needs (2) write pure functions to manipulate that type of data in useful ways (3) decide what kinds of identity or reference objects will be holding that kind of state

10:43 ngoc: each room in my example was a ref, which can only be changed in a transaction. If a thread has a transaction that only touches one ref (one room) it will not have to wait on threads touching other refs.

10:44 ngoc: an alternative would be for each room to be an agent. when you send the agent a task, it'll get a thread assigned to do that work which will then also be able to proceed without waiting on any other threads that may or may not be working on other rooms.

10:45 so in short: no bottleneck.

10:45 the top level map of rooms is a single thing so if lots of threads try to add or remove rooms at the same time, they would have to line up, so there could be a bottleneck there.

10:46 if that's a actual problem, you'd split that up so you don't have a single map of rooms -- partition it across multiple mutable reference objects somehow.

10:48 ngoc: Is there a way to map a room name like "room1" (for example a string) to a ref that floats somewhere in the JVM? This way when I have a name, I will be able to get back the ref?

10:49 stuartsierra: Sure, just define a var.

10:49 ngoc: I mean when all the refs are not put inside a single collection to avoid bottle neck...

10:49 Chouser: I don't think so. Things floating around tend to get garbage collected. Something needs to act as the root and provide the mapping from name to ref.

10:50 triyo: A map of refs perhaps then you can lookup re by :key

10:50 rhickey: j.u.c.ConcurrentHashMap is a fine place to put a top-level registry of refs, if all you'll ever do is add/remove/lookup by single key

10:51 * Chouser was just about to go poking through java.util.concurrent ...honest!

10:52 ngoc: Is map in Clojure the same as ConcurrentHashMap? Or do I have to use ConcurrentHashMap explicitly?

10:52 stuartsierra: rhickey: is a namespace basically a ConcurrentHashMap of vars?

10:52 Chouser: ngoc: the latter

10:53 hiredman: rhickey: what do you think about lifting Agent.Action out into AAction and IAction and providing some indirection in Agent so it is easy to proxy Agent with a custom Action

10:53 Chouser: stuartsierra: the list of namespaces is a ConcurrentHashMap

10:53 rhickey: one way to think about j.u.c. maps is: they are to refs-to-persistent-strucutres as atoms are to refs, only supporting atomic non-coordinated access, but more concurrency than putting a persistent structure in an atom

10:54 Chouser: stuartsierra: each namespace is basically (atom {})

10:54 rhickey: namespaces use both strrategies

10:54 stuartsierra: ok

10:55 rhickey: the biggest difference being you can get a snapshot of a pds in an atom easily, can never get one from the j.u.c. stuff

10:55 j.u.c. collections make good caches/registries

10:56 i.e. single lookup vs really treating the collection as a value

10:57 ngoc: I have another question. How to have a timeout callback? For example the callback function will be called after 30s of room inactivity?

10:57 rhickey: hiredman: custom action that does what?

11:05 ngoc: I feel that Java thread must be used to create this timeout effect. But the problem is not too many threads can be created in JVM. Is there a solution?

11:05 stuartsierra: ngoc: java has a Timer class that does this

11:06 mccraig: is there a destructuring way of defaulting an optional parameters value ?

11:09 dnolen: mccraig: have you looked at clojure.contrib.def defnk, it's pretty handy.

11:11 drewr: +1

11:12 mccraig: that should do the trick. thx

11:16 Chouser: ngoc: java.util.Timer allows you to schedule multiple events in a single thread

11:33 is there a way to do an unsigned-bit-shift-right?

11:36 ngoc: The doc of java.util.Timer says "Timer tasks should complete quickly. If a timer task takes excessive time to complete, it "hogs" the timer's task execution thread. This can, in turn, delay the execution of subsequent tasks, which may "bunch up" and execute in rapid succession when (and if) the offending task finally completes." I think this single thread implementation is not good.

11:37 Chouser: ngoc: that's your call of course. I think if your timer tasks simply send off agents you'll probably be fine.

11:37 ngoc: Ah, what a trick!

11:40 cgrand: Chouser: no

11:40 ngoc: In the API (http://clojure.org/api) I see there are some "shift" functions

11:41 Can't (bit-shift-right x n) be used?

11:41 Chouser: ,(bit-shift-right -12345 8)

11:41 clojurebot: -49

11:42 Chouser: anyway, I think I have a sufficient work-around here.

11:42 tmountain: Chouser: is this helpful? http://www.mail-archive.com/clojure@googlegroups.com/msg13789.html

11:43 Chouser: tmountain: ah, that's what I was doing. But that post gives me confidence I'm doing the right thing, thanks!

11:43 tmountain: Chouser: happy to help

12:04 mtm: is there any work in progress to to enhance 'memoize'? I've got a few ideas but didn't want to reinvent the wheel

12:04 ambient: how can it be enhanced?

12:05 mtm: right now, the cache can grow without bound

12:05 also, it holds a strong reference to the return value

12:05 ambient: news for me, i thought it had a bound

12:05 mtm: nope

12:06 hiredman: mtm: it's been discussed here in the paste

12:06 past

12:06 ambient: clojure has weak refs?

12:06 hiredman: ~logs

12:06 clojurebot: logs is http://clojure-log.n01se.net/

12:06 mtm: thanks, I'll dig into it

12:06 hiredman: hmm

12:06 mtm: but, yes, I'd like to use weak refs in the cache

12:07 Chouser: ambient: java has weak references, so yes

12:07 mtm: or, at least, be able to pass in a user defined cache

12:07 Chouser: I don't know that weak references would always be appropriate for a memoize fn

12:07 hiredman: for example around 2009:Aug:30:08:55:07 PDT

12:07 you'll to translate to the timezone the logs are from

12:07 mtm: if not weak refs then at least an LRU cache

12:08 cgrand: it doesn't fit every case but I like (binding [foo (memoize foo)] (some code))

12:08 Chouser: cgrand: oh, that's interesting.

12:09 mtm: cgrand: I like it

12:09 Chouser: but some takes 2 args

12:09 * Chouser ducks

12:09 * cgrand frowns at Chouser

12:10 hiredman: http://clojure-log.n01se.net/date/2009-08-30.html#11:51

12:11 mtm: it just seems you have to be really careful with memoize: it's pretty easy to have it retain the head of sequence

12:13 hiredman: thanks, reading it now

12:14 Chouser: anyone know how to get the pid of the current process?

12:16 mtm: I wasn't thinking of using a WeakHashMap; that only uses weak refs for the keys

12:16 stuartsierra: Chouser: there are ways to do it in Sun Java

12:16 Chouser: hm. or with jna I suppose.

12:17 stuartsierra: yeah, nothing in the standard JDK

12:17 Chouser: ok, thanks.

12:20 (.invoke (com.sun.jna.Function/getFunction "c" "getpid") Integer nil)

12:33 hiredman: clojurebot: git 64323d8c6ad4962ac780d4d904b69a891ab312f8

12:34 clojurebot: added ->>

12:50 ngoc: Just a curious question: Java uses camelCase, why Clojure is designed to use hyphen-case?

12:51 eevar: because clojure is a lisp

12:51 stuartsierra: tradition, no other reason

12:51 mabes: ngoc: not a clojure expert by any means, but that is more of clojure's lisp inheritance

12:51 djpowell: Chouser: this works in practice on Sun's JDK, but it is a hack, and not guaranteed: (-> (java.lang.management.ManagementFactory/getRuntimeMXBean) (.getName) (.replaceAll "@.*" ""))

12:55 ngoc: Is there any Clojure book to be published in the near future? I don't know Lisp, the current Clojure book looks like only an introduction.

12:57 I read the first chapter: well, this is introduction. Next chapter: oh, still introduction. Next... still introduction... Last chapter... God, still introduction :D

12:58 crios: +1 ngoc. "Programming Clojure" does not give you the right "mental shift" into Clojure

12:58 this is my experience

12:58 lisppaste8: mtm pasted "pid " at http://paste.lisp.org/display/87654

12:59 mtm: it's a bit more portable (though I haven't tried it on windows)

12:59 djpowell: mtm: I just pasted something similar just above. I can confirm that it works on windows

13:00 mtm: djpowell: argh1 you beat me to it1 ;)

13:00 oops, those 1's were supposed to be !'a (playing with a remapping of my top row on this keyboard)

13:02 I can confirm that it also works on OS X

13:03 so the only thing left: does it work on Android?

13:03 rsynnott: does clojure work on android?

13:04 mtm: I vaguely remember hearing that it did but I can't confirm that

13:04 stuartsierra: rsynnott: it has been demonstrated to work

13:05 dnolen: rsynnott: some work has been done on that. check the mailing list. I also think that is the point of clojure-slim.jar

13:06 hiredman: eh?

13:07 clojure-slim just omits compiled clojure code, certainly not suitable for the android

13:07 dnolen: hiredman: gotcha. I vaguely remember some patches for dalvik and I thought clojure-slim was related.

13:08 hiredman: I don't think there have been dalvik specific patches

13:08 just patches to allow for leaving out the dynamic bits

13:08 since code generation doesn't work on android

13:10 dnolen: hiredman: sounds like patches for dalvik to me ;) but whatever.

13:11 Chouser: clojurescript has also never supported generating code itself.

13:13 hiredman: dnolen: it's also useful in places where the security context does not allow for code generation

13:15 dnolen: hiredman: i see.

13:17 ngoc: Why "some" form does not have question mark ("some?")? Why there is "not-any?" but there is no "any?"?

13:17 (Just a curious question about the API)

13:20 And "some" returns true or nil, not true or false!?

13:20 stuartsierra: "some" returns the thing that made the predicate true

13:20 ,(some #(= 5 %) [1 2 3 4 5 6])

13:20 clojurebot: true

13:20 stuartsierra: no,

13:21 It returns the result of the predicate function.

13:21 ,(some #(when (= 3 %) "yes") [1 2 3 4 5])

13:21 clojurebot: "yes"

13:27 dnolen: back did I miss anything?

13:27 oops wrong channel :)

13:28 ngoc: In http://java.ociweb.com/mark/clojure/article.html, (some #(= % "Mark") stooges) should return nil, I have just reported this typo to the author

13:56 pixelman: Is it possible to make a lazy reverse range? like (range 9000000 1) somehow?

13:59 tmountain: pixelman: (range 10 1 -1)

14:00 pixelman: tmountain: thanks!!

14:00 tmountain: pixelman: np, you know about the doc function right?

14:01 ,(doc range)

14:01 clojurebot: "([end] [start end] [start end step]); Returns a lazy seq of nums from start (inclusive) to end (exclusive), by step, where start defaults to 0 and step to 1."

14:01 tmountain: pixelman: pretty handy... I use it constantly

14:01 pixelman: yep, I just assuemed range would not be able to do it, without looking it up :)

14:02 btw, is there a way I could search and get a list of all functions that works with lists and arrays?

14:06 Chouser: Sure! But you probably want seq functions too, right?

14:06 (find-doc #"seq|list|array")

14:06 pixelman: wow. that's great!

14:06 Chouser: That should keep you busy for a while. ;-)

14:06 pixelman: awesome.

14:51 * Chouser finds it difficult to lurk during a #haskell conversation about syntax and avoid jumping in with unhelpful comments.

14:53 LauJensen: I don't, see you there in a sec

14:58 Someone asked me on my blog to do a Haskell Vs Clojure piece, but which application space does Haskell cover?

15:06 ambient: academic study

15:06 :p

15:07 chouser, you're a better man than I clearly

15:08 LauJensen: prettier anyway :)

15:08 Chouser: er

15:08 LauJensen: This might be a very dumb question, but Haskell has no use in industry ?

15:08 stuartsierra: not necessarily

15:09 I know companies that use OOCaml, for example.

15:09 Makoryu: LauJensen: Yep, it's only useful for processing li... er, parallel distributed... uhm.... Academia. Yeah, that's it. It's strictly a research language.

15:09 Haskell is general purpose.

15:10 There's some company that uses it to make tractors, and of course there are several that write financial apps.

15:10 LauJensen: haha

15:10 That was fun Makoryu :)

15:10 * Chouser just learned about the tractor company

15:11 * Makoryu bows

15:12 tmountain: LauJensen: there's a book called "Real World Haskell"

15:12 LauJensen: it's an appeal to the world that haskell is useful for things besides quicksort

15:12 Makoryu: LauJensen: But seriously, the biggest Haskell apps (aside from the compiler, which serves as a back end to a bunch of logic/theorem languages these days) are probably darcs and xmonad

15:12 tmountain: Makoryu: and pugs...

15:13 LauJensen: All 3 of which are foreign to me

15:13 Chouser: I find Haskell to be quite impressive and I hope one day to be smart enough to use it.

15:13 Makoryu: tmountain: I... can't really vouch for pugs >_>

15:13 LauJensen: Darcs is a DVCS, and xmonad is a tiling window manager

15:13 LauJensen: Ok

15:13 Chouser: What impresses you about iT?

15:13 tmountain: LauJensen: Pugs is a Perl 6 interpreter

15:14 sfuentes: i like xmonad

15:14 ambient: i will be intriqued to use haskell the day someone uses it for actual commercial purposes successfully

15:14 tmountain: I used xmonad for a bit. It's pretty nice, but it's config file basically scared me away form haskell

15:15 Chouser: LauJensen: Haskell is succicnt, appears to have a powerful static type system with inference, has good immutable data structures, encourages pure functions...

15:15 in short, it's not PHP

15:16 tmountain: it also allows oodles of user-defined operators, which makes any new source file completely alien until you determine what the programmer had in mind this time around

15:16 Chouser: and the people who use it seem to love it. Who loves C++?

15:18 LauJensen: Chouser, please explain the term 'powerful static type system'

15:18 ambient: i think C++ is in many cases, the pragmatic choice

15:18 Makoryu: LauJensen: Haskell has a really nice implementation of parametric polymorphism (generics)

15:18 tmountain: LauJensen: http://book.realworldhaskell.org/read/types-and-functions.html

15:18 LauJensen: ambient: pragmatic means "if it works, its good", meaning c++ could never be the pragmatic choise

15:18 Makoryu: LauJensen: It's statically typed, but it uses whole program type inference so you don't usually have to worry about type declarations

15:18 ambient: LauJensen most of Googles Code Jam top coders disagree

15:19 tmountain: haskell is soooo controversial ;-)

15:19 LauJensen: ambient: that tells you something about them doesn't it? :)

15:19 Makoryu: Alright

15:19 Chouser: ambient: yes, people use C++, and perhaps sometimes it's the best choice. But it's been a while since I heard someone who really understands C++ express joy at the idea of using it.

15:19 ambient: i think C++ is way too convoluted that it's even possible to fully understand it

15:19 LauJensen: Makoryu: By parametric polymorphism, do you mean overload of functions based on arity ?

15:20 ambient: personally, im just happy using a simple subset of it

15:20 Makoryu: LauJensen: No. I mean overloading of functions, data structures, and values based on parameterized types

15:20 ambient: LauJensen it tells me that they get things done

15:20 LauJensen: exaple?

15:21 +m

15:21 Makoryu: For example, you'll see type signatures like "[b] -> b" which means "A function that takes a parameter of type 'list of b' and returns a value of type 'b'"

15:21 (Where b can stand for any type)

15:22 So, this will work on [String], [Int], etc.

15:22 That's fairly basic

15:22 manic12: aren't you glad I'm keeping my mouth shut.

15:23 LauJensen: manic12: Yes

15:23 Makoryu: k

15:23 Makoryu: manic12: About the sinister dangers of static typing? ;)

15:23 manic12: no, just in general

15:24 i could go off on that though

15:24 Makoryu: LauJensen: Okay, something cooler: Numeric literals are overloaded. For example, the token 5 can represent an Int, Integer (ie. a bignum), Float, Double, or anything else that implements the typeclass Num

15:25 LauJensen: Makoryu: Similar to Clojures automatic Int -> Bigint ?

15:25 wooby: hi everybody i'm new, i tried to code a solution to a problem from the holloway book from scratch: http://gist.github.com/192966, thanks in advance for ripping it apart ;)

15:25 Makoryu: LauJensen: For literals alone, yes.

15:26 LauJensen: Of course, you have to explicitly convert a value of type Int if you want to use it as a value of type Integer :p

15:26 > [5 :: Int, 5 :: Integer]

15:26 Hmm, lambdabot's gone

15:26 Oh, duh, what channel am I in?

15:26 * Makoryu kicks himself

15:27 Makoryu: LauJensen: Anyway, the above line would cause a type error, since lists have to be homogeneous.

15:28 LauJensen: oh ok

15:29 Makoryu: I should probably send you to #haskell, by the way, to talk about this

15:29 I have to leave soon anyway :p

15:30 LauJensen: Thanks for taking the time

15:30 Makoryu: No sweat

15:31 You'll find other #haskell folks equally willing to help, of course...

15:31 LauJensen: Nice

15:34 wooby: I don't know the problem description, but are you aware that passing a sec like [:p :h :h :t :h :h] will cause the 2x :h not to be filtered?

15:35 wooby: LauJensen: yeah, the problem description is to return the number of sub-sequences of a specified type and length

15:35 so input like [:p :h :h :t :h :h] should return 2

15:35 given type :h and length 2

15:37 LauJensen: ok

15:37 Then you need to rework it :)

15:38 wooby: LauJensen: how do you suggest i improve it?

15:39 LauJensen: Its the partition that's tripping you up, so maybe parse it using take-while and filter those of the length you need

15:40 wooby: LauJensen: is that a better way to do it? it seems to work

15:41 LauJensen: That's how I would do it, but it's good that you ask in here, so hopefully other people can chime in as well if they have improvements

15:42 wooby: i see, thanks

15:45 miltonsilva: hi!

15:45 LauJensen: yo

15:45 miltonsilva: I need some help with a function

15:45 LauJensen: shoot

15:46 miltonsilva: (defn calc [nBlocks & inodes]

15:46 (let [inodes (if (nil? inodes) (/ nBlocks 8) (first inodes))

15:46 iUsageT (/ inodes 128)

15:46 nBData (/ (+ (* 128 (- nBlocks (+ 1 inodes iUsageT))) 4) 129)

15:46 freeCT (/ (- nBData 4) 128)]

15:46 [inodes nBData freeCT]))

15:46 Chousuke: hm

15:46 miltonsilva: hmmm how can I past this in a more readeble maner

15:46 Chousuke: you should use a pastebin :/

15:46 lisppaste8: url

15:46 lisppaste8: To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.

15:46 miltonsilva: thanks

15:46 Chousuke: put it there, it'll be easier for us to help

15:47 lisppaste8: miltonsilva pasted "untitled" at http://paste.lisp.org/display/87670

15:48 Chousuke: to start with, dividing the calculations to multiple lines might make them more readable

15:48 LauJensen: second, whats it supposed to do exactly?

15:49 Chousuke: or you might want to make them their own functions

15:49 miltonsilva: ok, I would like to make this as idiomatic as possible... second is there some func that takes a math expression (infix) and evaluates it?

15:49 Chousuke: also, mixedCase is not very lispy. you should use hyphenated-names instead :)

15:49 miltonsilva: it's just

15:49 ok ;) good tip

15:51 Chousuke: what's the iUsageT supposed to mean anyway?

15:51 miltonsilva: this function is to make some calculations... I need to format a disk (write a formater) and some things depend on others... the inode usage table depends on the number of inodes etc

15:52 (actually i'm going to write it in C but I would like to test this function with clojure)

15:52 Chousuke: but an integer is not an iusagetable? does it signify the count or something? :/

15:53 miltonsilva: iusagetable is the size in blocks of the inode usage table

15:54 Chousuke: and what does nBData signify?

15:54 miltonsilva: number of blocks for data

15:56 you could as well this of it as x y z etc... but some things like the way I verify if inodes were passed, I think theres probably a better way of dealing with arity in this case...

15:58 Chousuke: hmm, right

15:58 you could actually override on arity

15:58 miltonsilva: how do I do that?

16:05 lisppaste8: Chousuke annotated #87670 "suggestion" at http://paste.lisp.org/display/87670#1

16:06 Chousuke: I didn't change the freeCT name for now though

16:06 also I forgot to change the name of the first function :P

16:09 actually it might also help to swap the (* 128 (- blocks (inc (+ inodes iut-blocksize)))) and 4 expressions :)

16:09 miltonsilva: ahah :) I like it

16:11 Chousuke: note though that / in Clojure is exact if you're dealing with integers. if you're relying on truncating behaviour I think you need to be explicit

16:11 ,(/ 3 4)

16:11 clojurebot: 3/4

16:13 miltonsilva: thanks for the tip but, this problem requieres a more complex ajustation system..

16:14 manic12: I know the answer is "it depends", but just to ask the question, what would I use in clojure to represent what I might have used a defvar for in common lisp? (accessible to all threads) an agent?

16:14 miltonsilva: (in order to maximize the number of free blocks of data)

16:14 stuartsierra: manic12: any reference type, stored in a var

16:19 manic12: use def to create it and def again to change it's state?

16:26 stuartsierra: no, do (def thing (ref initial-value))

16:26 then change with (dosync (alter/ref-set thing ...)))

16:27 manic12: ok

16:27 Chousuke: if you want something that's not controlled, you can use an atom

17:41 mtm: any opinions of the book "Let over Lambda"? how much of the content would be relevant to clojure?

17:44 Chouser: mtm: I've never heard of it, but Common Lisp macros have many similarities with Clojure macros.

17:44 I learned macros in CL with "On Lisp" and most of that knowledge came over pretty cleanly.

17:46 none of the debugging, disassembling, or other CL internals are going to be relevant.

17:49 mtm: chouser: thanks, I figured most of the CL stuff wouldn't apply, but it's good o know about the macro simularities

17:50 Chouser: the main difference in the macros themselves are how clojure improves hygene

17:56 Chousuke: if you come from CL I suppose you'll need to understand the namespace qualifying thing and how to get around it and then you're all set :)

17:59 mtm: no real CL experience, but in the dim past I played around with a TI Explorer. I have to say clojure is the most fun I've had programming since my FORTH days (and that was 25 years ago)

18:51 lisppaste8: hamza pasted "mac to string" at http://paste.lisp.org/display/87683

18:52 hamza: hey guys, i am trying to convert a byte array in to mac id string but i get class cast exception?

18:55 Chousuke: hamza: you're not using reduce correctly there.

18:56 stuartsierra: the first argument to your fn should be the accumulated return values of the function

18:56 Chousuke: you might want something like (apply str (map (fn [k v] ...) mac-bytes)))

18:59 stuartsierra: More likely (apply str (map (fn [v] ...) mac-bytes))

19:02 hamza: kk apply worked thx. for reduce i should use one more varible for the accumulation and return that?

19:39 drhodes: ,(union #{1 2} #{3 4})

19:39 clojurebot: java.lang.Exception: Unable to resolve symbol: union in this context

19:40 mtm: ,(clojure.set/union #{1 2} #{3 4})

19:40 clojurebot: #{1 2 3 4}

19:41 drhodes: thanks mtm

19:41 mtm: np

19:47 khora: not trolling, I'm trying to pick a language between Scala and Clojure. What are the advantages of using Clojure over Scala?

19:48 andrewaclt: khora: There are a lot of blog posts that outline the differences between the two.

19:49 khora: andrewaclt: the ones I've found had little substance to it

19:51 hiredman: khora: have you read rhickey's rationale?

19:51 ~why?

19:51 clojurebot: http://clojure.org/rationale

19:51 khora: hiredman: no, I didn't

19:53 hiredman: there are also the intro to clojure videos, in which rhickey mentions a few design decisions that went into the language

19:54 ~blip.tv

19:54 clojurebot: blip.tv is http://clojure.blip.tv/

19:55 khora: hiredman: may I confess you something?

19:55 hiredman: my standard pitch is "LOOK LOOK, SO AWESOME, CAN'T YOU SEE!?!?!" which doesn't work very well

19:56 khora: scala syntax makes me want to cry, and I'm sick of OOP. However, Clojure's lack of support for tools really put me off.

19:56 hiredman: which tools?

19:57 khora: hiredman: textmate

19:57 hiredman: oh, uh, well, uh...

19:58 really? textmate?

19:58 dnolen: khora: why not netbeans+enclojure. can't get more user friendly than that.

19:58 slashus2: khora: Have you tried IDE plugins? enclojure?

19:58 andrewaclt: hiredman: pretty sure there is a clojure textmate bundle

19:58 hiredman: I know there is

19:58 khora: no I didn't try IDEs because I thought they would be overkill for single scripts

19:58 * mDuff tends to revert to Emacs when working with LISPy languages -- using an editor which has been developed with that class of language in mind for *decades* makes sense.

19:59 hiredman: I assumed he is saying the textmate bundle isn't very good

19:59 andrewaclt: hiredman: sorry that was to khora :)

19:59 hiredman: ~google textmate clojure bundle

19:59 clojurebot: First, out of 638 results is:

19:59 nullstyle&#39;s clojure-tmbundle at master - GitHub

19:59 http://github.com/nullstyle/clojure-tmbundle/tree/master

19:59 khora: the textmate bundle I found didn't work for me

20:00 hiredman: clojurebot: vim?

20:00 clojurebot: Gesundheit!

20:00 hiredman: bah

20:00 clojurebot: vimclojure

20:00 clojurebot: vimclojure is http://kotka.de/projects/clojure/vimclojure.html

20:00 khora: it said that I didn't have clojure installed, then proceeded to install it for me, but next time... same thing

20:00 hiredman: clojurebot: vim is <reply>http://kotka.de/projects/clojure/vimclojure.html

20:00 clojurebot: Ack. Ack.

20:01 ambient: there's also vim plugin for netbeans which is pretty nice :)

20:01 khora: netbeans+enclojure is the state of the art?

20:01 hiredman: I installed netbeans once :(

20:01 khora: most here seem to use emacs

20:02 I installed emacs once too :(

20:02 khora: hiredman: I tried to get imto emacs

20:02 h

20:02 hiredman: too much all at once

20:02 hiredman: anyway, I use vim, it works, and I don't have to think about it

20:03 khora: hiredman: I may have to use vim too

20:14 trying to install vimclojure I get an error


20:16 dnolen: khora: netbeans+enclojure = no configuration. you can just start a project, make a script, be done wit it.

20:17 wavis: i use jedit, which has an edit mode for clojure that is pretty good. http://github.com/djspiewak/jedit-modes/blob/master/clojure.xml

23:24 hamza: how do i set a field in a class?

23:40 rboyd: hamza: I think you use set! http://clojure.org/java_interop

Logging service provided by n01se.net