#clojure logs

2008-02-02

08:21scramflotsweet, there's a room
08:22rhickeywelcome
08:22scramflotthanks
08:26scramflotI'm new to lisp. is learning any 'lisp-1' language the same as learning clojure? I get the feeling it's not, from the 'differences with other lisps' page
08:28rhickeyThere will be a lot that is similar
08:29scramflotSo could I learn clojure by reading a book about lisp-1?
08:31rhickeyThere's one sense in which Lisp is a set of ideas, which you can move around, and another in which each Lisp is a language with it's own syntax and semantics, which don't travel as well. Certainly don't expect to bring code between them.
08:34scramflotrgr. Well, I went through the whole website and it's really geared towards people who already know Lisp. Which is cool.. It's pretty early I guess.
08:35rhickeyI hope to add more material for newcomers to Lisp
08:35scramflotWhen running the argcount example on the functional_programming page, I'm seeing it just return all the arguments
08:36scramflot mmm, nevermind
08:36scramflotmust have been a typo when I typed it in
08:37rhickeyok
08:38scramflotsweet, works as advertised
08:46scramflotrhickey: what other lisp-1 dialect is very well documented?
08:47scramflotOr, better yet, a document that teaches lisp-n dialects
08:49scramflotI just read that scheme was a lisp-1
09:21scramflotreading htdp.. I got a long way to go ;)
09:21scramflotanyone still here?
10:55scramflotI'm trying to figure out how the make-adder function works on the http://clojure.sourceforge.net./features/functional_programming.html page
10:56scramflot(defn make-adder [x] (let [y x] (fn [z] (+ y z)))) (def add2 (make-adder 2)) (add2 4) -> 6
10:58scramflotI'm seeing x and z as the parameters being sucked in from the outside, but how is it determining to stick the 2 and the 4?
11:00scramflotso the def is "closing over" the value of x after it has been assigned? how does clojure know to reach down into add2 and stick 4 into z?
11:02scramflotwhat if I had another (fn [asdf] (...)) after (fn [z] (...))
11:02scramflothow would it know which one to pick from?
11:07jonathan_hi, anything happening?
11:08scramflotjonathan_: not much.. I was asking a question and no one was hearing me
11:08scramflotcare to take a stab at it?
11:08jonathan_shoot
11:09scramflotI'm trying to figure out how the make-adder function works on the http://clojure.sourceforge.net./features/functional_programming.html page
11:09scramflot(defn make-adder [x] (let [y x] (fn [z] (+ y z)))) (def add2 (make-adder 2)) (add2 4) -> 6
11:09scramflotI'm seeing x and z as the parameters being sucked in from the outside, but how is it determining to stick the 2 and the 4?
11:09jonathan_ok, hee hee
11:09scramflotso the def is "closing over" the value of x after it has been assigned? how does clojure know to reach down into add2 and stick 4 into z?
11:09scramflot what if I had another (fn [asdf] (...)) after (fn [z] (...))
11:09scramflothow would it know which one to pick from?
11:10jonathan_the return value is a function
11:10jonathan_it takes a single parameter
11:10jonathan_and adds y
11:10jonathan_where y is the x that you originally passed in
11:10scramflotoh.. wait.. so...
11:11jonathan_forget the x
11:12jonathan_you'll building a little box that has a little string that connects to y
11:12scramflotyou're actually.. add2, one could say, "resolves" to (fn [z] (+ 2 z))
11:12jonathan_yep
11:12scramflotoooh, I get it now
11:12scramflotYea, cause I started experimenting to try to figure it out, and...
11:13jonathan_now, if you have things like that, you can generate a little 'adder' that does anything
11:13jonathan_just map it onto a list
11:13scramflotI put two (fn [blah] (...))s in there
11:13scramflotand the last expression is the one that returned
11:14scramflot(one was an add, the other a subtract.. it subtracted)
11:14jonathan_yeah, if you do (fn [] (expr) (expr)) it generally gives you back the last one if that's syntactically valid
11:15jonathan_I still haven't worked through the pmap example
11:15scramflotI did (let [] (fn [] ())(fn [] ()))
11:16jonathan_try this ... make a couple of functions, then use (apply (comp fn1 fn2) [arg])
11:16jonathan_the comp glues the functions together
11:16scramflotcomp is builtin?
11:16jonathan_yep
11:17scramflotyou were saying, about mapping lists?
11:20jonathan_I did this thing at work for merging lists of date ranges
11:20jonathan_they could be timetables, or scheduling or pretty much anything
11:20jonathan_but you can build a function to tweak a date range
11:21jonathan_and another, and another, then compose them
11:21jonathan_then use map to apply all the tweaks
11:22jonathan_have you tried the new stuff?
11:24scramflothow bout, (defn make-operator [x y] (let [myx x] (fn [a b] (myx a b)))) (def myadd (make-operator '+)) (myadd 2 2) -> 4 ??
11:24scramflotnah, this is my first time looking at clojure, and I'm a bit of a spectator programmer anyway.. hit and run thus far
11:25scramflotWas that correct? to apostraphize the +?
11:25jonathan_you might need to adapt to call plus
11:26scramflotI was thinking maybe I should be sending in a function to myx
11:27scramflotthat takes a and b
11:27scramflotno?
11:27jonathan_I haven't tried that ...
11:28jonathan_but you do (reduce + '(1 2 3))
11:28jonathan_^can
11:29jonathan_the best source of 'idiom' is probably the boot.clj file
11:29scramflotI messed that up.. make-operator should have one param
11:30jonathan_doh ...
11:30scramflotanyway.. yea? you think a newb can digest it?
11:31jonathan_I'm digesting it and I'm a newb
11:31jonathan_I fall short of understanding those 'm' things
11:31jonathan_but I can just about cope with the STL
11:32scramflotSTL? C++?
11:32jonathan_And I'm more productive in Clojure than ... than ever
11:32jonathan_yeah lame 'enterprise' C++ is my thing
11:33scramflotI'm an arm-chair programmer.. passing java knowledge, jack-of-a-few-trades.. I'm a sys-admin
11:33jonathan_Clojure is a million times cleaner than Perl
11:34jonathan_All my Perl code eventually collapses on itself
11:34jonathan_I dunno if everyone has that experience
11:34scramflotNever had to write perl
11:35scramflotmight look into the regexs in perl 6 though
11:35scramflotlooks cleaner
11:35jonathan_it'll be dead if you can't run perl5 code on it
11:36jonathan_perl used to be my language for doing prototypes and what not
11:37scramflotoooh, I did it: (defn make-operator [x] (let [myx x] (fn [a b] (myx a b))))
11:37jonathan_cool
11:37scramflot(def myadd (make-operator +))
11:37scramflot(myadd 3 4)
11:37scramflot-> 7
11:37scramflotthat's sweet
11:37jonathan_read the boot.clj file
11:38jonathan_it's an awesome into to lisp programming
11:38jonathan_^intro
11:38scramflotcool
11:38scramflotI guess I will then
11:38jonathan_defining java interface and having it actually work is pretty sweet too
11:39jonathan_the new code in svn has a gui data inspector in 100 lines of code
11:40jonathan_have you looked at Arc?
11:43scramflotthat's actually what brought me here
11:43jonathan_I have it installed, has some neat stuff in it
11:44scramflotArc hit the news, then everyone was dissing it and saying things like "what does arc bring to the table? at least ikarus and clojure are doing neat things!" and that made me want to find out what clujure was
11:44jonathan_it still has the typical problem that I can't get at Oracle, or build a decent GUI
11:45jonathan_* on Win/OSX/Linux
11:45jonathan_but with pure java I can do all these things on any platform
11:45scramflotYou played with gui building in clojure?
11:45jonathan_I build in Netbeans, then just load it
11:46jonathan_works great, just stick the class on the -cp
11:46jonathan_or you can build dynamically
11:46jonathan_see inspector.clj
11:46scramflotwhere does the event handling go?
11:46scramflotin clojure?
11:47jonathan_(. mygui (addEventLister (implement (handler (fn[blah] ...
11:47jonathan_implement is a built in
11:47jonathan_yep
11:47scramflotoh, what does the . do?
11:47scramflot(been wondering that)
11:47jonathan_java instance methods
11:48jonathan_look at the hello world example
11:48scramflotthe one here? http://clojure.sourceforge.net./features/functional_programming.html
11:48jonathan_http://clojure.sourceforge.net/reference/getting_started.html
11:49jonathan_(. javax.swing.JOptionPane (showMessageDialog nil "Hello World"))
11:49jonathan_method calls go in () like a function
11:49jonathan_fields go without the ()
11:49scramflotok, yea... so what is . actually doing?
11:50jonathan_calling a java method on an object, or class (if a static)
11:50jonathan_showMessageDialog must be a static method, since we're calling it on a class
11:51scramflotok
11:52scramflotso, what would be JOptionPane.showMessageDialog() becomes that
11:52jonathan_all we need is someone to stitch the java reflection into a table model ... and we'll have a smalltalk style class browser
11:52scramflotthat would be sweet
11:52jonathan_it'd be easy if I knew java libs better
11:53jonathan_oh, you want this page http://clojure.sourceforge.net/reference/java_interop.html
11:53jonathan_for all the '.' stuff
11:53jonathan_.. chains
11:54scramflotI fricken love prefix notation
11:55jonathan_yeah, me too, and I haven't really grasped macros yet
11:55jonathan_in fact at all
11:56scramflotme neither.. haven't tried to grasp it yet.. I hear you can build the language with it though (roughly)
11:56jonathan_boot.clj is largely built from it
11:56scramflotright
11:57scramflotI've actually been wanting to try to implement a visual ide
11:57scramflotwhere you build a program visually
11:57jonathan_be nice to have it really dynamic
11:58jonathan_so you didn't even have to hit run
11:58scramflotAnd the analog I want to use is the file browser
11:58scramflotright
11:58scramflotprefix notation works well with this idea, cause the whole program can be broken down into a directory tree
11:58jonathan_my dad got our first computer, and spent hours typing in a program, and he was pissed because it didn't do anything ... he didn't think he needed to do anything else
11:59jonathan_RUN
11:59scramflothahahah
11:59jonathan_It was full of mistakes, it wouldn't have run correctly anyway
12:00scramflotyea, so.. dynamic like squeak, right?
12:01jonathan_I guess, no eperience of that sadly
12:01jonathan_look cool
12:02scramflotyou can use the gui to drill down into the code that is actually running the gui, and change it in real time
12:02jonathan_cool, sounds like a Lisp or Smalltalk
12:02scramflotsqueak is smalltalk 80 I believe
12:03jonathan_yeah, I always kinda think the syntax sucks
12:03jonathan_it's really bumpy
12:03jonathan_from the objective-c perspective (ie. basic cocoa programming)
12:04jonathan_squeak looks similar right?
12:04scramflotI've only seen it from the gui.. I'm not too familiar with the actual code view
12:05scramflotand I don't know smalltalk
12:05scramflotI'm only now learning lisp
12:06jonathan_I'm really enjoying it, and getting smugger by the day
12:06scramflot:)
12:06scramflotI can see why
12:08scramflotand having access to all the java libraries at the same time kicks ass
12:08jonathan_yeah, I kinda do management now, and I spent a few days writing a resolver for fuel rates for gas pipeline in C++, that's the main coding I've done in 8 months ... so I need to stay in practice
12:08jonathan_and yes, the java libraries are great ...
12:09scramflotI'm a system/network admin for the army.. so if I could find the time to get really good at a language, I could apply it to work.. but it's just finding the time first
12:10jonathan_I think it's like anything else, you just have to find a use for it and keep trying
12:10jonathan_it is easy ... < 100 lines to put an Oracle table in a Swing gui
12:11jonathan_it takes a while to understand, but all the bits are there
12:11scramflotI've used the io language (back in the day) to install anti-virus updates on a small network of windows boxes in afghanistan.
12:11jonathan_cool
12:11jonathan_are there any other good jvm languages ... scala?
12:11jonathan_is io on jvm?
12:11scramflotno
12:11scramflotio is definately cool though
12:12jonathan_it looked 'terse' from what I've seen
12:12scramflotsome say io has some problems, but it sure is sweet
12:12scramflotI was coding in it in no time
12:13scramflotvery intuitive
12:13jonathan_Cool, it's been on my list of things to look at for a while
12:13jonathan_along with Scala and Lua
12:13scramflotThe biggest complaint I heard was that it's so extremely reflective and runtime-modifiable that a security model is non-existent
12:14scramflotpractically any piece of code can modify any part of the system
12:14jonathan_yeah, that seems to be an Arc complaint
12:14jonathan_though I don't know how
12:14scramflotI've studied a bit on scala.. it looks even more verbose than java though..
12:15scramflotjust not very pretty
12:15jonathan_yeah, I have like three Haskell books
12:16jonathan_it's really inpenetrable
12:16jonathan_Scala looked pretty unpleasant
12:16scramflotby that you mean, hard to learn?
12:16jonathan_yeah, really finicky
12:17jonathan_I really enjoy being able to just try stuff out 'at the prompt'
12:17scramflotyea, haskell is the purely functional, no side-effects, etc. right?
12:17jonathan_there's various escape hatches
12:17jonathan_but in theory, yes
12:18jonathan_actually, I write functionally in Clojure
12:18scramflotYea, I'm a bit too intimidated by Haskell to really go after it
12:19scramflotany time soon, at least.. If I was in school for it, then sure
12:19jonathan_you can do stuff like (assoc mystuff key (assoc (get mystuff key) subkey newval))
12:20jonathan_which creates a copy of a hash with one subkey edited
12:20scramflotah
12:20scramflotdoes copying everything cause a memory issue?
12:21jonathan_not so far ... I've used that technique with 10 of 1000 of records with no hiccups
12:22jonathan_I'm writing a caching data server with undo and shared sessions
12:22jonathan_and I'll get fired if the prototype doesn't work
12:22jonathan_sweeeet
12:23scramflotyea
12:23jonathan_so far I've replaced 4000 lines of C++ with about 500 lines of Clojure
12:24scramflotwow.. so your really getting into it... how long have you been using clojure?
12:24jonathan_whereas before I would have used Perl and DBI
12:25jonathan_second week on Jan maybe
12:25jonathan_not long at all, it really is an easy language if you can handle the way functions and scope works
12:26jonathan_tcl is a bit clojureish
12:26jonathan_stick something in ( ) and it gets evaluated
12:26scramflotI don't see a lot of '() in the examples
12:27jonathan_in tcl?
12:27scramflotin clojure
12:27scramflotdelayed evaluation
12:27jonathan_yeah, it certain has less than Lisp
12:28scramflotit's just still has it, right? it's just not required as much?
12:28jonathan_Yeah Rich has fixed a lot of crappy syntax from Lisp
12:29jonathan_like (let ((x 1)(y 2)) (... becomes (let [x 1 y 2] ( ... which reads a lot better
12:29scramflotyea.. I'm still on the fence
12:30scramflotI think I like it.. but.. it _is_ more syntax
12:30jonathan_my only complaint so far is that (apply fn [args]) the [] seems not needed
12:30jonathan_more syntax than what?
12:30scramflotthan just using ( )
12:31scramflotas the universal code container
12:31jonathan_yeah, and more special forms like . etc
12:31jonathan_but it all fits together pretty well
12:31jonathan_I have a *lot* of things work first time
12:32scramflotI'm surprised I got that make-operator thing to work so quick
12:32jonathan_Plus the performance rocks
12:32scramflotreally?
12:32scramflotsweet
12:33jonathan_all the stuff you really do in real code is probably running on the metal in the java libs
12:33jonathan_so my JDBC code runs faster than C++ on my windows box
12:34scramflotwow
12:34scramflotscala is fast too
12:34jonathan_Yeah, if it weren't for people hating on Java, the JVM would have taken over the world
12:34jonathan_Thanks Microsoft
12:35jonathan_<insert bad words here>
12:35scramflotwhat do you think about parrot?
12:36jonathan_Haven't looked at it yet
12:36scramflotthe vm that aims to run all dynamic languages
12:36jonathan_Does it have libraries? Does it run all the perl odules?
12:37scramflotperl6 will run on it.. I think they're trying to port perl 5 to it
12:37scramflotso then both will run eachother's libraries
12:37jonathan_if they can slide perl5 onto it that'll help
12:37scramflotand they'd like to see python and ruby on there as well
12:37scramflotand then they can all share libraries
12:37jonathan_but most Perl programmers are probably writing pretty basic perl
12:38jonathan_It's horrible to read, and tricky to debug
12:38scramflotwell, I don't think anyone expects that perl 5 will go away after 6 is out
12:39scramflotwell, 6 is out now
12:39jonathan_yeah, it's just too useful
12:40jonathan_It's funny, I always seem to need to connect to a database
12:40jonathan_I totally choose languages based on libraries
12:40jonathan_oh, for sql lite, there's a pure java one
12:41scramflotI think I've heard about it
12:41jonathan_check this out http://www.zentus.com/sqlitejdbc/
12:42jonathan_it emulates Unix in Java I think
12:42jonathan_Just amazing
12:43jonathan_The sqlite executable is inside the Java jar
12:43jonathan_so you have sqlite on any platform in Clojure
12:44scramflotyea.. jetty's pretty sweet too
12:44jonathan_Is that the web server?
12:44scramflotyea, web-app server
12:44scramflotwhat do they call it, web-app-container?
12:45scramflotlike tomcat, but small
12:45jonathan_Yeah, I need to look into that, I'd sure like to build some web apps
12:45scramflotembeds right into your application
12:46jonathan_so you would you do web pages? define code to template them out?
12:46jonathan_I've been on VC6 since 2001, it's like the web never happened at my office
12:47scramflotuh.. you'll have to look into it.. I think jetty does cgi but I think most people use that other java server backend language thing.. forgot what it was called
12:47scramflotseen this: http://hsqldb.sourceforge.net/ ??
12:48scramflot(about jetty.. like asp, but for java? jsp? I can't remember)
12:49jonathan_awesome, thanks
12:49scramflothsqldb is fast
12:49jonathan_I've seen the name and assumed it was Haskell
12:49jonathan_Don't IBM have something also
12:49jonathan_derby?
12:50scramflotI think that's something similar.. not sure
12:50scramflothsqldb vs. others: http://hsqldb.sourceforge.net/images/imola_retrieve.jpg
12:52jonathan_haha
12:52jonathan_what a bizarre graph
12:52scramflotyea
12:54jonathan_actally, it might be fun to write a sql gui in clojure
12:55jonathan_you're 70 % towards most business apps if you have that
12:56scramflothey, if you have any gui/closure stuff built.. example-ware kind of stuff, I'd love to see it..
12:57jonathan_yeah, we need to get like a wiki going or something
12:57scramflotyes
12:57jonathan_plus get the boot.clj file documented
12:57jonathan_plus get an index of all the functions
12:58jonathan_I discovered compose (comp fn1 fn2) totally by accident
12:58jonathan_and memfn is cool too
12:58scramflotrich was here before you got here. I asked him about documentation.. he said "I hope to add more material for newcomers to Lisp"
12:59jonathan_I think the best thing is to read example code
12:59scramflotsame here.. my fav format is cookbook
12:59jonathan_once you have the (), that's the syntax
13:00jonathan_actually, I just remembered how I found Clojure, there's a Lisp user group page where Rich did a talk
13:01jonathan_http://lispnyc.org/wiki.clp?page=past-meetings
13:01scramflotawesome
13:02jonathan_The presentation is really good
13:03scramflotNYC huh.. where'bouts in the city is it?
13:03jonathan_Dunno, I'm in Tx
13:03scramflotI might have to go to one
13:03scramflotI'm a couple hours away, but there aint nothing going on up here in fort drum
13:04jonathan_yeah, I have something on a website somewhere to get a Lisp group going in Houston
13:04jonathan_but nothing yet
13:05jonathan_But there's one other language that I do really enjoy ... Javascript
13:05jonathan_But it's just Lisp in drag
13:06jonathan_I think it can do all the same tricks
13:07scramflothmm.. Javascript might be a great language, but I've been averse to letting any website run it on my browser whenever they want.
13:08albinoI came by because of the arc posts myself
13:08jonathan_you guys have the same story
13:08albinoheh, well at least we follow up :)
13:08scramflotyea, same here
13:09jonathan_I was at least hoping for an Arc compiler
13:09jonathan_I guess it sort of is
13:09jonathan_I'm a convert to the JVM
13:09jonathan_Especially now it's open
13:09scramflotperhaps I would be excited about arc if I new enough about Lisp in general, but for now I think clojure has quite a few benefits
13:11jonathan_the syntax sucks less in Arc, but it seems like it doesn't add a whole lot
13:13jonathan_It seems like with concurrency, everyone has to move towards functional programming
13:13scramflotactually, io probably got me interested in all these languages.
13:15jonathan_and what pushed you towards io?
13:15scramflothype... and then it was really simple to start hacking..
13:16scramflotI still play around with it from time to time
13:18jonathan_it does look interesting
13:19jonathan_actually, it's really easy to port Java code into Clojure, like simple web servers and stuff
13:20jonathan_the worst part is ocasional broken library behavior
13:21jonathan_and insane verbosity for InputBufferedStreamReader and friends
13:21scramflotaye
13:22scramflotdo you ever juts cut and paste large multi-line code blocks into the repl?
13:22scramflots/juts/just
13:22jonathan_Yes, that's how I work
13:23scramflotdo you see anything wrong with this?
13:23jonathan_then build it into a file once it's debugged
13:23scramflot(import '(javax.swing JFrame JLabel JTextField JButton)
13:23scramflot '(java.awt.event ActionListener)
13:23scramflot '(java.awt GridLayout))
13:23scramflot(defn celsius []
13:23scramflot (let [frame (new JFrame "Celsius Converter")
13:23scramflot temp-text (new JTextField)
13:23scramflot celsius-label (new JLabel "Celsius")
13:23scramflot convert-button (new JButton "Convert")
13:23scramflot fahrenheit-label (new JLabel "Fahrenheit")]
13:23scramflot (. convert-button
13:23scramflot (addActionListener
13:23scramflot (implement [ActionListener]
13:23scramflot (actionPerformed [evt]
13:23scramflot (let [c (. Double (parseDouble (. temp-text (getText))))]
13:23scramflot (. fahrenheit-label
13:23scramflot (setText (strcat (+ 32 (* 1.8 c)) " Fahrenheit"))))))))
13:23scramflot (doto frame
13:23scramflot (setLayout (new GridLayout 2 2 3 3))
13:23scramflot (add temp-text) (add celsius-label)
13:23scramflot (add convert-button) (add fahrenheit-label)
13:23scramflot (setSize 300 80) (setVisible :t))))
13:23scramflot(celsius)
13:23scramfloter. how bout I just get the link for you...
13:23scramflothttp://clojure.sourceforge.net/features/jvm_hosted.html
13:24scramflotthere.. sorry about that
13:24jonathan_works for me ...
13:25scramflothhmm.. yea, it works now here too
13:25jonathan_25 oC = 77 F
13:25jonathan_you might have missed a bracket
13:25scramflotthe first time I pasted it in, I was cutting from the pdf of the presentation
13:25scramflotaye
13:25jonathan_probably a fancy '
13:25jonathan_`
13:25scramflotah, I've heard of pdfs doing that
13:25jonathan_the repl doesn't like tabs
13:26jonathan_notepad2 untabify
13:26jonathan_damn, a repl in netbeans would be great
13:27jonathan_netbeans kicks visual studios ass
13:28scramflotI do like netbeans the best, but I really want to like eclipse
13:28jonathan_I think I tried it once, then moved on
13:29scramflotit's just slow
13:29jonathan_yeah, netbeans is faster than visual studio now
13:29jonathan_mainly because visual studio is so crappy
13:30jonathan_Build big .NET projects is terrible
13:30jonathan_dependency hell
13:30jonathan_assembly hell
13:30jonathan_Our apps *have* to be installed locally now
13:31jonathan_It's 10x worse than Java ever was
13:31scramflothmm
13:34jonathan_It's a shame because the .NET guy did turbo pascal originally I believe
13:35jonathan_I wonder ... if that still exsts
13:40bgeronwe use delphi at school, but it's proprietary :(
13:41jonathan_aren't there a bunch of free pascal compilers that do the same thing?
13:42bgeronyes
13:42jonathan_That's cool, what kind of stuff do you write?
13:42bgeronbut they don't do GUI design as ugly as delphi does, which why I must use delphi
13:43bgeronit's not that cool, actually ;) last time I had to write a program that drew random points on a plane, then let you rotate/shift a duplicate of that plane
13:44bgeronyou get the illusion of circles then
13:44bgeronand when you right-rotate, then shift right, the circle moves down (because the points down are first shifted left, then right again so there's the center)
13:45jonathan_I think that sounds pretty neat
13:45jonathan_you're not far off rotating shapes
13:45bgeronI'm not sure about that
13:46jonathan_graphics is fun
13:46bgeronagree, but this did not really extend to graphics in general
13:46bgeronthe painting routing (blegh, painting) was changed to paint each point twice
13:49jonathan_what would happen if you shifted the plane in 3d
13:49jonathan_you'd get donuts right?
13:50bgeronnot with shifting, I think
13:50jonathan_sorry rotating
13:50bgeronyou get a donut if you wrap it or something
13:51jonathan_damn, time for a snack
14:40jgracinhi all!
14:41jonathan_hi, what's happening?
14:42jgracinToday, I was trying to figure out the way to implement function "disassemble" but no luck.
14:42jgracinSeems that the version of ASM is a bit cut down.
14:42jgracinNo ASMifier... and stuff.
14:44jonathan_I haven't looked at the source ... what does Clojure use that for?
14:44jgracinfor bytecode generation
14:46jonathan_so like recur jumps and stuff?
14:46jgracinClojure instantly compiles all function definitions into JVM bytecode.
14:47jgracinwhen you evaluate (defn f [] 1) it is compiled into JVM bytecode.
14:47jonathan_I've been using it for prototyping and I know it's fast but I wasn't sure what is going on underneath
14:47jgracinI was trying to see what does the compiled code looks like.
14:48jonathan_the actually jvm instructions?
14:48jgracinActually, I was getting surprisingly slow results on some trivial benchmarks so I wanted to check the JVM instructions.
14:48jonathan_are you type hinting?
14:50jgracinYes, I am, but I'm not sure if the hints are ignored cause I can't see the code that gets produces. :-)
14:50jgracinproduced.
14:51jgracinsumming a range of numbers, from 1 to n
14:51jgracintakes very long time
14:51jgracincompared to SBCL, and GCC.
14:52jgracinand I'm sure that SBCL and GCC didn't optimize the loop out.
14:53jonathan_user=> (dotimes n 100 (time (reduce + (range 1 1000))))
14:53jonathan_"Elapsed time: 1.572 msecs"
14:54jonathan_"Elapsed time: 1.003 msecs"
14:54jonathan_"Elapsed time: 0.997 msecs"
14:54jonathan_"Elapsed time: 1.559 msecs"
14:54jonathan_like that?
14:54jgracinYes. GCC sums from 0 to 2 000 000 000 in 1.7 seconds.
14:55jonathan_hahahah
14:55jonathan_what kind of speed in raw Java?
14:55jgracinand java version is even faster (around 1 second), but I'm not sure what the compiler does to it.
14:55jonathan_GCJ?
14:56jonathan_or javac?
14:56jgracinjavac
14:57jonathan_wow, that's impressive, but seems like a limited benchmark
14:57jgracinOf course, it's stupid, but it was just a sanity check.
14:57jgracin:-) a stupid sanity check.
14:57jgracinLet me show you the code....
14:58jonathan_I've had some great results with JDBC, in fact Clojure makes it pretty easy to build up big bundles of data recursively, and it is really quick
14:58jonathan_sure
15:01jgracinit's here http://www.inge-mark.hr/~gracin/bm.clj
15:02jgracinOh, maybe it's because of overflow in sum!
15:03jonathan_aha
15:03jgracinI couldn't have been so stupid
15:03jonathan_lol
15:03jonathan_Is the 'loop' necesary
15:05jonathan_maybe the loop is better than having an alt parameter set
15:06jgracinI'd have to have a 'sum' parameter in the function lambda list.
15:06jonathan_add a single param form that calls the two param form
15:06jonathan_(reduce + '(1 2 3)) must have two forms
15:07jonathan_I was really surprised when that worked
15:09jonathan_I would have pasted some code but my clip is messed up
15:09scramflot(dotimes n 5 (time (reduce + (range 1 1000000000)))) -> java.lang.OutOfMemoryError: Java heap space ;)
15:10jonathan_http://pastebin.com/d53bad58e
15:12jonathan_Handles merging date ranges together ... it's a tad long-winded
15:12jgracinthanks, I'll have a look. I'm not sure I understand what you said the above, which part were you surprised with?
15:12jonathan_doesn't reduce normally need an accumulator?
15:13jonathan_arrggg
15:13jonathan_(+ 1) = 1???
15:13jgracinoh, I see
15:13jonathan_it must special case the first call
15:15jonathan_The more functional programming I see, the more I like it
15:15jgracinI've just check CLHS and it says that the function to reduce must accept no arguments, and two arguments.
15:15jgracin(+) = 0
15:16jonathan_lol, You are leaving Common Lisp, thanks for visiting
15:16jgracinthat's probably what Clojure does as well. It's easy to check.
15:16jgracinFirst call is the call with no args.
15:17jonathan_user=> (+)
15:17jonathan_0
15:17jonathan_user=> (*)
15:17jonathan_1
15:17jonathan_user=>
15:17jonathan_so I wonder where that comes from?
15:18jonathan_(defn reduce
15:18jonathan_ ([f coll]
15:18jonathan_ (if (seq coll)
15:18jonathan_ (reduce f (first coll) (rest coll))
15:18jonathan_ (f)))
15:18jonathan_ ([f val coll]
15:18jonathan_ (if (seq coll)
15:18jonathan_ (recur f (f val (first coll)) (rest coll))
15:18jonathan_ val)))
15:18jonathan_That's the actual code
15:21jgracinof course, makes sense.
15:22jonathan_yeah, I love that all the neat stuff is in boot.clj
15:22jgracinI wonder why CL mandates that the function must be able to take no arguments.
15:23jonathan_no arguments = nil? easier to compose ?
15:25jgracinjonathan_: nice talking to you. bbl.
15:25jonathan_ttl
16:14jonathan_(seq (.. interface (getClass) (getMethods)))
16:14jonathan_(def interface
16:14jonathan_(implement [ActionListener]
16:14jonathan_ (actionPerformed [evt]
16:14jonathan_ (print (str evt)))))
16:15jonathan_pretty sweet, can reflect into the Proxy0 objects that implement generates
16:30jonathan_hey jg, made any progress on figuring out if you can reflect method code?
16:33jgracinnope. I've put it aside for the moment. I'm currently reading JVM specification. :-)
16:33jonathan_k
16:35jgracinJVM code looks very unusual to someone having only experience with x86 and Sparc.
16:36jgracinI have some catching up to do.
16:37jgracinbtw, I haven't solved that benchmark problem. Even without those overflows, the speed is rather low.
16:42jgracinthis code http://pastebin.com/d5126d011 is 20 times slower than the equiv. Java or CL code.
16:43jonathan_haha, we had Sun 3/50's at uni and we ran 3 guys to a box
16:44jonathan_that was kinda slow
16:44jonathan_20x slower seems like a reasonble trade for 20x easier to write
16:52jonathan_Hey Rich, thanks for such an awesome language!!
16:53rhickeyyou're welcome!
16:56jonathan_I have a question, can we call the classloader and get access to the compiled 'class' files in memory? (just playing really)
16:57rhickeynot officially - they can't be serialized for reuse without dealing with the constants
17:00jonathan_constants?
17:01rhickeyliterals, quoted things etc
17:01rhickeyi.e. some of the code really is data and would need to be reconstituted
17:02jonathan_ok, what actually comes out of the code generation ... is there a class file in mmory?
17:03rhickeyyup, plus some data literals that get passed through the classloader
17:03jonathan_ahhhh, I should have started at the repl ;-)
17:12scramflotrhickey: hi.. jonathan_ helped me out and explained some of the questions I had. Pretty kick ass!
17:15rhickeygreat!
17:15jonathan_so if you compile a closure, you have to fixup any outside vars when you load?
17:16rhickeyevery function becomes a class and its ctor takes any closed-over vars
17:17jonathan_ahh, that's really neat
17:17scramflotjonathan_ brought up a good point. There should be a wiki where we can post up snippets and examples.
17:19rhickeyI was hoping to use Google code for wiki and issue tracking but they don't support CPL projects
17:22scramflotwha? that's wild
17:22jonathan_patents?
17:22rhickeyno they only support a few licenses in order to reduce proliferation
17:23jonathan_ah ok (the non-sinister reason ;-) )
17:24rhickeyjust looking now - seems like sourceforge has wiki support, I'll look into it
17:24scramfloteh.. sf's community tools are ug'
17:25scramflotthere's wiki-books too
17:25scramflotsome languages just link to that
17:25scramflot(or open-source projects in general)
17:25rhickeyI know, I've avoided the other sf stuff other than code/web hosting
17:27jonathan_I learnt 10x more playing with the code in boot.clj than reading lisp books, so an annotated version of that up on a web might be awesome
17:27rhickeyinteresting idea
17:29jonathan_it's interesting that so much of the language is in boot.clj ...
17:29scramflotYea, with an intro to help someone understand the boot.clj
17:30rhickeyThat's what's so cool about Lisp, just implement the core and then the rest of the language in itself
17:30scramflotthe syntax, etc... like, for instance, it could be because I'm so unfamiliar with functional languages in general, but... I had to ask jonathan_ about:
17:30jonathan_memfn and comp in the resultset-seq code ... I had to go runing to boot.clj to find out what that was all about
17:30scramflot(defn make-adder [x] (let [y x] (fn [z] (+ y z))))
17:31scramflotnow, after his explaining, I understand that add2 simply resolves to (fn [z] (+ 2 z))
17:31rhickeyI think every function is documented on the web site now (memfn, comp etc)
17:32jonathan_cool, does that include namespaces now ...
17:32rhickeyyes, functions returning functions is a higher order thing you might not see much outside of functional/lisp languages
17:33rhickeynot namespaces yet, I try to keep the docs in sync with the release so people downloading don't get mixed messages - I hope to make a release soon
17:34jonathan_ah ok, of course, that makes sense
17:34scramflotI've seen namespaces talked about, in the reference maybe?
17:35rhickeythey've been greatly enhanced recently, so are due for a doc update
17:35rhickeyI put a decent description in a message on the google group
17:36scramflotah, that'd be it then
17:36jonathan_yep, and I noticed that class has gone away
17:37rhickeynot needed, just use the classname
17:37jonathan_yeah nice
17:37jonathan_Errr, yeah, I had a question: If I had a server that serves as a 'cache' for some data in an Oracle db, how would I sensibly access that and update it ... I was just (def *cache* ...) ing it, which works, but it seems like I'd want to put it in a ref or something?
17:38jonathan_*it = the bundle of hashes
17:38rhickeyYes, use a ref - which you can put in a var - (def cache (ref {}))
17:40jonathan_cool, having Clojure makes prototyping even business software fun
17:41jonathan_and pure Java oracle drivers are just icing
17:42scramflotfor add2, is it possible to reach return a copy of add2, changing the value of 2 to 3?
17:43rhickeyyou can't 'get at' the closed-over locals in a fn - fn values are opaque
17:43jonathan_unless you write an accessor and return that?
17:44scramflotbut can I copy, changing a closed over value, without rewriting the whole function?
17:44scramflotso, return a new function, with a different value
17:44rhickeyNot exactly sure - what code do you want to write?
17:46scramflotwell, I'm just thinking about it.. listened to some of your talk a while ago actually.. and you said something like "lispers are used to being able to type into the repl, change the code, and polish the product" etc, etc.. something like that
17:47scramflotI'm wondering how I'd modify a buggy function without having to rewrite the whole thing
17:48rhickeyAh - ok. If some fn bar calls foo, and you redefine foo, the next call to bar will use the new foo.
17:48rhickeytry it
17:50scramflotoh, so keep functions relatively small... the group of functions modular.. and it's easily modifiable. But returning a new function with one of it's values changed isn't what it's about, right?
17:51rhickeyRight, the "values" of the function are private to it
17:53jgracinscramflot: One keeps the source of functions in the editor which is connected to the repl and then you don't actually rewrite anything. Sorry if I'm stating the obvious.
17:54jgracinyou change the stuff in the editor and send the new definition to the REPL, i.e. the Lisp image.
17:54scramflotjgracin: yea, I'm tracking that it can be done that way... be back in a min.. to get deeper at my curiousity here
17:57jonathan_is there a way to use SLIME?
17:58jonathan_or similar?
17:58jgracinjonathan_: I use Clojure mode and paredit.
17:59rhickeynot right now - someone who knows more about the protocol might take a crack at it. I'm hoping the new first-class namespaces will facilitate things like that.
18:00jonathan_Yeah, I just paste from TextEdit or notepad2 right now
18:01jgracinrhickey: the ASM in the Clojure sources is a stripped down version 3.0, am I right? I cannot find some classes like ASMifier... and stuff.
18:02jgracinjonathan_: Clojure mode uses inferior-mode, so it's much easier than copy-paste.
18:02rhickeyright - subset of ASM to keep the size down.
18:03rhickeywith debug off clojure.jar is < 250k
18:03jgracinrhickey: I was trying to write a "disassemble" function but I failed. Do you think it's achievable with what's currently in the Clojure?
18:04rhickeyNope, but it's possible to see what's going on by:
18:04rhickeyputting full ASM in your classpath,
18:05rhickeyswap the import comments on the top of Compiler.java,
18:06rhickeyswapping the cv initialization with the line below in Compiler.FnExpr.compile()
18:07rhickeyThen Clojure will spew full disassembly of everything it compiles (i.e. my dirty laundry :)
18:08rhickeyThat's what I do to debug code-gen
18:10jgracinCool, thanks, I'll try that. Have you considered adding this functionality to the main code?
18:11rhickeyyes, unfortunately it doubles the size of ASM's contribution to Clojure's size (it's almost 50% right now)
18:13scramflotback.. so can you do something like: (defn make-operator [x] (let [myx x] (fn [a] (let [mya a] (myx mya b))))) ?
18:13scramflotembedding a let inside a let
18:13scramflotand a function inside a function
18:16jgracinBed time for me. Bye all!
18:17rhickeyyou can, but I wonder if make-adder hasn't set you off on the wrong track - most functions are defined directly with defn and not by a function-defining-function like make-adder
18:18scramflotI'm not under the impression that that is prescribed method of function composition.. I was just wondering about how deep one could layer the closures
18:19rhickeyindefinitely deep
18:20scramflotdoing so too deeply would result in brittle code though, right?
18:21rhickeyyes, the deeper you get the more difficult it becomes to independently test the parts
18:21scramflotcause you can't really modify the nested structure much
18:22rhickeyyou can't modify it at all - all those locals are immutable
18:24jonathan_I've been surprised at how quick it is to use assoc to generate updated copied of hashes ... that completely rocks
18:26rhickeyHotSpot can do a great job optimizing all of the final stuff in the persistent classes
18:27jonathan_yeah I always like to write the simplest functional type code ... and it's always been plenty fast so far
18:27jonathan_try to anyway
18:31jonathan_do you know of any interesting uses of Clojure yet Rich?
18:32rhickeyNone I can talk about, but I was thinking of asking on the group
18:34jonathan_That'd be cool, it seems like there's a few people coming and looking around, esp. with all the Arc buzz going on
18:35rhickeyYup, the arc release has caused people to look at Clojure
18:37rhickeyI think Clojure has more to offer, but I'm biased :)
18:38jonathan_I completely agree ... the indexers, refs, stm mainly stuff I haven't got to yet, but I've written a GUI in 500 lines that kicks the ass of 4000 lines of C++ ... so I'm pretty sold
18:39jonathan_great for prototyping ideas that people don't think can be made to happen ...
18:40jonathan_though a simple undo/redo stack is considered 'impossible' at my company, as are 'splitters' in a GUI .... it's like a research project
18:40rhickeyWell, keep blogging about your success with Clojure - it helps
18:41jonathan_I sure will, I honestly haven't ever enjoying writing code as much .... only Javascript comes close
18:41jonathan_oh, why is [] required on apply ?
18:41jonathan_for the args
18:42rhickeyThe last arg to apply must be a collection/seq - is that what you mean?
18:43jonathan_right
18:43jonathan_sorry phrased it badly, couldn't apply be & rest ?
18:45rhickeythen it would only collect args and still not give you a way to apply a fn to an arglist already in hand.
18:45jonathan_ok, I'll go read the code ... ohhh I think I understand, thanks
18:46rhickeyDinner time here - bye all!
18:46jonathan_k byee
23:11rhickeyI added a Clojure Programming book to wikibooks.org - just an outline right now
23:27jonathan_wow, that's awesome
23:28jonathan_I'll go take a look
23:31jonathan_what's it under Rich? I can't see anything
23:31rhickeyhttp://en.wikibooks.org/wiki/Clojure_Programming
23:33jonathan_cool, just needs some content :)
23:34rhickeyyup
23:37jonathan_I've been in a greek restaurant for the last 3 hours, so I'm a tad dazed
23:38rhickeytoday is over for me, bye all