#clojure logs

2011-08-31

00:14chewbrancawhat's the recommended lib for interacting with sql? (sqlite and postgres)
00:19gstampI'm not sure what's recommended by you can find a list of them here: http://clojure-libraries.appspot.com/category/136007
00:19sridwhich clojure resource/book would you recommend to *thoroughly* learn clojure and its standard library functions?
00:19sridakin to 'python in a nutshell' that I used for python back in 2003
00:20chewbrancagstamp: ahh cool, haven't seen that site before, was using clojure-toolbox.com
00:20gstampI try to keep it fairly up-to-date
00:21chewbrancathe clojure.contrib.sql (now: https://github.com/clojure/java.jdbc) appears to be the most widely used (or blogged about and found by google), but is lacking in docs and examples compared to https://github.com/LauJensen/clojureql
00:22amalloysrid: try again, but don't put "nutshell" and "thorough" in the same sentence?
00:22chewbrancagstamp: well done! glad to see another site with a variety of clojure resources
00:22chewbrancasrid: http://java.ociweb.com/mark/clojure/article.html that's a good place to start (at least I've found it useful and up to date)
00:23amalloyanyway, the only way to become thoroughly familiar with clojure and its standard libraries to write a lot of clojure and (just as important) read a lot of clojure
00:24sridwhat do you mean "read a lot of clojure"?
00:24chewbrancasrid: read source code of good projects
00:25amalloynot even good projects. i mean, sure, prefer good projects
00:25amalloyjust read source code of any clojure program. you'll learn something
00:25chewbrancaamalloy: very true
00:28ddwwk_evenin'
00:30ddwwk_where are the irc logs kept?
00:31ddwwk_n01se
00:31ddwwk_got it
00:31chewbrancagstamp: hey for the editing section, I want to give a shoutout to slimv (https://github.com/vim-scripts/slimv.vim) which is awesome, swank client in vim with a nice paredit plugin as well
00:35polypus74chewbranca: ty for tip. paredit definitely an incentive to learn vim
00:35chewbrancapolypus74: well slimv is a port of slime for emacs, so as much as I love vim, emacs is probably better to learn in regards to clojure/lisp if you don't know either yet
00:36polypus74already on emacs/paredit, but i like the vim philosophy better. no paredit was a real downer, until your post that is
00:37chewbrancapolypus74: oh cool! well in that case, slimv rocks, works great with swank-clojure, gives you a repl directly in vim and the paredit support works well
00:37gstampchewbranca: feel free (or I'm happy to edit it if you don't have a google login)
00:38chewbrancagstamp: oh cool, yeah I can add that in
00:49chewbrancagstamp: http://clojure-libraries.appspot.com/show/141002
00:51gstampchewbranca: thanks!
00:51chewbrancagstamp: no problem, good job on the site!
01:28amcnamaraamalloy_: any idea what would cause java.util.concurrent.RejectedExecutionException when running 4clojure locally? something to do with clojail permissions perhaps?
01:28amcnamaraexception is thrown on all page loads
01:28accel_is there any clojure addon taht allows static typing?
01:30scottjaccel_: no, there's a logic tutorial that explores static typing and there's the potential for clojurescript to someday use google closure's static type checking
01:30amcnamaraaccel_: you can use type hints though, not static but improve performance slightly
01:31scottjand there's a defn macro that lets you automatically add pre/posts based checking types
01:33accel_i care less about performance
01:33accel_and more about finding bugs at compile time
01:42amcnamaraaccel_: you can try asserting against a type, but I'm not sure how idiomatic that is
01:49tomojwouldn't be at compile time anyway?
01:52khaliGjust got my copy of Joy of Clojure, looks great. Is it intended to be read from cover to cover or as a reference?
02:13jblomois prxml being released for 1.3.0?
02:18scottjCL library that claims to be almost as good as gclosure https://github.com/mishoo/cl-uglify-js
04:07kzar,(apply or [true true false]) <- How can I do something like that?
04:07clojurebot#<CompilerException java.lang.RuntimeException: Can't take value of a macro: #'clojure.core/or, compiling:(NO_SOURCE_PATH:0)>
04:08opqdonutkzar: (defn orf [x y] (or x y))
04:08kzaropqdonut: Oh and then reduce right?
04:09opqdonutbut also, ##(some identity [true true false])
04:09lazybot⇒ true
04:10opqdonutand, ##(every? identity [true true false])
04:10lazybot⇒ false
04:10opqdonutthose are the equivalents of apply or and apply and
04:11kzaropqdonut: Gotya thanks
05:30clgvIs there any support in leiningen to "lein deps && lein install" multiple projects that form a dependency tree with one leiningen command?
06:04clgv"lein sub" seems promising
07:52kumarshantanuclgv: There is a lein-sub plugin
07:53kumarshantanuwhich will have much better support in Leiningen 2.0
07:53clgvkumarshantanu: yes thats what I found before ;)
07:53clgvbut indeed I need something different like "build all checkouts"
07:54clgvand that has to be recursively and build each only once
07:54kumarshantanuclgv: In lein 2.0 you can specify fine-grained chain of actions
07:54michaelr525Hello!
07:54kumarshantanuBut that is not ready yet
07:55clgvah ok. I hope they adjust the deletion so that .gitignore files (or "hidden linux files") are not deleted
07:56kumarshantanuclgv: Can you file a bug to have it on the collective TODO list?
07:58clgvkumarshantanu: not really. a github account is needed for it, it seems
08:00kumarshantanuclgv: Okay, so the error description is something like "`lein clean` should not remove the hidden (beginning with a period) files"?
08:00kumarshantanuI can file the bug
08:00clgvkumarshantanu: yes. but it's not only lein clean. lein deps also deletes them
08:01clgvkumarshantanu: clean deletes them in classes/ and deps in lib/
08:04kumarshantanuclgv: Right, I can reproduce the bug -- however, I have a question
08:05kumarshantanuWhy would you keep anything in "lib" or "classes"? They may not be required to put in version control at all
08:07clgvEclipse/CCW does not create them when they are missing, so it is annoying to have to create them after a "git clone"
08:08lnostdal_i've probably asked this a couple of times, but how does one go about getting slime to catch this exception: (.start (Thread. (fn [] (/ 42 0)))) ? .. it ends up "outside" of slime now, back in the terminal where `lein swank' was started
08:09kumarshantanuclgv: It seems you need this fixed for a development workflow you follow -- can you share what is your workflow? Is "classes" or "lib/*" on your Eclipse project classpath?
08:09clgv"lib/*" is. I am currently changing my workfolow a bit.
08:10clgv"classes" is as well
09:27michaelr525sleepy@work
09:27michaelr525maybe it's an idea for a website
09:27clgva blog ;)
09:27michaelr525sleepyTube.com
09:27michaelr525:)
09:28michaelr525wake me up before you go go
09:31bsteuberwhat's the most common clojure css generating solution?
09:33st3fanbsteuber: 'vi main.css' ? :)
09:35Raynesbsteuber: Marginalia has a nice little css generator.
09:37bsteuberfound gaka and cssgen so far
09:37bsteuberas stand-alone libe
09:41thorwilbsteuber: a recent announcement of https://github.com/rathwell/clj-style mentioned gaka, cssgen, and csslj
09:44bsteuberthanks
10:15cees_Hi, does anyone now a gracefull way to get out of a clojure program that parses a stream of input commands via (doseq [c (BufferedReader. *in*)] (processCommand c)?
10:15cees_Of course I can press ^D or ^C, but that kills my clojure.repl too.
10:16joegalloloop/recur instead of doseq and have a special "quit" command where you don't recur?
10:17joegallo(when (not= c "quit") (processCommand c) (recur ...)
10:17cees_Joegallo Thanks, that sound simple. Should have thought of it myself :-)
10:42arohnerhow do I convert a j.u.Vector to a seq?
10:45polypus74arohner: just calling seq on it should do the trick
10:45arohnerpolypus74: I'm getting "Don't know how to create ISeq from: java.util.Vector$1"
10:46clgvit already "is a seq" - see ##(map inc (java.util.Vector. (range 10)))
10:46lazybot⇒ (1 2 3 4 5 6 7 8 9 10)
10:46joegalloit seems like you aren't passing in a vector, then, but some anonymous class defined inside the vector class (hence the $1)
10:47joegalloare you sure it's a Vector?
10:49joegallosomebody is calling elements somewhere, Vector$1 is the anonymous Enumeration class defined inside Vector
10:49joegalloif you want to keep the rest of the code as is, use enumeration-seq, i guess
10:50arohnerjoegallo: that did it, thanks
11:00gtrakis there a way to manually fail a test in clojure.test?
11:04dakronegtrak: (is false)
11:05gtrakdakrone, i can put that anywhere within the body?
11:05dakroneyep
12:48sridamalloy_: (replying to yesterday's message) how did you personally learn clojure?
12:50hugodanyone else notice that :gen-class doesn't statically resolve protected method calls on the class it is extending?
12:53ejacksonhugod: I know it doesn't extend final
12:53ejacksonthat kicked me about for a little while
13:03llasramConvention question: what's the most idiomatic way of expressing something needing both initialization and finalization?
13:03llasram Like `with-open' handles objects which need to be .close'd when they leave scope, but with custom behavior.
13:03llasramWhat I have right now is `open' & `close' functions and a `with-foo' macro which takes a binding form of [name args-to-open]. It just looks a little sloppy to me because `name' isn't literally bound to `args', but `(open args)'
13:09khaliGIs there any project for adding a loop feature to the language?
13:12technomancyone loop feature's not good enough for ya?
13:15joly,(doc loop)
13:15clojurebot"([bindings & body]); Evaluates the exprs in a lexical context in which the symbols in the binding-forms are bound to their respective init-exprs or parts therein. Acts as a recur target."
13:15khaliGtechnomancy, no i mean a real loop :)
13:16llasramkhaliG: How is that not a real loop?
13:16khaliGsee http://www.ccs.neu.edu/home/shivers/papers/loop.pdf and http://video.google.com/videoplay?docid=-3704713569771882785
13:18hiredmankhaliG: common lisp's loop is seen as not abstract enough
13:18hiredmanor not declaritive enough I guess
13:18hiredmanbecause you can't parallelize it
13:19khaliGyeah and CL:LOOP involves mutation of loop variables
13:19khaliGbut i think Olin shows how to do make a functional one which would fit clojure perhaps
13:19llasramWhat about clojure's for/doseq? Not the same syntax, but it looks like you con do similar stuff
13:21khaliGyea that's handy sometimes but still fairly limited imho
13:22llasramWhat's something that the cl:loop makes easier?
13:22VinzentI saw clj-iter somewhere ob github...
13:24khaliGVinzent, thank you, i'm a fan of iterate :)
13:25khaliGsweet that's exactly what i was looking for!
13:28VinzentkhaliG, it'd be cool to add it to the new contrib, wdyt?
13:29khaliGwould be cool indeed
13:31khaliGVinzent, would be nice too if clj-iter did code-walking too
13:32chewbrancatechnomancy: fun bbq script, worked like a charm
13:35technomancychewbranca: hehe; awesome
13:47amalloyamcnamara: broken version of lein
13:50amalloysrid: i read JoC, and then wrote and read a bunch of clojure
13:50amalloyand hung out in #clojure a lot, asking and answering questions
14:11gtrak`how would i check that the input is a bytearray?
14:13opqdonutyou mean a byte[]?
14:13opqdonutsay (instance? (something Byte/CLASS) x)
14:13opqdonutI'm trying to remember what "something" was :)
14:14amalloy&(Class/forName "[B")
14:14lazybot⇒ [B
14:14amalloy&(instance? (Class/forName "[B") (byte-array 0))
14:14lazybot⇒ true
14:14opqdonutoh, that's good
14:15opqdonutbut there's something like: &(instance? (.getClass (java.lang.reflect.Array/newInstance Byte/CLASS 1)) (byte-array 0))
14:15opqdonutgah
14:16opqdonut,(instance? (.getClass (java.lang.reflect.Array/newInstance Byte/TYPE 1)) (byte-array 0))
14:16clojurebottrue
14:16gtrak`ah....
14:17amalloyopqdonut: j.l.r.Array/newInstance is like thirty times more verbose than make-array or into-array
14:17opqdonutISTR there being something that gave the array class when given the element class
14:17gtrak`that's really complicated
14:17opqdonutyeah, amalloy's solution is fine
14:17amalloybut i don't see anything in j.l.reflect or j.l.Class that would turn Foo.class into Foo[].class
14:18opqdonutyeah. something that I found with google actually says getClass+newInstance is the canonical generic way of doing that
14:20amalloyit probably is, although i bet apache commons has something better
14:23amalloyi've apparently lost the ability to compile and run simple java apps from the CLI
14:23xicubedi am starting out. i got "lein ring server" to run but how do I stop it? Ctrl-z gets me back to the shell but if I run it again the port is taken.
14:23r9@xicubed: ctrl-z suspends a process
14:24amalloyah, no. just forgot my package declaration. anyway, it looks like java can use the nice syntax `byte[].class` for literals
14:24r9try "fg"
14:24r9that will bring it to the foreground
14:24r9then do Ctrl+C
14:24r9http://www.linuxtutorialblog.com/post/tutorial-the-best-tips-tricks-for-bash
14:24r9read up on process control
14:27xicubedthx - got it working
14:31amalloyopqdonut: it looks like someone wrote a library for it, at least, but amazingly i don't see it in apache commons. seems more useful than some of the crap they shove in there
14:31amalloyhttp://code.google.com/p/reflectutils/source/browse/trunk/src/main/java/org/azeckoski/reflectutils/ArrayUtils.java#48
15:06amcnamaraamalloy: ah, thanks. It seems to only bail on gzip so I removed that handler for now, I'll try building both ring and clojail sans-lein later to see if it fixes.
15:08amalloyamcnamara: i use cake, myself, but i know people who have used lein successfully. at least once, lein didn't work, and it exhibited this failure mode. switching to a working version of lein fixed it
15:09coopernurseclojurescript folks: does it offer any help in terms of DOM manipulation and event callbacks? or is that something google closure would assist with? or neither?
15:09technomancyamcnamara: is this about the rejected execution thing?
15:09amcnamaratechnomancy: yeah,
15:10coopernursein particular I'm interested in help avoiding memory leaks resulting from orphaned DOM event listeners, etc
15:10technomancyamcnamara: if you make your main thread block on the server it'll work
15:10amalloythe issue is that gzip uses a future, which some versions of lein didn't play nice with (technomancy: accurate?)
15:10technomancyamalloy: it's a workaround for the fact that clojure doesn't give you any control over the thread pools it uses
15:10amalloysure, i understand the cause
15:11technomancyhttp://p.hagelb.org/shutdown-agents.jpg and http://tech.puredanger.com/2010/06/08/clojure-agent-thread-pools/
15:11technomancyhaving your main thread block takes care of it
15:11technomancyclojurebot: rejectedexecutionexception?
15:11clojurebotRejectedExecutionException in swank means you need to upgrade swank to 1.3.2 or higher.
15:12technomancyhmm... not quite relevant here
15:12amalloyamcnamara: anyway, we also use an agent that gets updated every time someone solves a problem, so just disabling gzip wouldn't completely fix your issue
15:13polypus74given some java class over which i have no control, how would i go about making seq callable on instances of it. is it possible?
15:14technomancyamcnamara: is that something you can do?
15:15arohnerpolypus74: what clojure syntax do you want?
15:15arohnerpolypus74: (my-seq)?
15:15amcnamarathis is running a bit over my head, but I'll spend the afternoon figuring it out :)
15:15polypus74arohner: (seq instance)
15:15technomancypolypus74: seq isn't a protocol (yet?)
15:15technomancyso not really
15:15polypus74arohner: (my-seq ...) i can figure out
15:16arohnerpolypus74: since seq isn't a protocol, you have to implement ISeq
15:17polypus74ok ty guys
15:17arohnerpolypus74: another (crazy) option would be to make your own fork of clojure, that adds to clojure.lang.RT.seqFrom(Object)
15:17hiredmanyou can follow the lead of enumeration-seq
15:18amalloyand iterator-seq
15:18arohneryeah, that's a pretty good idea
15:18hiredmanmaybe it is interator-seq I am thinking of
15:19polypus74i'll have a look
15:33gtrak`can you do (binding ...) on a private fn var in another namespace?
15:34amalloyhiredman: no, i think enumeration-seq exists also
15:36hiredmangtrak`: yes
15:37gtrak`it seems to ignore me when i try
15:39amalloyare you trying to rebind a non-dynamic var in 1.3, then?
15:40gtrak`1.2, just a (defn-
15:40gtrak`maybe I need to use var on the calling function?
15:40gtrak`to refer to the one i'm rebinding?
15:41gtrak`nope
15:43michaelr525heya!
15:43r9clojurebot: rejectedexecutionexception?
15:43clojurebotRejectedExecutionException in swank means you need to upgrade swank to 1.3.2 or higher.
15:43r9clojurebot: runtimeerror?
15:43clojurebotexcusez-moi
16:30sritchietechnomancy: is it okay to specify "LATEST" as the version for some dependency/
16:30sritchie?
16:30sritchieI'd thought that was the case, but I'm getting a not found error, with lein
16:32technomancythere's a way to get the newest version; I think it's in the faq
16:32technomancyI've never used it myself
16:36sritchietechnomancy: looks like [0,) works, I
16:36sritchie'll check the faq for the accepted way
16:36Netpilgrimsritchie: I don't know why it doesn't work with Leiningen, but you might consider using RELEASE instead of LATEST to avoid snapshots.
16:37sritchieNetpilgrim: yeah, this is really just for internal dev -- we've got a project with our thrift schema and generated code, so I just want to pull in anything on an update
16:37sritchiebut that's a good key to know about
17:08jlion line 74 of clojurescript/src/cljs/cljs/reader.cljs, should the "#" be a \#?
17:08jlithat is, should the "#" string be a \# character? seems like it..
17:14jlioh, I guess it doesn't matter because chars become 1-character strings in javascript ?
17:15raekyes
17:20gtrak`it seems that binding is broken from run-tests on swank, yet it works in the repl, what's the dealio?
17:22zippy314If I have functions declared in two namespaces (i.e. in two files) that I'd like to be able to use in both namespaces, how do I declare that in the "use" declaration at the beginning of each file? I can't seem to get anything to work. It acts as though there is a strict usage hierarchy where two files can't mutually refer to each-other. Is this true?
17:24joegallono circular dependencies
17:25gtrak`ah wait, i was just doing it wrong
17:26amalloyzippy314: yes, it is true
17:26zippy314Ouch!
17:28zippy314Why is this? It seems like a huge limitation. Are there any workarounds?
17:29scgilardisearch for compilation unit at: http://news.ycombinator.com/item?id=2466731
17:29scgilardiworkaround is to make the hierarchy a non-cyclic graph by rearranging the contents of the namespaces
17:33amalloyit's a pain every so often, but most of the time if you have a problem it's because your design isn't very good - too many pieces of the design all know about each other
17:36amalloyand the limitation exists so that clojure can compile a given form based only on forms it's already seen, rather than needing your whole program all at once. if a *correct* form could depend on code not yet read, it would mean that, for example, (defn bar [x] x) (defn foo [] (bsr baz)) couldn't be flagged as an error immediately - maybe you're planning to define bsr later
17:37gtrak`you can do forward declarations just like C right? can that fix cyclic dependencies?
17:38amalloynot between namespaces
17:53gtrak`what we really need is a .h file paradigm
17:53amalloy(defmacro pretend-this-is-C [& body] ...)
18:07TimMczippy314: In my experience, it is pretty rare for a wad of code I have written to both have large-scale cyclic dependencies and also be otherwise well-structured.
18:07TimMcI usually end up factoring out a "common" namespace.
18:07TimMcIt can happen though, I guess.
18:12zippy314In my case, I'm working around this by having a global registry of certain functions that I can lookup by name at runtime. The issue is that these functions are created by macros, and they represent signals that "agents" can receive. I was trying to have these "agents" (which can contain other agents) to map to clojure name-spaces. But the problem is that parent and child "agents" can send each-other signals (which are
18:41sjlAnyone know why an input stream defined like so: (DataInputStream. (BufferedInputStream. (.getInputStream socket))) would read data correctly when talking to a server on localhost but not read correctly when talking to a server over a network?
19:26amcnamaratechnomancy, amalloy: Got it sorted out by binding a flag to block run-jetty (using :join?) when called from -main, while keeping the run fn non-blocking by default. Thanks for the help.
21:43solussdleiningen question- I added ':main my.package.core' to my project.clj but 'leon repl' starts me at clojure.core. I was under the impression that :main would set my namespace in the repl
22:01tomojsolussd: main is, afaik, only for setting the main class in the jar manifest
22:02solussdah. sad. Ideally, I'd like to build a jar that launches a repl with the namespace set to something
22:16tomojhm.. you could just supply a main function that calls clojure.main/main
22:16cemericksolussd: Pretty easy to do.
22:16tomojbut that will be a crappy repl I think?
22:16cemerickheh, what tomoj said.
22:16cemerickcrappy?
22:16tomojor is it the same as `lein repl`
22:16tomojnever use either..
22:16solussdwell the idea is they'd be able to kick off a handful of API tests
22:16solussdthey don't know clojure
22:17tomojputting them in a repl seem strange to me, then :)
22:17solussdit's a gateway drug
22:17tomojI'm can't imagine getting addicted to manually balancing parentheses
22:18solussdmost of the commands would be of the (something arg arg arg) nature
22:18tomojthen why not just `java -jar foo.jar something arg arg arg`? really in an effort to get them to see the light?
22:19solussdyeah.. really wish java didn't take so long to start up.
22:19tomojah
22:19solussdmaybe I'll throw together a swing ui. :D
22:20solussddo we have a nice gui framework yet?
22:26amalloylein has an option somewhere that's like "run this code every time you start a repl"
22:29amalloysomething like :repl-options [:init (fn [] (doto 'myproj.core require in-ns))]
22:29amalloysolussd: ^
22:31tomojwhoa
22:31tomojthat looks quite useful
22:31amalloytomoj: that's actually a feature of clojure.main/repl - lein just passes that option on untouched
22:32solussdhm.. didn't work
23:15solussdwhy would I want to use a gensym instead of ~'body and ~@'body in a macro generated by a macro?
23:20solussde.g. (defmacro [blah] `(defmacro ~(symbol blah) [~'body] ~@'body)) or (defmacro [blah] `(defmacro ~(symbol blah) [body#] ~@body#))
23:24sridwhat is the equivalent of `eval-buffer` for clojure code in emacs?
23:25sridI ran `m-x clojure-jack-in` to get a clojure repl going. now I want to send the entire buffer (if foo.clj) to this buffer. repeatedly (upon edits)
23:25sridnote that foo.clj may not be saved to disk yet
23:26arohnersrid: C-c C-k, slime-compile-and-load-file, but that reads the file off disk
23:26arohnersolussd: sometimes you need to use gensym to create local, unnamed variables
23:27sridarohner: good enough for me; i can remember to save before eval'ing.
23:27arohnersrid: I believe it asks if you want to save
23:27sridyes, that's very handy!
23:29amalloysolussd: well, ~@'body will never do what you want in any circumstances
23:30solussdb/c I needed a [& ~'body] ?
23:30amalloybecause it will try to splice in '(quote body)
23:32solussdhrm. ~'@body ? :D
23:32solussdis there any way to express this?
23:32solussdwithout a gensym
23:32amalloydo you have an allergy or something?
23:32solussdmostly just curious
23:33solussdand gensyms look terrible in doc strings. :D
23:33amalloysolussd: so set the :arglists metadata to something else
23:34solussdso, if I want to splice in stuff, I have to use a gensym in this case?
23:34amalloyi don't think it is ever the case that you *have* to use a gensym. they're just syntactic sugar for another construct
23:35amalloybut that construct can get confusing and/or complicated
23:35solussdI'll buy that. Still, is there a way?
23:35solussdmostly b/c I want to understand it
23:35amalloythe quoting is complicated and i'm never quite sure
23:36solussdgot it!
23:36amalloy(defmacro foo [name] `(defmacro ~name [& ~'body] `(do ~'~@body))) or something
23:36solussd~@~'body
23:36clojurebot@ has nothing to do with whether sth is evaluated or not
23:37sridcould someone tell me why I get "Unsupported binding" for multiple function bodies? http://dpaste.com/606442/ -- reading the defn syntax at http://clojure.org/special_forms doesn't tell me what is wrong my code.
23:37solussdand yes, that's ugly.
23:37solussdbut it makes sense- I'm unquoting a quoted body and splicing it in
23:37amalloysrid: [nil] is wrong
23:38sridhow would I match an empty list, then?
23:39amalloyclojure doesn't have pattern matching built in
23:39sridso it *only* does destructuring.
23:39amalloyyes
23:39srid[x & xs] works, but not, say, [2 & xs]
23:41amalloyyes, but see dnolen's match lib
23:42sridthere is no if-nil? ah, anything other than nil is true
23:45gaze__Hey... would someone mind helping me understand how state is passed around? Let's say on the OO side I had some class (no hierarchy) that was used to represent a connection to an FTP server... it might have the host, port, username, etc. as locals, some methods that connect, set that state, list the current directory, etc.
23:45gaze__I can recognize that you might plop all that into a record and pass it around as the first argument to all associated functions on the lisp side
23:45gaze__but... is that the right way to do it?
23:47gaze__in haskell I'd probably just make a state monad or something
23:49amalloythere are a million ways to do it. you could mimic the OO approach by having (make-connection foo) return a function for doing stuff; that function would be a closure around whatever connection-specific data you need
23:49amalloy(defn make-connection [host] (let [connection (...open-connection)] (fn [operation] (case operation :close (.close connection)))))
23:50sridthis is my implementation of list reverse function without using the core `reverse` - http://dpaste.com/606444/ ... can it be improved?
23:51amalloysrid: improved is super-vague
23:51amalloyanyway, the answer is surely yes. try (shallow-reverse (range 100000))
23:52sridimproved ... with respect to idiomatic clojure, and am-I-forgetting-a-core-function thing.
23:52sridi couldn't use cons/conj, so had to settle for concat.
23:53sridyes, it sucks at performance.
23:54amalloydid you try the above?
23:54sriddoes it kill my emacs proces?
23:55ambrosebs_has clojure.contrib.def been promoted/moved to contrib 1.3?
23:55gaze__okay... that kinda reminds me of something I've seen in common lisp
23:55gaze__the sorta make-* idiom and then closing over the state
23:55amalloy(first (shallow-reverse (range 1e5))) if you're worried about printing too much
23:55amalloyi strongly suspect you get a stackoverflow
23:55amalloygaze__: it's far from the only clojure style
23:55amalloybut it's one that's entirely reasonable and might apply here
23:56gaze__what's the sort of preferred way? I don't particularly like the switching
23:56amalloyit depends on how much state you have, and how much you want it to change over time
23:57sridyes, I get stackoverflow. let me think how to fix this
23:57gaze__well, what are some other options?
23:58sridright, xs keeps accumulating over the stack in the order of N*N
23:59gaze__I feel like this is kinda one of the first things I wanna ask coming from an imperative background... and it's a pretty well defined thing anyway. Has anyone written anything about it?