#clojure logs

2009-09-24

00:10mabescan anyone explain to me why I'm getting this error?
00:10mabes,(def l '(1 2 3)) (defn look_at_first (first l))
00:10clojurebotDENIED
00:10mabeshrm.. well the error is: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Symbol (NO_SOURCE_FILE:22)
00:11mabesI can say (first l) but I can't say than in a function
00:11mabesit seems like l doesn't resolve to a sequence in the function for some reason
00:12hiredmanok
00:12hiredman,(doc defn)
00:12clojurebot"([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"
00:13hiredmandefn is for defining functions
00:13mabesright, which is what I want to do.. I see what I am doing wrong though.. I need to have an empty vector
00:13mabeseven if I don't have any args
00:13hiredmanyes
00:15hiredmanI recommend looking at example code, of which there is some on clojure.org, some on core.clj, and some in the pastebin
00:16hiredmanhttp://delicious.com/clojurebot/pastbin <-- not all of the code here is good, but there is some good code there
00:17mabesok 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
00:18hiredmanhttp://delicious.com/clojurebot/pastbin+chouser should all be good
08:29chouserhttp://n01se.net/paste/4CK -- Currying
08:57hamzahey 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?
08:57Fossiif you don't want to find new files or directoriess
08:58hamzathat 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?
09:02Chouseryou'd have to re-run memoize itself and start over with a completely empty cache.
09:03hamzakk thx.
09:04Chouseror write your own memoize so that you can delete subsets of the cache as needed
09:06hamzais there a restriction for memoize or can i use it on any funtion i want?
09:10Chousernothing will stop you from using it on any clojure function, but of course it may behave weirdly if used on non-pure functions.
09:11hamzakk thx. all the functions i am planning to use on disk io functions.
09:11ChouserI would generally consider those non-pure, so use with care.
09:12Chouser,(let [p (memoize println)] (doseq [i [1 2 3 2 1 0 1 2]] (p i)))
09:12clojurebot1 2 3 0
09:13hamzafiles 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?
09:14ChouserI guess if you know when the files change and clear caches as appropriate, that would count as using with care.
09:14hamzakk thx.
09:50vyHi! 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?
09:51triyoWas 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.
09:52triyoAny suggestions welcome pls.
09:54crioshello vy
09:54criosI also donwloaded those examples, but never used (add-classpath
09:55triyovy: Where you running the example from? Was you command?
09:56triyo*what's your command you use to run example
09:57vycrios: 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.
09:57vytriyo: 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"
09:59criosexist file:///tmp/code/examples/snake ?
10:00Chouserin general, add-classpath is unreliable, though I don't know if that is the problem in this specific case.
10:01vycrios: `ls -l /tmp/code/examples/snake.clj' returns right stuff.
10:04dnolenvy: you need to add paths to your swank-clojure-extra-classpaths in your .emacs file.
10:04triyoThat should work, perhaps try load-file
10:05dnolenvy: unfortunately this is not dynamic you'll have to edit your .emacs file and restart Emacs.
10:05vydnolen: Restarting current clojure session is what I was trying to avoid...
10:05triyo,(doc load-file)
10:05clojurebot"([name]); Sequentially read and evaluate the set of forms contained in the file."
10:06dnolenvy: add-classpath probably needs to absolute, did you try that?
10:07vyabsolute?
10:08triyoYou dont have to restart emacs after changing .emacs, you can eval the changes in emacs buffer
10:08dnolenvy: on my machine when I've add-classpath it always "/full/path/to/my/project/folder"
10:08dnolentriyo: no for that particular var, it's a design problem.
10:08triyovy: try without file:// protocol
10:09vydnolen: (add-classpath "/tmp/code") => no protocol: /tmp/code
10:09triyoHehe
10:10vydnolen: You sure add-classpath works with strings without a protocol?
10:10rsynnottah, classpaths
10:10dnolenvy: pretty sure at one point I worked on a halfbaked Clojure project management tool and use it that way.
10:11triyo,(doc add-classpath)
10:11clojurebot"([url]); Adds the url (String or URL object) to the classpath per URLClassLoader.addURL"
10:11Chouserrsynnott: yes
10:11dnolenvy: OOPS. just check my code, you do need the protocol.
10:12dnolenwhen in doubt check the code :)
10:13ngochi, 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:14Chouserngoc: Clojure uses Java threads which are usually full OS threads.
10:14triyorsynnott: 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:15Chouserngoc: 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:17ngocI come to clojure from erlang. it seems that clojure focuses on data, while erlang focuses on processes
10:18Chouserngoc: that's an interesting summary.
10:19ngocin 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:19Chouserone might also argue that Clojure focuses on functions.
10:19ngocis there any way to create instance of agent in clojure? in the feeling of erlang's gen_server?
10:20Chouseran 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:21Chouserbut 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:24dnolenvy: for what it's worth I just tried a quick test myself of add-classpath and it just worked.
10:24ngocFor 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:24ngocHow can I do this in Clojure?
10:26ngocI think I will have to create a thread and wrap an agent inside that thread. Is this the right way to do?
10:26stuartsierraI would just use a function that returns a new agent each time it's called.
10:27Chouserngoc: 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:29Fossihaving done my share of erlang and clojure, i don't see where gen-server or agents come into play
10:29ngocAh, then all room should be put to a map of :room-id => agent, right?
10:30Fossithen, i don't really understand what a 'room' is, so that might be the problem
10:30Chouserngoc: 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:31Chouser(def all-rooms (ref {:the-first-room (ref {:turn :player-1 :board '[x o o, o x - ...] ...
10:31ngocThat's what I mean "data". How about code? When a player make a move, how to make the room "react"?
10:33ngocFossi: a room is a thing that has a state and some code attached to it
10:34Chouser(alter (:the-first-room @all-rooms) apply-players-move the-move)
10:34Fossii'd argue that that's a bad (unpure) construct in most cases
10:34Chouserwhere 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:34Fossii understand it from a message passing point of view, but i rarely find myself modelling things like that in clojure.
10:35Fossimight be related to my clojure problem-domain though
10:35Chouserthat 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:35ChouserAs such, apply-players-move will be easy to test at the repl or in unit tests, etc.
10:36Chouser...and completely thread safe, so you can spawn as many threads as needed to process incoming player moves.
10:39ngocCan 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:41ngocDoes the central variable become the bottle neck: all threads must do some kind of locking on this variable?
10:41ngocIf there are tens of thousands of players, the variable will become the bottle neck?
10:42Chouser(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:43Chouserngoc: 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:44Chouserngoc: 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:45Chouserso in short: no bottleneck.
10:45Chouserthe 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:46Chouserif 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:48ngocIs 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:49stuartsierraSure, just define a var.
10:49ngocI mean when all the refs are not put inside a single collection to avoid bottle neck...
10:49ChouserI 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:50triyoA map of refs perhaps then you can lookup re by :key
10:50rhickeyj.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:52ngocIs map in Clojure the same as ConcurrentHashMap? Or do I have to use ConcurrentHashMap explicitly?
10:52stuartsierrarhickey: is a namespace basically a ConcurrentHashMap of vars?
10:52Chouserngoc: the latter
10:53hiredmanrhickey: 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:53Chouserstuartsierra: the list of namespaces is a ConcurrentHashMap
10:53rhickeyone 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:54Chouserstuartsierra: each namespace is basically (atom {})
10:54rhickeynamespaces use both strrategies
10:54stuartsierraok
10:55rhickeythe 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:55rhickeyj.u.c. collections make good caches/registries
10:56rhickeyi.e. single lookup vs really treating the collection as a value
10:57ngocI have another question. How to have a timeout callback? For example the callback function will be called after 30s of room inactivity?
10:57rhickeyhiredman: custom action that does what?
11:05ngocI 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:05stuartsierrangoc: java has a Timer class that does this
11:06mccraigis there a destructuring way of defaulting an optional parameters value ?
11:09dnolenmccraig: have you looked at clojure.contrib.def defnk, it's pretty handy.
11:11drewr+1
11:12mccraigthat should do the trick. thx
11:16Chouserngoc: java.util.Timer allows you to schedule multiple events in a single thread
11:33Chouseris there a way to do an unsigned-bit-shift-right?
11:36ngocThe 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:37Chouserngoc: that's your call of course. I think if your timer tasks simply send off agents you'll probably be fine.
11:37ngocAh, what a trick!
11:40cgrandChouser: no
11:40ngocIn the API (http://clojure.org/api) I see there are some "shift" functions
11:41ngocCan't (bit-shift-right x n) be used?
11:41Chouser,(bit-shift-right -12345 8)
11:41clojurebot-49
11:42Chouseranyway, I think I have a sufficient work-around here.
11:42tmountainChouser: is this helpful? http://www.mail-archive.com/clojure@googlegroups.com/msg13789.html
11:43Chousertmountain: ah, that's what I was doing. But that post gives me confidence I'm doing the right thing, thanks!
11:43tmountainChouser: happy to help
12:04mtmis there any work in progress to to enhance 'memoize'? I've got a few ideas but didn't want to reinvent the wheel
12:04ambienthow can it be enhanced?
12:05mtmright now, the cache can grow without bound
12:05mtmalso, it holds a strong reference to the return value
12:05ambientnews for me, i thought it had a bound
12:05mtmnope
12:06hiredmanmtm: it's been discussed here in the paste
12:06hiredmanpast
12:06ambientclojure has weak refs?
12:06hiredman~logs
12:06clojurebotlogs is http://clojure-log.n01se.net/
12:06mtmthanks, I'll dig into it
12:06hiredmanhmm
12:06mtmbut, yes, I'd like to use weak refs in the cache
12:07Chouserambient: java has weak references, so yes
12:07mtmor, at least, be able to pass in a user defined cache
12:07ChouserI don't know that weak references would always be appropriate for a memoize fn
12:07hiredmanfor example around 2009:Aug:30:08:55:07 PDT
12:07hiredmanyou'll to translate to the timezone the logs are from
12:07mtmif not weak refs then at least an LRU cache
12:08cgrandit doesn't fit every case but I like (binding [foo (memoize foo)] (some code))
12:08Chousercgrand: oh, that's interesting.
12:09mtmcgrand: I like it
12:09Chouserbut some takes 2 args
12:10hiredmanhttp://clojure-log.n01se.net/date/2009-08-30.html#11:51
12:11mtmit just seems you have to be really careful with memoize: it's pretty easy to have it retain the head of sequence
12:13mtmhiredman: thanks, reading it now
12:14Chouseranyone know how to get the pid of the current process?
12:16mtmI wasn't thinking of using a WeakHashMap; that only uses weak refs for the keys
12:16stuartsierraChouser: there are ways to do it in Sun Java
12:16Chouserhm. or with jna I suppose.
12:17stuartsierrayeah, nothing in the standard JDK
12:17Chouserok, thanks.
12:20Chouser(.invoke (com.sun.jna.Function/getFunction "c" "getpid") Integer nil)
12:33hiredmanclojurebot: git 64323d8c6ad4962ac780d4d904b69a891ab312f8
12:34clojurebotadded ->>
12:50ngocJust a curious question: Java uses camelCase, why Clojure is designed to use hyphen-case?
12:51eevarbecause clojure is a lisp
12:51stuartsierratradition, no other reason
12:51mabesngoc: not a clojure expert by any means, but that is more of clojure's lisp inheritance
12:51djpowellChouser: this works in practice on Sun's JDK, but it is a hack, and not guaranteed: (-> (java.lang.management.ManagementFactory/getRuntimeMXBean) (.getName) (.replaceAll "@.*" ""))
12:55ngocIs 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:57ngocI read the first chapter: well, this is introduction. Next chapter: oh, still introduction. Next... still introduction... Last chapter... God, still introduction :D
12:58crios+1 ngoc. "Programming Clojure" does not give you the right "mental shift" into Clojure
12:58criosthis is my experience
12:58lisppaste8mtm pasted "pid " at http://paste.lisp.org/display/87654
12:59mtmit's a bit more portable (though I haven't tried it on windows)
12:59djpowellmtm: I just pasted something similar just above. I can confirm that it works on windows
13:00mtmdjpowell: argh1 you beat me to it1 ;)
13:00mtmoops, those 1's were supposed to be !'a (playing with a remapping of my top row on this keyboard)
13:02mtmI can confirm that it also works on OS X
13:03mtmso the only thing left: does it work on Android?
13:03rsynnottdoes clojure work on android?
13:04mtmI vaguely remember hearing that it did but I can't confirm that
13:04stuartsierrarsynnott: it has been demonstrated to work
13:05dnolenrsynnott: some work has been done on that. check the mailing list. I also think that is the point of clojure-slim.jar
13:06hiredmaneh?
13:07hiredmanclojure-slim just omits compiled clojure code, certainly not suitable for the android
13:07dnolenhiredman: gotcha. I vaguely remember some patches for dalvik and I thought clojure-slim was related.
13:08hiredmanI don't think there have been dalvik specific patches
13:08hiredmanjust patches to allow for leaving out the dynamic bits
13:08hiredmansince code generation doesn't work on android
13:10dnolenhiredman: sounds like patches for dalvik to me ;) but whatever.
13:11Chouserclojurescript has also never supported generating code itself.
13:13hiredmandnolen: it's also useful in places where the security context does not allow for code generation
13:15dnolenhiredman: i see.
13:17ngocWhy "some" form does not have question mark ("some?")? Why there is "not-any?" but there is no "any?"?
13:17ngoc(Just a curious question about the API)
13:20ngocAnd "some" returns true or nil, not true or false!?
13:20stuartsierra"some" returns the thing that made the predicate true
13:20stuartsierra,(some #(= 5 %) [1 2 3 4 5 6])
13:20clojurebottrue
13:20stuartsierrano,
13:21stuartsierraIt returns the result of the predicate function.
13:21stuartsierra,(some #(when (= 3 %) "yes") [1 2 3 4 5])
13:21clojurebot"yes"
13:27dnolenback did I miss anything?
13:27dnolenoops wrong channel :)
13:28ngocIn http://java.ociweb.com/mark/clojure/article.html, (some #(= % "Mark") stooges) should return nil, I have just reported this typo to the author
13:56pixelmanIs it possible to make a lazy reverse range? like (range 9000000 1) somehow?
13:59tmountainpixelman: (range 10 1 -1)
14:00pixelmantmountain: thanks!!
14:00tmountainpixelman: np, you know about the doc function right?
14:01tmountain,(doc range)
14:01clojurebot"([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:01tmountainpixelman: pretty handy... I use it constantly
14:01pixelmanyep, I just assuemed range would not be able to do it, without looking it up :)
14:02pixelmanbtw, is there a way I could search and get a list of all functions that works with lists and arrays?
14:06ChouserSure! But you probably want seq functions too, right?
14:06Chouser(find-doc #"seq|list|array")
14:06pixelmanwow. that's great!
14:06ChouserThat should keep you busy for a while. ;-)
14:06pixelmanawesome.
14:53LauJensenI don't, see you there in a sec
14:58LauJensenSomeone asked me on my blog to do a Haskell Vs Clojure piece, but which application space does Haskell cover?
15:06ambientacademic study
15:06ambient:p
15:07ambientchouser, you're a better man than I clearly
15:08LauJensenprettier anyway :)
15:08Chouserer
15:08LauJensenThis might be a very dumb question, but Haskell has no use in industry ?
15:08stuartsierranot necessarily
15:09stuartsierraI know companies that use OOCaml, for example.
15:09MakoryuLauJensen: Yep, it's only useful for processing li... er, parallel distributed... uhm.... Academia. Yeah, that's it. It's strictly a research language.
15:09MakoryuHaskell is general purpose.
15:10MakoryuThere's some company that uses it to make tractors, and of course there are several that write financial apps.
15:10LauJensenhaha
15:10LauJensenThat was fun Makoryu :)
15:12tmountainLauJensen: there's a book called "Real World Haskell"
15:12tmountainLauJensen: it's an appeal to the world that haskell is useful for things besides quicksort
15:12MakoryuLauJensen: 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:12tmountainMakoryu: and pugs...
15:13LauJensenAll 3 of which are foreign to me
15:13ChouserI find Haskell to be quite impressive and I hope one day to be smart enough to use it.
15:13Makoryutmountain: I... can't really vouch for pugs >_>
15:13MakoryuLauJensen: Darcs is a DVCS, and xmonad is a tiling window manager
15:13LauJensenOk
15:13LauJensenChouser: What impresses you about iT?
15:13tmountainLauJensen: Pugs is a Perl 6 interpreter
15:14sfuentesi like xmonad
15:14ambienti will be intriqued to use haskell the day someone uses it for actual commercial purposes successfully
15:14tmountainI used xmonad for a bit. It's pretty nice, but it's config file basically scared me away form haskell
15:15ChouserLauJensen: Haskell is succicnt, appears to have a powerful static type system with inference, has good immutable data structures, encourages pure functions...
15:15Chouserin short, it's not PHP
15:16tmountainit 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:16Chouserand the people who use it seem to love it. Who loves C++?
15:18LauJensenChouser, please explain the term 'powerful static type system'
15:18ambienti think C++ is in many cases, the pragmatic choice
15:18MakoryuLauJensen: Haskell has a really nice implementation of parametric polymorphism (generics)
15:18tmountainLauJensen: http://book.realworldhaskell.org/read/types-and-functions.html
15:18LauJensenambient: pragmatic means "if it works, its good", meaning c++ could never be the pragmatic choise
15:18MakoryuLauJensen: It's statically typed, but it uses whole program type inference so you don't usually have to worry about type declarations
15:18ambientLauJensen most of Googles Code Jam top coders disagree
15:19tmountainhaskell is soooo controversial ;-)
15:19LauJensenambient: that tells you something about them doesn't it? :)
15:19LauJensenMakoryu: Alright
15:19Chouserambient: 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:19ambienti think C++ is way too convoluted that it's even possible to fully understand it
15:19LauJensenMakoryu: By parametric polymorphism, do you mean overload of functions based on arity ?
15:20ambientpersonally, im just happy using a simple subset of it
15:20MakoryuLauJensen: No. I mean overloading of functions, data structures, and values based on parameterized types
15:20ambientLauJensen it tells me that they get things done
15:20LauJensenexaple?
15:21LauJensen+m
15:21MakoryuFor 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:21Makoryu(Where b can stand for any type)
15:22MakoryuSo, this will work on [String], [Int], etc.
15:22MakoryuThat's fairly basic
15:22manic12aren't you glad I'm keeping my mouth shut.
15:23LauJensenmanic12: Yes
15:23LauJensenMakoryu: k
15:23Makoryumanic12: About the sinister dangers of static typing? ;)
15:23manic12no, just in general
15:24manic12i could go off on that though
15:24MakoryuLauJensen: 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:25LauJensenMakoryu: Similar to Clojures automatic Int -> Bigint ?
15:25woobyhi 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:25MakoryuLauJensen: For literals alone, yes.
15:26MakoryuLauJensen: 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:26Makoryu> [5 :: Int, 5 :: Integer]
15:26MakoryuHmm, lambdabot's gone
15:26MakoryuOh, duh, what channel am I in?
15:27MakoryuLauJensen: Anyway, the above line would cause a type error, since lists have to be homogeneous.
15:28LauJensenoh ok
15:29MakoryuI should probably send you to #haskell, by the way, to talk about this
15:29MakoryuI have to leave soon anyway :p
15:30LauJensenThanks for taking the time
15:30MakoryuNo sweat
15:31MakoryuYou'll find other #haskell folks equally willing to help, of course...
15:31LauJensenNice
15:34LauJensenwooby: 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:35woobyLauJensen: yeah, the problem description is to return the number of sub-sequences of a specified type and length
15:35woobyso input like [:p :h :h :t :h :h] should return 2
15:35woobygiven type :h and length 2
15:37LauJensenok
15:37LauJensenThen you need to rework it :)
15:38woobyLauJensen: how do you suggest i improve it?
15:39LauJensenIts the partition that's tripping you up, so maybe parse it using take-while and filter those of the length you need
15:40woobyLauJensen: is that a better way to do it? it seems to work
15:41LauJensenThat'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:42woobyi see, thanks
15:45miltonsilvahi!
15:45LauJensenyo
15:45miltonsilvaI need some help with a function
15:45LauJensenshoot
15:46miltonsilva(defn calc [nBlocks & inodes]
15:46miltonsilva (let [inodes (if (nil? inodes) (/ nBlocks 8) (first inodes))
15:46miltonsilva iUsageT (/ inodes 128)
15:46miltonsilva nBData (/ (+ (* 128 (- nBlocks (+ 1 inodes iUsageT))) 4) 129)
15:46miltonsilva freeCT (/ (- nBData 4) 128)]
15:46miltonsilva [inodes nBData freeCT]))
15:46Chousukehm
15:46miltonsilvahmmm how can I past this in a more readeble maner
15:46Chousukeyou should use a pastebin :/
15:46Chousukelisppaste8: url
15:46lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
15:46miltonsilvathanks
15:46Chousukeput it there, it'll be easier for us to help
15:47lisppaste8miltonsilva pasted "untitled" at http://paste.lisp.org/display/87670
15:48Chousuketo start with, dividing the calculations to multiple lines might make them more readable
15:48LauJensensecond, whats it supposed to do exactly?
15:49Chousukeor you might want to make them their own functions
15:49miltonsilvaok, 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:49Chousukealso, mixedCase is not very lispy. you should use hyphenated-names instead :)
15:49miltonsilvait's just
15:49miltonsilvaok ;) good tip
15:51Chousukewhat's the iUsageT supposed to mean anyway?
15:51miltonsilvathis 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:52miltonsilva(actually i'm going to write it in C but I would like to test this function with clojure)
15:52Chousukebut an integer is not an iusagetable? does it signify the count or something? :/
15:53miltonsilva iusagetable is the size in blocks of the inode usage table
15:54Chousukeand what does nBData signify?
15:54miltonsilvanumber of blocks for data
15:56miltonsilvayou 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:58Chousukehmm, right
15:58Chousukeyou could actually override on arity
15:58miltonsilvahow do I do that?
16:05lisppaste8Chousuke annotated #87670 "suggestion" at http://paste.lisp.org/display/87670#1
16:06ChousukeI didn't change the freeCT name for now though
16:06Chousukealso I forgot to change the name of the first function :P
16:09Chousukeactually it might also help to swap the (* 128 (- blocks (inc (+ inodes iut-blocksize)))) and 4 expressions :)
16:09miltonsilvaahah :) I like it
16:11Chousukenote 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:11Chousuke,(/ 3 4)
16:11clojurebot3/4
16:13miltonsilvathanks for the tip but, this problem requieres a more complex ajustation system..
16:14manic12I 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:14miltonsilva(in order to maximize the number of free blocks of data)
16:14stuartsierramanic12: any reference type, stored in a var
16:19manic12use def to create it and def again to change it's state?
16:26stuartsierrano, do (def thing (ref initial-value))
16:26stuartsierrathen change with (dosync (alter/ref-set thing ...)))
16:27manic12ok
16:27Chousukeif you want something that's not controlled, you can use an atom
17:41mtmany opinions of the book "Let over Lambda"? how much of the content would be relevant to clojure?
17:44Chousermtm: I've never heard of it, but Common Lisp macros have many similarities with Clojure macros.
17:44ChouserI learned macros in CL with "On Lisp" and most of that knowledge came over pretty cleanly.
17:46Chousernone of the debugging, disassembling, or other CL internals are going to be relevant.
17:49mtmchouser: thanks, I figured most of the CL stuff wouldn't apply, but it's good o know about the macro simularities
17:50Chouserthe main difference in the macros themselves are how clojure improves hygene
17:56Chousukeif 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:59mtmno 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:51lisppaste8hamza pasted "mac to string" at http://paste.lisp.org/display/87683
18:52hamzahey guys, i am trying to convert a byte array in to mac id string but i get class cast exception?
18:55Chousukehamza: you're not using reduce correctly there.
18:56stuartsierrathe first argument to your fn should be the accumulated return values of the function
18:56Chousukeyou might want something like (apply str (map (fn [k v] ...) mac-bytes)))
18:59stuartsierraMore likely (apply str (map (fn [v] ...) mac-bytes))
19:02hamzakk apply worked thx. for reduce i should use one more varible for the accumulation and return that?
19:39drhodes,(union #{1 2} #{3 4})
19:39clojurebotjava.lang.Exception: Unable to resolve symbol: union in this context
19:40mtm,(clojure.set/union #{1 2} #{3 4})
19:40clojurebot#{1 2 3 4}
19:41drhodesthanks mtm
19:41mtmnp
19:47khoranot trolling, I'm trying to pick a language between Scala and Clojure. What are the advantages of using Clojure over Scala?
19:48andrewacltkhora: There are a lot of blog posts that outline the differences between the two.
19:49khoraandrewaclt: the ones I've found had little substance to it
19:51hiredmankhora: have you read rhickey's rationale?
19:51hiredman~why?
19:51clojurebothttp://clojure.org/rationale
19:51khorahiredman: no, I didn't
19:53hiredmanthere are also the intro to clojure videos, in which rhickey mentions a few design decisions that went into the language
19:54hiredman~blip.tv
19:54clojurebotblip.tv is http://clojure.blip.tv/
19:55khorahiredman: may I confess you something?
19:55hiredmanmy standard pitch is "LOOK LOOK, SO AWESOME, CAN'T YOU SEE!?!?!" which doesn't work very well
19:56khorascala 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:56hiredmanwhich tools?
19:57khorahiredman: textmate
19:57hiredmanoh, uh, well, uh...
19:58hiredmanreally? textmate?
19:58dnolenkhora: why not netbeans+enclojure. can't get more user friendly than that.
19:58slashus2khora: Have you tried IDE plugins? enclojure?
19:58andrewaclthiredman: pretty sure there is a clojure textmate bundle
19:58hiredmanI know there is
19:58khorano I didn't try IDEs because I thought they would be overkill for single scripts
19:59hiredmanI assumed he is saying the textmate bundle isn't very good
19:59andrewaclthiredman: sorry that was to khora :)
19:59hiredman~google textmate clojure bundle
19:59clojurebotFirst, out of 638 results is:
19:59clojurebotnullstyle&#39;s clojure-tmbundle at master - GitHub
19:59clojurebothttp://github.com/nullstyle/clojure-tmbundle/tree/master
19:59khorathe textmate bundle I found didn't work for me
20:00hiredmanclojurebot: vim?
20:00clojurebotGesundheit!
20:00hiredmanbah
20:00hiredmanclojurebot: vimclojure
20:00clojurebotvimclojure is http://kotka.de/projects/clojure/vimclojure.html
20:00khorait said that I didn't have clojure installed, then proceeded to install it for me, but next time... same thing
20:00hiredmanclojurebot: vim is <reply>http://kotka.de/projects/clojure/vimclojure.html
20:00clojurebotAck. Ack.
20:01ambientthere's also vim plugin for netbeans which is pretty nice :)
20:01khoranetbeans+enclojure is the state of the art?
20:01hiredmanI installed netbeans once :(
20:01hiredmankhora: most here seem to use emacs
20:02hiredmanI installed emacs once too :(
20:02khorahiredman: I tried to get imto emacs
20:02khorah
20:02khorahiredman: too much all at once
20:02hiredmananyway, I use vim, it works, and I don't have to think about it
20:03khorahiredman: I may have to use vim too
20:14khoratrying to install vimclojure I get an error
20:14khoraBUILD FAILED
20:16dnolenkhora: netbeans+enclojure = no configuration. you can just start a project, make a script, be done wit it.
20:17wavisi use jedit, which has an edit mode for clojure that is pretty good. http://github.com/djspiewak/jedit-modes/blob/master/clojure.xml
23:24hamzahow do i set a field in a class?
23:40rboydhamza: I think you use set! http://clojure.org/java_interop