#clojure logs

2011-08-27

00:06joshnzHi all. I'm trying to learn clojure and my heads going round in circles trying to get emacs/slime/clojure setup. Does anyone here have time to please provide some guidance?
00:09sridanother clojure web framework - http://ringfinger.floatboth.com/
00:12amalloydnolen: i don't understand how much happens at compile time vs runtime. could the method bodies at line 37 be typehinted?
00:12taliossrid: looks interesting - yours?
00:12amacjoshnz: http://www.dreamux.com/community/getting-started-with-clojure-setup.php
00:12sridtalios: nope, just found that by browsing reddit
00:12amacthis is pretty much up-to-date
00:12hiredmanugh
00:12hiredmanno
00:12hiredmanamac: not
00:13hiredmanblog posts are horrible, and always out of date
00:13hiredmanread the swank-clojure readme, and follow the 3 steps listed there
00:13dnolenamalloy: why would method bodies need typehints?
00:13joshnzI've just been looking at swank-clojure latest readme
00:13amachiredman: fair enough, though I tried to write this one comprehensively and somewhat recently
00:14taliosI'd go so far as to say for a newbie - stay away from emacs/slime and use clooj - http://dev.clojure.org/display/doc/getting+started+with+Clooj - so much easier for a newbie
00:14amacthough it only covers setup on osx
00:14hiredmanamac: well, you should have read the swank-clojure readme
00:14amalloydnolen: even better question. i guess i don't even know if extend-type automatically hints stuff. i suppose it should
00:14dnolenamalloy: it does.
00:14amactrue.
00:14amalloywell then
00:14hiredmanamac: lein-swank hasn't been required for a long time now
00:14amalloycarry on being clever, i'll just keep making bad suggestions
00:15hiredmanhttps://github.com/technomancy/swank-clojure <-- 3 steps under usage, all you need to do
00:15amacgah, you're right.
00:15hiredmanyou can run into issues with osx, because it doesn't give cocoa emacs the right path, it might be able to find lein unless you manually set your path
00:15hiredmanmight not
00:16joshnzemacs 23.3. clojure-mode 1.10.0 installed via emacs-starter-kit from marmalade.
00:16joshnzlein plugin install swank-clojure 1.3.2. done
00:16joshnzFrom inside a project, invoke M-x clojure-jack-in
00:17amacjoshnz: working?
00:17joshnzIt just says "starting swank server...." but nothing else
00:17amacyou need a project.clj
00:17taliosjoshnz: another kiwi clojurian? nice :)
00:17hiredmanit can take some time, you should have a *swank* buffer start to op up
00:17amacgo to a directory and type lein new
00:18joshnzyeah, I created a lein project. I've open the project.clj file in emacs
00:18amacthen open src/project/core.clj and do mx clojure-jack-in again
00:18amacand it can take a while
00:18hiredmanif clojure-jack-in doesn't work, and you don't want to try and debug it, you can run `lein swank` in a shell, use M-x slime-connect
00:19amachiredman: clj-jack-in doesn't really give much feedback for debugging
00:19hiredmandepends
00:20hiredman*shrug*
00:20joshnzdoes clojure-jack-in just use clojure-mode's own logic to talk to the swank server? Does it bypass slime totally?
00:20amacit starts the swank server and then fires up the slime connection
00:21amacbasically it starts both sides of the conversation for you
00:21hiredmanclojure-jack-in pulls a copy of slime that is known to work with swank-clojure out of the swank-clojure jar and loads it into emacs
00:21amacdoin lein swank from your project will start the server manually, and mx slime-connect starts slime manually
00:21joshnzah...I've found the swank buffer: /bin/bash: lein: command not found... hmm...
00:21hiredmanright
00:21hiredmanjoshnz: osx right?
00:21joshnzyup
00:21hiredmanthis is the exact issue I mentioned
00:21joshnzit's on the path for terminal
00:22hiredmansure, but osx doesn't read your dotfiles when launch gui apps
00:22taliosjoshnz: what part of nz are you in?
00:22hiredmanlaunching
00:22joshnzhamilton
00:22duck1123I never have had much luck getting path working right for osx emacs
00:22hiredman(setenv "PATH" "...:whereverleinis:...")
00:22taliosjoshnz: ahh- bit to far to often a inhouse clojure tutorial pair session then :) Auckland here
00:24hiredmanif you want your env variables to be populated to gui apps, I believe you need to load them into launchd somehow, or write them up in some xml file
00:24joshnzno prob ;) At least I've got a bit more a lead on what the issue is. The problem following blog posts and video tuts as mentioned earlier is that all have a different way and none of them are correct any more ;)
00:25taliosjoshnz: that being said, I've been thinking of reasons for a road-trip weekend to hamilton. been too long since I've visitied folk down there.
00:26duck1123http://www.astro.washington.edu/users/rowen/AquaEnvVar.html
00:26joshnzhow is it that clojure-mode knows where to find swank-clojure? Does it depend on lein?
00:27hiredmanit uses lein's plugin system
00:27joshnz(I should probably just read the clojure-jack-in code ;)
00:27hiredmanlein plugin install makes swank-clojure available for all projects as a user level plugin
00:29joshnzthanks for the link duck1123.
00:31hiredmanlaunchctl also has a setenv cmd
00:37joshnzPossibly the easiest thing right now without mucking around with the system is to simply append my lein path to the PATH var in emacs. Something like (setenv (append "/usr/local/bin" (getenv "PATH"))) but that's not quite working..
00:37joshnzNot crash hot on my elisp either.. but it's only been a few days ;)
00:38hiredmanPATH is a string
00:38hiredmanso you need to use stringconcat or something
00:38hiredmanjust (concat ...)
00:38hiredmanand you'll need a :
00:39joshnzah so that's what's happening :) I
00:39joshnzIt's outputting my new path as a vector of char bytes
00:39joshnzlol. Makes sense
00:40joshnzgoogle's good: (setenv "PATH" (concat "your-lein-dir:" (getenv "PATH")))
00:43hiredmanyou could actually have emacs fork your shell and echo $PATH
00:45joshnzNow I get an error in the process filter: Symbol's value as variable is void: Process [2 times]. This is while loading slime from the jar it appears.
00:46joshnzI'll restart emacs. I'm assuming the swank server is shut down when I do this?
00:46hiredmanif you kill the *swank* buffer it will die
00:47hiredmanbut yes, closing emacs with do that
00:47joshnzyup, that would have been the active process I just told emacs to kill :)
00:48hiredman (setenv "PATH" (shell-command-to-string "echo $PATH")) ; works pretty nicely
00:48hiredmanhmmm, maybe not, I should try it on a clean emacs
00:49joshnzyeah, I've got some other similar suggestions from google groups... there's env-var-from-shell
00:50joshnzBut I'm connect to swank now. Probably had a few stuck processes before which was stuffing things up
00:59joshnzThanks heaps to all. It appears I have it working. I should probably go and add to the clojure wiki.
01:00paul__hey, I'm trying to make a seq of vectors into just one seq, what is the function to do this called?
01:01amalloypaul__: (apply concat vecs)
01:01paul__thanks
01:01amalloybut also see if you can not produce the seq of vectors to begin with, by using eg mapcat
01:01amalloyjoshnz: that'd make you a better citizen than most of us
01:09joshnzHow does emacs know that I'm in a clojure project? Does clojure-jack-in need to be called from core.clj, or does it do something clever and traverse folders looking for something? That be seem hard to implement a stop condition on.....
01:10joshnzoh, it probably doesn't care. clojure-jack-in will just connect to swank regardless...
01:13amalloyit has to start the swank server too. i suspect it walks up the tree looking for project.clj
01:19amalloyjoshnz: i was wrong. it just calls "lein swank" in the cwd, and lein does the filesystem walking
01:19amalloyor i guess it calls "lein jack-in"; whatever, same thing
01:20joshnzreally? So it will walk all the way to root if you're in say a rails project? lol
01:20semperostrying to tinker with the Clojure repl, intercepting the read process, making some adjustements to what's in *in* and then letting it resume per usual, but I'm not sure how to work with the LineNumberedPushbackReader that is *in*
01:20amalloyprobably. i've never looked at the lein source
01:20joshnzI guess it's not too bad, since you're not checking sibling folders, only the parent or current
01:21amalloyright
01:21semperosas an arbitrary example, say I just wanted to make a single case where if "1 + 1" is typed at the repl, I can parse that, and then replace that with "(+ 1 1)" and send the repl on its normal path
01:21semperosI see how to replace the standard read fn for clojure.main/repl, but as I mentioned, at this point I'm not sure how to work with PushbackReaders
01:22semperosany thoughts/guidance/good resources to look at?
01:22amalloysemperos: you could rebind *in* to a proxy of LNPBR
01:23amalloythat wraps the original *in* and delegates to it
01:24semperosright
01:24semperosthat it needs a PushbackReader or derivation thereof I understand, I suppose my question is more on the Java side of actually using that class to look at the contents and then constructing a new one
01:25semperossome of the code samples I found were less than helpful...
01:30amalloysemperos: i'll gist something up in a few minutes
01:30semperosamalloy: didn't mean to ask for too much hand-holding, but I appreciate any help, thanks
01:36amalloysemperos: hm. it's more complicated than i thought because the reader reads stuff one character at a time, not line at a time. but i'll gist what i have and you can take what you like
01:37amalloyhttps://gist.github.com/1175034
01:37semperosyeah, I noticed that
01:37semperosthanks for putting that together, I'll take a look
01:38amalloy$javadoc java.io.PushbackReader
01:38lazybothttp://download.oracle.com/javase/6/docs/api/java/io/PushbackReader.html
01:38semperosyep, I looked at those
01:38amalloyyeah, that was for me
01:38semperosgotcha
01:39semperoshaven't been on in a while, nice to see continued bot helpfulness
01:39amalloyyou probably want to proxy BufferedReader, which does all its input line-at-a-time, and then wrap a LNPBR around your proxy
01:39amalloyugh, but i bet it doesn't do *all* its input line at a time :P
01:39semperosheh
01:40semperosthat makes sense, though
01:42amalloysemperos: i always have a hell of a time finding the java stdlib sources. i'm curious now; you don't happen to know where i can see buffered-reader's impl?
01:42semperosno, I don't
01:43semperosfor download: http://download.java.net/jdk6/source/
01:45amalloyah, lovely
01:49joshnzok, added a comment to the dev page. If there's anything horrible incorrect, let me know and i'll update it
01:49joshnzhttp://dev.clojure.org/display/doc/Getting+Started+with+Emacs?focusedCommentId=2687001&amp;#comment-2687001
01:50semperosmy other question would be in actually getting a running repl; I've tried to mimic the appropriate parts of clojure.main/main to run a repl with my updated read fn
01:51semperosbut whenever I run the code, it just prints the "user=>" prompt and then immediately exits
01:51ivan__joshnz: hi fellow NZ person :)
01:51joshnzhowdy ivan_
01:53amalloysemperos: are you running it from swank?
01:53semperostried that
01:54hiredmansemperos: using lein run?
01:54semperoscurrently using the code from lein repl and tweaking there, as I got that working
01:54amalloyi wouldn't be surprised if that didn't work
01:54semperosamalloy: now that you mention it, I'm not either
01:54amalloyrepl and/or run probably would
01:54cheiersemperos: make sure you setq slime-net-coding-system 'utf-8-unix
01:54semperoshiredman: yes, in my own code, was trying lein run
01:54hiredmansemperos: I've seen that behaviour before, your repl will run fine outside of lein run
01:54semperosrather, with my own code, was putting the code to run the repl in -main and using `lein run` from cmd line
01:55hiredmane.g. if you uberjar it
01:55semperosah
01:55semperosshouldn't taken that one more step, I'll git it a try
01:55amalloyjoshnz: "You will still need to the :. "?
01:55hiredmanlein run and clojure.main/repl have issues
01:57joshnzI assumed so. Because you're appending to the head of PATH, so it still needs to be separated with a colon. I'll tweak that a bit
01:57amalloyjoshnz: i'm not saying you're wrong, i'm saying i don't understand the sentence
01:57joshnzyeah, that's how I understood your question
01:57amalloyespecially, do i need ":", and your sentence ends with ".", or do i need ":."?
01:58amalloysince :. is a pretty common thing to have in your PATH
01:58joshnzI'm not sure if you need the : if PATH is empty string. I assume it won't break anything if you end your PATH var with a colon
01:59hiredmanamalloy: only if you like being insecure
01:59amalloyor...maybe "." isn't actually common, and i just thought it was when i was a DOS junkie
01:59joshnzI agree that I thought it was a bit weird typing :. but i'm not one for long docs ;)
02:00amalloyhiredman: i remember learning it was insecure (and perhaps forbidden) as root, but i never re-evaluated the assumption that it's good for general users. now that i say it aloud it's clearly wrong
02:00amalloy(and indeed it hasn't been on my path for years)
02:02semperoshiredman: yep, uberjar worked, good call
02:02joshnzupdate to make :. a bit more descriptiive
02:02joshnzupdateD that should be
02:03hiredmansemperos: I was playing with my own repo recently
02:03hiredmanrepl
02:04semperosthat'd help
02:12joshnz@ivan_: You're not Ivan from Mindscape by chance?
03:50zoldarHello, I'm trying to use an object instance from compiled record in java code. Minimal example here: http://pastebin.com/P4C3FxXM . Is it at all possible to refer to the vars outside record's namespace? Or is gen-class the only way in such situation?
03:51hiredmanas I said last time you asked, you have to load the namespace
03:52zoldarhiredman, sorry, had to miss your answer then
03:52hiredmanloading the record doesn't load the namespace, and the record tries to use the values of vars that are not setup until you load the namespace
03:53zoldarhow would I accomplish this? in such case ?
03:54hiredmanRT.load maybe work
03:54zoldarshould I explicitly put require/use inside method body?
03:54hiredmanno
03:54zoldarah
03:54hiredman(clojure.lang.RT/load "foo/core") or whatever
03:54hiredman(but as java)
03:57zoldarthat worked
03:58zoldarbut it'll require writing wrappers
04:03zoldarthanks for pointers anyway, and sorry for reposting the same question
06:07kzarWhat d'ya reckon to this attempt at filtering every nth item in a sequence? http://paste.lisp.org/display/124299 - sure it's a bit clunky
06:25thorwilkzar: seems a bit brutal to index the items
06:28kzarthorwil: Hmm can't think of how else to approach it though
06:33thorwilkzar: i'd consider the use of partition or somehow looping with an internal counter
06:36thorwil,(flatten (map butlast (partition 4 [:a :b :c :d :e :f])))
06:37clojurebot(:a :b :c)
06:37thorwilkzar: ^
06:37mrBliss,(mapcat butlast (partition 4 [:a :b :c :d :e :f]))
06:37clojurebot(:a :b :c)
06:38thorwilnice :)
06:55thorwilis there any potential use in using one name more than once in a function signature?
07:00kzarmrBliss: Hey I did the same approach, one problem though is that partition leaves off the
07:00kzarend of the list if there's not enough for the partition
07:00kzar,(partition 3 [1 2 3 4 5])
07:00clojurebot((1 2 3))
07:01mrBlissuse partition-all instead (btw thorwill came up with the function, I only tweaked it a bit)
07:01mrBliss*thorwil
07:02kzargold stars all round
07:03thorwilah, well, butlast will not be the right thing is the last partition is shorter ...
07:04kzarYea just noticed that, (take (dec nth) col) instead maybe
07:06peteriserinsI'm following the cljs QuickStart, getting this error when launching script/repljs java.lang.ClassNotFoundException: sun.org.mozilla.javascript.internal.Context
07:07peteriserinsis it because I am running openjdk?
07:07morphlingpeteriserins: yes
07:08kzar(defn skip-nth [col nth] (apply concat (partition-all (dec nth) nth col)))
07:48peteriserinswould one use vim-clojure with clojurescript?
07:58fliebelWhat became of the indexed vs map-indexed discussion? I keep wanting the index of an item in different places.
08:00fliebelI suppose amalloy-utils has it...
08:05fliebelkzar: What became of your drop-nth?
08:06kzarfliebel: Shortest I did was this: #(apply concat (partition-all (dec %2) %2 %)) which is as above but with #() instead of (fn ..
08:07kzarfliebel: I think there's an indexed function in seq-utils
08:07fliebelkzar: I was playing with the modulus of the index in filter.
08:08kzarfliebel: Yea I thought about that, didn't try it that way in the end though
08:09fliebelkzar: It *might* be faster, because you create less temp objects that way.
08:10kzarfliebel: Something like (map second (filter #(not (zero? (mod (first %) (dec nth)))) (clojure.contrib.seq-utils/indexed col)))
08:10kzarfliebel: Tpyed that straight into IRC without trying it, probably wont work
08:10fliebelI did this: (map peek (remove #(zero? (mod (first %) 3)) (indexed (range 10 0 -1))))
08:12kzarfliebel: Is there a shorter way of writing (apply concat ...) ?
08:13fliebelmapcat comes to mind
08:13kzarfliebel: But without mapping a function voer first
08:13fliebelyea... dunno
08:14kzarWhat's bamboozling me now is this one http://4clojure.com/problem/31
08:15fliebelflatten, maybe, but that's not very nice I think.
08:16fliebelkzar: let me tell you ther's a function in core that almost solves that.
08:16kzaraha that's got me down into shortest solution
08:16kzarfliebel: Cool OK, well don't tell me I'll try and find it heh
08:17fliebelMaybe a synonym to 'pack' might help... well, not really a synonym, but the sultuion reads like the problem description.
08:18kzarah got to run anyway
08:38semperosI'm playing with clojure.main/repl, I've written my own read function that does some things with *in* and then calls Clojure's default clojure.core/read function
08:38semperosI can successfully "intercept" it and call it, but in the running REPL, I have to hit enter twice for the result to be returned
08:39semperosso if I write (+ 1 1), I can see it running through my read code, but then it hangs after the call to clojure's default read function, at which point if I press enter again, it continues and returns 2
08:41semperosI've tried adding \newline to the end of the content I pass to read, but that doesn't seem to help
08:50lobotomy_hm, is there something special about testing multimethods that (invoke functions that) throw exceptions?
08:51lobotomy_i'm trying to verify that the exception is thrown. with (make-piece [-1 20 6 6] "" "" "") i get the exception as i should; with (is (thrown? java.lang.IllegalArgumentException (make-piece [-1 20 6 6] "" "" ""))) the test fails, saying "actual: nil", which apparently means nothing was thrown
08:53lobotomy_make-piece is a multimethod that switches on the type of the first of the first argument, and in the Integer case does a (map verify-edge first-arg), where verify-edge throws IllegalArgumentException for illegal values such as < 0
11:08technomancyhiredman: would something like (shell-command "echo \"lein jack-in 92424\" | sh") solve the macosecks path issue?
11:32scodeWhat's the idiomatic way to do (byte 200) in clojure? That won't work due to overflow protection. I want to do the equivalent of "byte b = (byte)myInt;" in Java, preferably without doing (byte (- x 128)).
11:33coopernursescode: try (.byteValue 20)
11:33coopernurse,(.byteValue 20)
11:33clojurebot20
11:34coopernurse(class (.byteValue 20))
11:34coopernurse,(class (.byteValue 20))
11:34clojurebotjava.lang.Byte
11:34scodeThanks!
11:34coopernurse&(class (.byteValue 30))
11:34lazybot⇒ java.lang.Byte
11:34coopernurselooks like it works in 1.3 also..
11:35coopernursenot sure if there's a more idiomatic way, but that should work
13:25solussdquestion- why when I add the clojure.data.json library to my dependencies list in my project.clj (leiningen) do I prefix it with org.clojure/ ? the json library is in the clojure.data.json namespace, what's with the / and org. ?
13:25solussdin other words what's the difference between that usage and the name.space/package usage in clojure?
13:26coopernursesolussd: in project.clj you're specifying a (maven style) library dependency
13:26Chousukesolussd: someone else might offer a modified version of the same package
13:26Chousukeso you have organisation/package
13:26coopernursewhich is a JAR that contains many packages
13:27coopernursesorry, namespaces (not packages) in clojure parlance
13:27coopernursedoes that help?
13:27solussdok, so there isn't necessarily a relationship between the package namespace and the organization/package in my project.clj
13:27coopernurseright
13:27solussdthat does. thanks!
13:28coopernurseif you look in your ~/.m2/repository dir
13:28coopernurseyou'll see the local cache of JARs you've specified in project.clj across all projects on your box
13:28coopernurseand that dir structure will match project.clj's naming conventions
13:28solussdcool. Sure is a lot in there. :D
13:28coopernurseif you "jar tvf [filename]" one of the jars in lib
13:29coopernurseyou'll see the layout of files in the library
13:29coopernurseand that layout will match your namespaces for the files you use/require
13:30coopernurseheh, yeah, maven (which lein uses) has been described as a "DSL for downloading the internet"
13:30solussdhaha
13:30coopernursegood thing there's a local cache
13:55rdbcciis it just me or does the repl hang alot?
13:56coopernurserdbcci: how are you starting the repl?
13:56rdbccijava -cp .;jline-0_9_5.jar;clojure.jar jline.ConsoleRunner clojure.main
13:57coopernurseand you're interacting with it directly, or are you talking to it from an editor like emacs?
13:58rdbccidirectly windows vista
13:58jkkramerrdbcci: does it just hang out of the blue or in reaction to certain input (e.g., infinite sequences)?
14:01rdbcciinput, maybe infinite seq - but since im fiddling about...
14:02jkkramerif you find yourself accidentally realizing infinite seqs a lot, the *print-length* and *print-depth* vars may help
14:02fliebelThose guys at Geni are like 6 hours behind GMT, right? I'm having trouble figuring out the right time to try to reach them.
14:02jkkramerer, *print-level*, not *print-depth*
14:05rdbccinot giving any output though, just hanging
14:07jkkramerrdbcci: it tends to hang if you attempt to print an infinite seq
14:07jkkramer,(binding [*print-length* 10] (prn (iterate inc 1)))
14:07clojurebot(1 2 3 4 5 6 7 8 9 10 ...)
14:07jkkramerin the repl, (set! *print-length* 10)
14:07raekrdbcci: are there certain expressions that hangs, or is the hanging random?
14:09rdbccicertain expressions im pretty sure
14:12rdbccii know i may be abusing it, but it seems a little less than robust
14:13raekrdbcci: can you show an example of an expression that hangs?
14:13arohnerfliebel: they're in california, so that's -8 I believe
14:14fliebelarohner: Hm, okay, so I'm GMT+2 ATM, I believe, so they should at least be awake now, right?
14:14arohneryes, 11AM there
14:16rdbccisure, happens while exploring function for url data fetching
14:20rdbccimainly coll returned from url .getHeaderFields
14:31semperosplaying clojure.main/repl, I've put together a custom read function that does a few things, then builds a new LineNumberingPushbackReader and passes it to the default clojure.core/read function
14:32semperoshowever, whenever I create this LNPBR and pass it to the default read, the prompt just sits there
14:32semperoseither waiting for me to press enter twice
14:32semperosI've tried appending newlines to the content of the LNPBR before sending it to read, but that doesn't make any difference
14:33semperoswhen I spit to file what is in *in* by default, e.g. if I enter foo at the repl, it's foo plus three newlines (char code 10)
15:11michaelr525Hey!
15:21jblomoanyone using lein-beanstalk? trying to get my app working on aws
15:47NetpilgrimHi. I’m reading The Joy of Clojure, and the authors say (p. 91): “Also, the order of values returned by seq on a list is backward compared to seq on a vector …” Am I missing something, or is this just not true?
15:47Netpilgrim,(seq '(1 2 3))
15:47clojurebot(1 2 3)
15:47Netpilgrim,(seq [1 2 3])
15:47clojurebot(1 2 3)
15:51jblomoNetpilgrim: I don't have the book, but yea that seems wrong the way i'm reading it. the order in which things are *added* is reversed
15:53Netpilgrimjblomo: I know, and I'm thinking about how this could be they meant somehow but I don't think the sentence as written can be misinterpreted.
15:53Netpilgrims/they meant/what they meant/
15:53lazybot<Netpilgrim> jblomo: I know, and I'm thinking about how this could be what they meant somehow but I don't think the sentence as written can be misinterpreted.
15:54jblomoyea, strange. maybe they have an eratta on the website
15:55Netpilgrimjblomo: They have, but it's not in there.
15:56jkkramerthe context is stacks and peek/pop. maybe they meant peek/pop work on opposite ends for list/vector
15:56jkkramer,(peek '(1 2 3))
15:56clojurebot1
15:56jkkramer,(peek [1 2 3])
15:56clojurebot3
15:56jkkramerit does appear to be incorrect as worded, though
15:57jblomodefonce doesn't work with Vars from other namespaces?
15:58jblomoi'd like to (:use settings.custom) then have (ns settings) set defaults
16:01Netpilgrimjkkramer: That's probably what they were thinking about. It's still more than just a type. I'll add it to the errata thread in the Manning forum.
16:01Netpilgrims/type/typo/
16:02lazybot<Netpilgrim> jkkramer: That's probably what they were thinking about. It's still more than just a typo. I'll add it to the errata thread in the Manning forum.
16:11stuartsierrajblomo: The full name of a Var includes the namespace in which it was defined.
16:12stuartsierraAll the `def` forms create a new Var in the current namespace.
16:13jblomois there a better way to conditionally load custom settings?
16:14stuartsierraLots.
16:14stuartsierraYou could merge a map of defaults with a map of overrides.
16:16jblomo(try (require 'custom) (merge settings custom/settings) (catch FileNotFound e settings))
16:16jblomokind of like that?
16:35stuartsierrajblomo: preferably without the try/catch, but yes
16:35stuartsierraYou could even put the custom/default settings in a file, as a map, and `read` it in.
16:38stuartsierraGood luck, see you later.
16:39NetpilgrimSince (some #{:x} coll) seems to be idiomatic, am I right in assuming that it's more efficient than ((set coll) :x)?
16:43scottjNetpilgrim: not sure, but (set coll) turns the entire coll into a set even if :x is the first thing
16:45Netpilgrimscottj: Good point. And (set coll) is probably not very fast because of all the equality tests needed.
16:47amalloyNetpilgrim: well, (set coll) can mostly just do hash comparisons; it only needs equality tests on hash collisions
16:47amalloybut (set coll) is necessarily O(n*logn), when you only want to do an O(n) "compare everything with :x" operation
16:50Netpilgrimamalloy: I wish the doc strings of functions had more information on their run time.
16:51amalloywell, it...i mean, it has to be. conjing onto a set is logn, and you're doing it n times
16:52amalloyand many functions don't even have a meaningful runtime. what is the runtime of concat? or of conj?
16:52Netpilgrimamalloy: I'm not doubting your assessment, just saying it would be nice if (doc f) would give me that information.
16:53Netpilgrimamalloy: Not sure about concat but shouldn't the run time for conj be O(1) for every data structure?
16:55amalloyno. it's logn for sorted data structures, at least. i asserted a moment ago that it's logn for hashsets too, but i'm not actually sure of that now i come to think of it
16:56amalloyand because clojure's data family of data structures is extensible, you can write your own data type that has O(n^2) insertion. surely nobody would want to rewrite conj's docstring then!
16:56Netpilgrimamalloy: Yes, I hadn't thought of sorted structures.
17:01lobotomy_wait, why is (set coll) O(n log n)?
17:07amalloylobotomy_: well, i said that because i thought insertions were logn. but as remarked above i'm no longer sure of that
17:07amalloyi mean, certainly they're at least log32(n)
17:07amalloybut that's basically constant
17:20michaelr525oudeis: hey there
17:22Netpilgrimmichaelr525: Hi.
17:22Netpilgrimmichaelr525: Didn't realize you were talking to oudeis.
17:25michaelr525hehe
17:25michaelr525don't worry about it
17:28semperosamalloy: so on the topic of the repl read function from last night, I tried reading through *in* and saving that off to a string; I then do my processing with the string, and create a new LNPBR with (LineNumberingPushbackReader. (StringReader. my-string)) and pass that to the default (read) function, but then the repl just hangs and waits for me to press enter or C-d before it even starts reading my LBPBR
17:28sempeross/LBPBR/LNPBR
17:28lazybot<semperos> amalloy: so on the topic of the repl read function from last night, I tried reading through *in* and saving that off to a string; I then do my processing with the string, and create a new LNPBR with (LineNumberingPushbackReader. (StringReader. my-string)) and pass that to the default (read) function, but then the repl just hangs and waits for me to press enter or C-d before it even starts reading my LNPBR
17:29semperosnot saying it's an optimal way to deal with the *in* at this point, but just trying to get something simple working
17:30amalloyNetpilgrim: i think JoC was referring to ##(seq (conj [] 1 2 3)) vs ##(seq (conj () 1 2 3))
17:30lazybot(seq (conj [] 1 2 3)) ⇒ (1 2 3)
17:30lazybot(seq (conj () 1 2 3)) ⇒ (3 2 1)
17:30currentBif I have a vector of maps, how do I access the first map with destructuring?
17:31amalloybecause if you've been conjing into the structure as a stack, and you then call seq, it matters which structure you were using
17:31amalloycurrentB: uhm, the same way you access the first of any seq with destructuring, no?
17:32amalloy&(let [maps [{:a 1 :b 2}, {:x 5 :y 6}], [{:keys [a b]}] m] [a b])
17:32lazybotjava.lang.Exception: Unable to resolve symbol: m in this context
17:32amalloy&(let [maps [{:a 1 :b 2}, {:x 5 :y 6}], [{:keys [a b]}] maps] [a b])
17:32lazybot⇒ [1 2]
17:33amalloysemperos: no useful advice from me, i'm afraid
17:33semperosokie doke, wasn't sure if something would spring to mind
17:33currentBactually sorry, it's actually a map of vectors of maps. {:thinga [{:a1 "x" :a2 "y"]}
17:33Netpilgrimamalloy: Might be, but it's still conj creating a different order, not seq.
17:34amalloyso...currentB, what is it you actually want to do? "access" is pretty vague
17:36currentBI have a map of info about a product, containing a vector of image info of that product (ie, path, dimensions, whatever). I'd like to be able to refer to the first image as first-img in a function that handles these products
17:36amalloy&(let [m {:thinga [{:a1 "x" :a2 "y"}]}, {[{a :a1}] :thinga} m] a) ;might work?
17:36lazybot⇒ "x"
17:37amalloy&(let [m {:thinga [{:a1 "x" :a2 "y"}]}, {[first-img] :thinga} m] first-img) ; if you want the whole map
17:37lazybot⇒ {:a1 "x", :a2 "y"}
17:37currentBawesome, thanks! eventually my brain will start to catch up with this stuff and I'll stop asking dumb things here. Thanks again!
17:38michaelr525ERC is great
17:38michaelr525it's C-l's every once in a while
17:50mbachow do I get to the UNIX API in clojure?
17:50mbacgetuid and the like
17:50amalloyjava doesn't really expose most posix stuff
17:51mbacright
17:54mbacam I screwed unless I write native bindings
17:54mbac?
17:55amalloymore or less. i think there are some unofficial native libraries out there already, but i don't know if they're any good
17:55raekmbac: there should be libraries for accessing the posix stuff. it's just not included in Java
17:56amalloyand of course that would hurt your portability and distribution. if you want to run it anywhere other than your own machines, people may worry about the unsandboxed native code
17:56mbacis everything in clojure-contrib intended to be built on standard J2SE?
17:56mbacoh, Linux is the only platform that matters to me :)
17:59raekmbac: I think so
18:03amalloymbac: sure. but are your *own* linux machines the only platform that matter? if so, have a blast, of course. just pointing out that native libraries make it harder for anyone to use your stuff, even on the same arch
18:03zakwilsonThe Gaka docs suggest compiling the code to a static stylesheet and serving that. Why not just memoize the css function instead?
18:04mbacamalloy, 90% of software is written for a single buyer, so that's not a big deal to me
18:04mbacand it shouldn't be for most people, I gather
18:05amalloyfair enough. i assume that statistic is completely made up, either by you or whoever you got it from, though :P
18:05mbacit's my statistic, i got it from looking at ads for software developers
18:06scottjzakwilson: seems that would be fine, I basically do that with slice
18:06mbacmost software developers work on projects that never leave one company's walls
18:06amalloythat's probably related to the fact that google, microsoft, etc., don't advertise on stackoverflow-jobs
18:07amalloybut whatever. your product is for one buyer, and that's what counts
18:07scottjzakwilson: I mark slices that are impure and everything else is memoized
18:08amalloyzakwilson: if you compile to a static stylesheet you can do http-level caching, no?
18:09mbacso, i take it there's no clojure->C interface :)
18:09zakwilsonamalloy: well, yes, but you could probably come up with a way to do that with memoization too. Granted, with a static sytlesheet you can leave the caching up to an external server or a CDN.
18:10amalloysure
18:11arohnermbac: there's jna
18:11mbacright
18:13arohnerother than clj-native, I'd look at e.g. jtux
18:26bultershi. If I add a dependency in a leiningen project.clj; is it possible to have the new dependency available in a running swank session?
18:27amalloyno
18:30sridi have a function that returns a list of two elements [a, b] - and the caller of this function needs to assign it within the map with other elements {:a <> :b <.> :c 3 :d 5 ....}
18:30sridcan I destructure the return value like that? or is there a better way?
18:31sridthe function exists only to not pollute the caller with its functionality; technically it is not required.
18:31bultersamalloy: thanks. all i needed to know ;-)
18:32sridreal world case - in this map https://github.com/srid/notaskinnerbox/blob/master/src/notaskinnerbox/stackexchange.clj#L42 - I want to add a ":todate" key, and extract calculation of :fromdate and :todate to a different function that accepts a single argument 'N'
18:32amalloysrid: just conj the two maps together
18:33amalloy&(conj {:a 1 :b 2 :c 3} {:from 'x :to 'y})
18:33lazybot⇒ {:to y, :from x, :a 1, :b 2, :c 3}
18:33sridright, i still think imperatively :)
18:34NetpilgrimWhat is the most idiomatic way to get the first element in a seq, for which a predicate is true? I've come up with (some #(if (pred %) %) s) and (first (drop-while (not (pred %)) s)).
18:35amalloyNetpilgrim: those are both reasonable, though most people use filter rather than drop-while there
18:36Netpilgrimamalloy: Oh, I knew I had overlooked a more common function. :)
18:36amalloyyou can also write a HOF for #(if (pred %) %), which IMO makes it nicer
18:36amalloy(some (validator pred) s)
18:36Netpilgrimamalloy: HOF?
18:37amalloygiven (defn validator [pred] (fn [x] (when (pred x) x)))
18:37amalloyhigher order function
18:37amalloyor call it "satisfying" instead of "validator", whatever
18:38Netpilgrimamalloy: I like it.
18:39sridamalloy: i ended up not writing a function, but still using conj - https://github.com/srid/notaskinnerbox/commit/8bbda3758f82b322d35199cba1d52356179c41cd#L0L42
18:40amalloysrid: ##(doc pos?)
18:40lazybot⇒ "([x]); Returns true if num is greater than zero, else false"
18:40sridah, good to know.
18:42NetpilgrimI'm picking up on how to use the bots here, but is there a manual or help function?
18:43amalloynone that are comprehensive
18:43amalloyNetpilgrim: the important ones to know are that if the first character is , or & then clojurebot or lazybot (respectively) will eval it as clojure code
18:44amalloylazybot also snags things like ##(inc 1) in mid-message
18:44lazybot⇒ 2
18:44Netpilgrimamalloy: What's the difference between the bots?
18:45amalloyfor other commands, lazybot takes $command and clojurebot takes ~command
18:45amalloy*chuckle* just about everything. they don't have any common code that i know of these days
18:46Netpilgrimamalloy: So if I want something evaluated I can take either one?
18:46amalloyyeah
18:46Netpilgrimamalloy: OK, thanks.
18:46amalloylazybot: do you guys also respond to PMs???
18:46lazybotamalloy: Oh, absolutely.
18:47NetpilgrimCool.
18:50shelloxhi
18:50Netpilgrimshellox: Hi.
18:53shelloxcan you help me, i dont understand why i get the error in the paste: http://dpaste.com/603789/
18:53amalloytoo many parens in foo
18:54amalloyand also no parameter declaration
18:54amalloyie, square has [n], but where are the args to the function foo?
18:55Netpilgrimamalloy: You're fast. My browser tab hadn't loaded yet.
18:55amalloyquickest gun in the west, that's me
18:56shelloxamalloy: i just want to calculate it in foo without giving an argument, and then do (println foo) or so
18:56amalloythen you don't want defn, which defines a function
18:56shelloxjust fn then?
18:56amalloyyou could just write (+ (square 5) (square 5)) and the repl would print it for you
18:57amalloyif you want to give it a name, you can (def foo (+ ...))
19:02shelloxamalloy: ok i got it now, but if i want to print the result it put - before, but the calculation is correct
19:02shelloxhttp://dpaste.com/603791/
19:03shelloxits 2640, but it shows -2640 then, why?
19:03shelloxi thought it calculate and print the result then
19:04amalloy&(- 385 3025)
19:04lazybot⇒ -2640
19:04amalloy&(- 3025 385)
19:04lazybot⇒ 2640
19:06shelloxah, you are right of course, my mistake :/
19:07shelloxi first tried it with plus, so it wasnt important whats first, but it is with - of corse ;)
19:07shelloxcourse*
19:18dgreenspcan I use Ring with Clojure 1.3? Is anything packaged to work with 1.3? I'm trying to run the ClojureScript compiler on my web server
19:23dgreenspis there a website for clojure-contrib 1.3? it seems like things were moved around, but I can't find any information on it
19:34mudgecould ring-serve be used for a production server?
19:35mudgeanybody here use ring?
19:38Netpilgrimdgreensp: If I understand it correctly, there will be no clojure-contrib 1.3 because all further development will be done in separate smaller projects. The only information I could find about these: http://dev.clojure.org/display/doc/Clojure+Contrib
19:40shelloxmhh, how to calculate the crossfoot of a number
19:42mudgeNetpilgrim: yes, that's right
19:44dgreenspNetpilgrim: thanks, that's a new link to me. I saw something about it being broken up as a practical matter. I was expecting to change a few lines in project.clj and move on, but I have no idea where to find "split-line", "pprint", etc. now...
19:46dgreenspit doesn't seem like anyone is really using 1.3, though, except Rich :P
19:47Netpilgrimdgreensp: I hope, someone will update the clojure-contrib page on clojure.org to show where all the functions can be found now.
19:47amalloy(1) what/where is split-line? (2) pprint was never in contrib, it's in core, so i would be a little surprised if it moved
19:51shelloxhow to split "foo" in a list ['f', 'o', 'o']?
19:53dgreenspsorry, clojure.contrib.string/split-lines, and clojure.contrib.pprint -- I guess there is a clojure.pprint too, but for whatever reason I got an error message in my fiddling around from something using the contrib pprint
19:54amalloy&(seq "foo")
19:54lazybot⇒ (\f \o \o)
19:57dgreenspoh, there's clojure.string/split-lines too -- maybe clojure.contrib.string is completely obsolete
20:03mudgeanybody here use ring?
20:07tomojask?
20:07tomojclojurebot: ask?
20:07clojurebotNo entiendo
20:07amalloytomoj: that's his real question, actually
20:07mudgeany reason not to use ring serve for production?
20:07tomojah
20:08amalloymudge: ring is eminently suitable for production. i suspect [almost] every real-life clojure webserver uses ring
20:08tomojheh
20:08amalloycertainly 4clojure.com and geni.com do
20:08amalloyand clojars
20:08mudgeamalloy: my question is, can ring-serve be suitable for production as the production server
20:10tomojI think only you can decide that
20:18mudgedoes anybody emed jetty into their clojure web application for production?
20:18mudgeor is this only used for development?
20:18mudgeembed*
20:21amalloyi think embedding jetty is fairly common, but often you put another webserver in between (possibly another jetty) to proxy to jetty
20:22mudgeamalloy: is this proxying done so that you can have multiple embeded jetties for multiple websites on the same machine?
20:22amalloythat's why i do it. others probably have better reasons
20:23mudgeamalloy: cool beans, I think I will do something similar
20:28amalloymudge: nginx has been pretty good for my needs, if you're looking for recommendations
20:28mudgeamalloy: yes looking for recommendations, thanks
20:28mudgei see using nginx as the proxy server
20:30amalloyyes
20:32amalloymudge: the server at 4clojure.com is serving about a dozen other websites via nginx
20:33mudgeamalloy: cool, is 4clojure.com yours?
20:33amalloymostly
20:33mudgeawesome
20:33mudgehow do you go about embedding jetty for those websites?
20:33amalloyi don't understand the question. the other websites?
20:34mudgei am just curious how you embed jetty for your clojure websites
20:34mudgein the typical way with ring/ring-jetty-adapter
20:34mudge?
20:35amalloyhttps://github.com/dbyrne/4clojure/blob/develop/src/foreclojure/core.clj#L14
20:35mudgeamalloy: ah, thanks!
20:36amalloyand then nginx is told to forward 4clojure.com:80 to localhost:8080
20:36mudgeamalloy: yea, make sense
20:37mudgeI am currently using lein ring uberwar to create a war file out of my clojure app and then dropping the war app into a tomcat container, but I think I am going to change it so that it is similar to how you are doing it
20:37mudgewith jetty embedded
20:40mudgeamalloy: do you ever connect a repl to one of your remote websites?
20:40mudgeor use a repl somehow with 4clojure as it is running?
20:41amalloyno
20:41mudgefor development?
20:41amalloylocal copy
20:41mudgei see
20:42st3fanwhat is 4clojure?
20:42mudge4Clojure is a resource to help fledgling clojurians learn the language through interactive problems.
20:42mudgehttp://4clojure.com/
20:42st3fanoh fun
20:43mudgethe website is also written in clojure: https://github.com/dbyrne/4clojure
20:43st3fancool
20:43st3fani wrote a little web app with noir
20:43mudgest3fan: cool, what's it do?
20:44st3fanbasically a hackernews clone :)
20:44mudgeah, cool
20:44st3fanyeah was a good exercise
20:44st3fani am not sure about generating *all* html in code though
20:44mudgewhy not?
20:45mudgeusing hiccup?
20:45st3fanyeah
20:45st3fani would like to combine hiccup with more traditional templates i think
20:45mudgethere's enlive
20:45mudgehave you used enlive?
20:45st3fannope, checking!
20:46mudgenot a templating system, you write raw html and enlive allows you to hook and combine things together awesomely
20:47amalloyi'm not sure i'd say enlive is *not* a templating system
20:47mudgei take it back
20:47amalloyit's a DOM transformer
20:47amalloywell. that's not true. it transforms...trees. html, xml, whatever
20:48st3fanyeah nice
20:48st3fani'll give it a try
20:48mudgei was thinking that it would be nice to have something that transforms hiccup vectors, like how enlive transforms html
20:49mudgeit would be nice to be able to write hiccup vectors and have something like enlive work on that
20:49tomojbah
20:49tomojjust use hiccup to generate static html?
20:49tomoj..if you must
20:50st3fantomoj: the problem is that our amazing web people know html and css very well
20:50st3fanwell it is not a problem
20:50tomojnot suggesting that
20:50st3fanbut i don't want them to get into clojure
20:50tomojmy web people know html and css too
20:50amalloyst3fan: tomoj doesn't mind writing html and transforming it with enlive
20:50tomojso I want them to write pure html and css
20:50amalloybyt writing hiccup and transforming that with enlive? you lose most of the benefits of both enlive and hiccup
20:51tomojI don't think you lose any enlive benefits unless your hiccup pieces are dynamic
20:51tomojwell, yeah
20:52st3fando you all use Emacs?
20:52tomojyou lose the benefit that it's actually written in html :)
20:52amalloyst3fan: a majority
20:52mudgeyou only lose the enlive benefit of having raw html, if that is a benefit for you, for me it is not because i don't have html design people
20:52mudgest3fan: of course, who doesn't use Emacs?
20:58danenaniahey all, i'm trying to get started with both clojure and emacs on osx 10.6. no experience with either. i am to the point of having swank-clojure installed, and 'lein swank' inside a project opens a connection on 4005. but when i open core.clj with emacs and do 'M-x clojure-jack-in', i get 'No Match'
20:58danenaniaany ideas?
20:58amalloyif you've started the swank server yourself, just run M-x slime-connect
20:59danenaniaok.. that is equivalent?
20:59mudgeclojure-jack-in starts up swank, so you don't need to
20:59st3fanneo, jack in
21:00danenaniai see.. guess i will go with slime-connect then, but i wonder why jack-in isn't working...
21:01mudgetry clojure-jack-in without a swank process already running
21:02danenaniahaven't had the process running when i've tried
21:02mudgeah, i see, i guess emacs doesn't find clojure-jack-in
21:03danenaniayeah.. well i'll just use connect to get going and maybe figure this out when i understand things better
21:03danenaniathanks for the help
21:04mudgeamalloy: have you thought of writing a clojure book?
21:04amalloynot really interested
21:04mudgeah
21:05amalloyinteractive teaching in #clojure is more fun
21:05mudgeyea, that's fun
21:15mudgewhen is #clojure businest?
21:15mudge*busiest
21:25mdeboardmudge: Seems like it's always very close to the mean
21:26mdeboardprobably overnights USA would be slowest
21:27mudgethanks
21:41mudgeamalloy: why do you use (var app) in (run-jetty (var app) {join false :port 8080})) ?
21:42amalloyit's a pretty standard compojure trick, basically giving jetty a pointer to a function instead of a function itself, so that you can re-def stuff and the running jetty instance will see the new code
21:43st3fanhm 4clojure is awesome
21:43mudgeamalloy: i see
21:44coopernursest3fan: agreed.. working on a problem now myself
21:45st3fancoopernurse: i'm at the beginning .. implementing count nth last in terms of loop/rest/recur .. learning a lot
21:45coopernursest3fan: nice. do you have a FP background? or is clojure your first
21:46st3fanmore hobby than a background .. did some common-lisp stuff (practical common lisp)
21:46clojurebotlisp is the red pill
21:46st3fanbut i intend to actually do some useful things with clojure
21:46mudgest3fan: like what?
21:46coopernurseexcellent. clojuredocs is very good too if you haven't seen it yet http://clojuredocs.org/
21:47st3fanhm that is ncie
21:49mudgeamalloy: in this namespace declaration why are some of the namespaces in a vector and some not: (ns foreclojure.core
21:49mudge (:use compojure.core
21:49mudge [foreclojure static problems login register golf ring
21:49mudge users config social version graphs mongo utils]
21:49mudge ring.adapter.jetty
21:50amalloyshorthand for forclojure.static foreclojure.problems...
21:50mudgeamalloy: oh right, thanks
22:32technomancydanenania: your clojure-mode is too old; need to get it from either marmalade or my git repo
22:33wastrelwhat do they pay you for this technomancy
22:33technomancyhehe
22:33danenaniaah thank you, it was actually much dumber than that... i just didn't edit my .emacs file correctly
22:34danenaniaall set now
22:34technomancycool
22:58klutometisIt doesn't look like there's a `defmacro-' analog to `defn-'; and I take it adding `:private true' metadata is meaningless.
22:58hiredmanwhy do you take that?
23:01fbru02hi ! what's the usual way to embed some server variables in the javascript (using cljs but the question is more general also) , is it templating the javascript and generating the js with the server?
23:07klutometishiredman: It works, but not quite in the way `defn-' works: whereas public functons can call ones defined with `defn-', public macros cannot invoke macros with `:private true' outside the namespace.
23:24dgreenspklutometis: there's a clojure.contrib.def/defmacro-
23:27dgreenspfbru02: for basic stuff, I usually put (str "clientVars=" (json-str client-vars)) in a script tag
23:28fbru02dgreensp: makes sense
23:28dgreenspor it should be called serverVars depending on how you look at it :)
23:28fbru02:P
23:43amalloyi try, where possible, to avoid :private metadata by using closures instead. i guess i don't have a lot of company in this, but you might consider writing your private macro as a macrolet instead, with tools.macro
23:45amalloy(or by just making things public and not worrying about "hiding" them)