#clojure logs

2011-05-01

01:28hiredmanhttps://github.com/hiredman/javap-mode might be of interest to some people here
01:30hiredmanhttp://www.thelastcitadel.com/images/javap-mode.png
01:38technomancyhiredman: your haskell growl is showing =P
01:39hiredmanI know
01:39hiredmangrowls by https://github.com/hiredman/Howler
01:41hiredmanI guess I should figure out parsley since that seems like it will be the "blessed" parsing library
01:41hiredman"An experimental undocumented parser lib/DSL." the docstring for the parsley namespace
01:42technomancyclojurebot: dsl?
01:42clojurebotHuh?
01:43technomancyclojurebot: just wondering if you had any clever one-liners on the topic.
01:43clojurebotGabh mo leithscéal?
02:44lisperadoanyb ody here?
02:44brehautprobably
02:44lisperadooh cool.
02:45lisperadoi'm trying to get cljr installed
02:45lisperadodo you or anybody else use cljr?
02:45brehauti do
02:45brehauton a mac
02:46lisperadogreat. i'm on mac also.
02:46lisperadoi got an error trying to install it.
02:46lisperadoi filed a bug report, but i don't think liebke maintains the program anymore
02:47brehautthat does appear to be the case
02:48lisperadoi wrote about it here: https://github.com/liebke/cljr/issues/21
02:49brehautno idea sorry; i just followed the instructions and it was fine
02:50lisperadointeresting...do you use maven or maven2?
02:50brehautdirectly?
02:50lisperadowellno, i mean do you have maven or maven2 installed?
02:50lisperadoi think clhr uses maven, but i have maven2 installed
02:50brehauti have no idea; if they are i havent installed it myself.
02:50brehautcljr is built on lein which is mvn2
02:51lisperadothat makes esnse
03:04amalloycljr is old and crufty. it should work, but it really does not improve the UX compared to say, cake, in any way
03:04amalloysudo gem install cake && cake repl
03:04amalloybam, you have a repl
03:05lisperadointeresting...thanks!
03:05lisperadois cake a ruby tool?
03:05amalloyit's clojure with a thin ruby layer to get things started
03:05amalloy(like lein is clojure with a thin bash layer)
03:06lisperadoi was planning to use cljr to install compoure. can cake do that?
03:06hiredman(use lein)
03:06lisperadoeh? how do i use lein to install compojure?
03:06amalloydon't. throw away everything in your head about "installing"
03:07amalloyyou specify dependencies per project, so you never have to do global installs. neither does anyone else using your project; they just fetch your project and maven gets your dependencies too
03:08amalloyyou don't even install clojure. clojure.jar is one of the ordinary dependencies in your project
03:08amalloy$google Raynes getting started with clojure
03:08sexpbotFirst out of 69 results is: An indirect guide to getting started with Clojure » Bathroom ...
03:08sexpbothttp://blog.raynes.me/%3Fp%3D48
03:08amalloyargh that link still sucks
03:09amalloyhttp://blog.raynes.me/?p=48
03:09lisperadothanks. i'll read that page and get up to speed
12:12datkaDoes anyone know of any projects that are using Cuke4Duke with Compojure? I'm looking for good examples.
13:03fliebeldnolen: I gave the second paper a try, and they said that after cannonicallisation, predicate dispatch is reduced to multi dispatch. Does that mean you can write any predicate dispatch with a defmulti? And does that also mean you're going to write a faster defmulti?
13:05dnolenfliebel: you could probably compile to defmulti, but defmulti is slow for certain things because of it's design. I want to build everything on case. I think it could be as much as 6X faster than defmulti for some things.
13:06fliebeldnolen: So you're not using a binary decision tree then? Because in that case 'if' would suffice I assume?
13:07dnolenfliebel: if is slow for multiway decisions (think types)
13:07dnolenif checks nil
13:22thorwilhrmp, seems Enlive refuses to work on stuff within <script> tags
13:28raekthorwil: html elements inside script tags?
13:30thorwilraek: that, too. but content and co also seem unreliable and nth-of-type either does nothing, or works on all the script elements with (nth-type 1)
13:30thorwil(i tried tags inside <script> only as possible workaround)
13:31raekI assume that tagsoup (the underlying lib that does the parsing) treats everything between the script tags as text
13:33raekit is built to reasonably be able to parse any html document, no matter how badly it's written
13:34raek(so that's why I think < is always treated as text in a script, unless it's the stop element)
13:37thorwilmakes perfect sense. i can use prepend to insert that one line i need. only it must be in the 3rd script tag
13:38thorwil[[:script (en/nth-of-type 3)]] doesn't match
13:39thorwilwith 2 doesn't either, with 1 it matches all 3 script elements
13:42raekI tested it on a page with two script elements and (select foo [:script]) returns two elements, as expected
13:44thorwili get the same behavior with 3 consecutive <p> and [[:p (en/nth-of-type 3)]]. no effect, but selects all 3 if i use nth-of-type 1
13:45thorwili must be misunderstanding nth-of-type?!
13:45raekhm, how is nth-of-type supposed to work anyway?
13:46thorwil"Selector step, tests if the node has an+b-1 siblings of the same type (tag name) on its left. See CSS :nth-of-type."
13:46raekI don't understand the "an+b-1" part... is "n" a variable?
13:47thorwili got to that function via http://stackoverflow.com/questions/2695701/how-to-select-nth-element-of-particular-type-in-enlive
13:49raekin my case, (select foo [:script (nth-of-type <any number here>)]) always returns ()
13:49raekmaybe it only works on consecutive occurances of the elements
13:50thorwili only tested with consecutive occurrences
13:53Ramblurrdoes the ->> macro have a name? I'm trying to understand it, but searching for it is.. well not working :P
13:54mecRamblurr: thread-last
13:54raekthorwil: ah, now I tested with [[:script (nth-of-type 1)]] insted of [:script (nth-of-type 1)]... it works for me now
13:55thorwilraek: for nth above 1, too?
13:55mecRamblurr: also i think its called something like thrush although that may be ->
13:56thorwili thought -> is thread or threading?
13:56raekthorwil: yes, with 1 and 2 it returns the corresponding script elements
13:57Ramblurrmec: I understand that (a (b (c (x) is the same as (-> x b c a), but what does ->> do?
13:57raekthorwil: maybe you could try (pprint (html-resource ...)) and look how/if the elements appear in the tree
13:57mecRamblurr: ##(->> (range 10) (map inc ,) (reduce + ,))
13:57sexpbot⟹ 55
13:58mec,(macroexpand '(->> (range 10) (map inc ,) (reduce + ,)))
13:58clojurebot(reduce + (clojure.core/->> (range 10) (map inc)))
13:58raekRamblurr: (-> x (a 1 2) (b 3 4)) = (b (a x 1 2) 3 4), but (->> x (a 1 2) (b 3 4)) = (b 3 4 (a 1 2 x))
13:59raekwith -> each step becomes the first argument of the next, but with ->> it becomes the last argument
13:59RamblurrAh.. I see!
14:08thorwilraek: all 3 appear as {:tag :script ... }
14:11thorwil(en/select (en/html-resource "templates/article-form.html") [[:script (en/nth-of-type 2)]]) works perfectly on the repl
14:14alandipert /j #boxgrinder
14:14alandipertwhoops
14:15alandipertalso re: ->>, it's the one known as 'thrush'
14:16alandipertin clojure, since it's implemented syntactically (with macros) as opposed to functionally, it's not quite the 'thursh combinator', but effectively same thing
14:31thorwilso as soon as i want to use nth-of-type in a defsnippet, it stops working
14:31joshuacHow do I get rid of the mapping in clojure-mode that maps return to a re-indent function?
14:32joshuac90% of my frustration with the mode would be gone if that little function wasn't used.
14:35thorwiloh, with the exception to what happens with comments sometimes, i'm glad to have that indention feature
14:39thorwiljoshuac: i guess you could look for the command that does the indentation, then search the clojure mode script for it, to see how it is bound, as that might give you an idea how to rebind/undo that
14:40thorwilactually, that might not be a part of clojure mode
14:41thorwilreindent-then-newline-and-indent could be the command
14:41joshuacthorwil, fixed it
14:42joshuac(add-hook 'clojure-mode-hook
14:42joshuac (lambda ()
14:42joshuac (define-key clojure-mode-map (kbd "RET") nil)))
14:43thorwiljoshuac: i would have been worried to render RET entirely effectless
14:44joshuacthorwil, I just can't keep putting up with a not-perfect indenting feature which 'changes' code that is indented properly to something that isn't. A lot of the time its fine, but the times its wrong really bug me.
14:45joshuacthorwil, It should really just put the cursor at where it expects to indent to on the next line like most other modes I've used do.
14:46joshuacthorwil, *in my opinion
14:46raekjoshuac: in recent versions, you can configure it to use 2-space indentation for your own macros
14:47joshuacraek, I like conds to have the sexps which correspond to action indented (like you would indent were it an if statement)
14:47raekah, I see.
14:47thorwilraek: my experimentation suggests that nth-of-type works in an enlive transform, but not in transformation 0.o
14:49joshuacraek, example of what I mean. What I like on top what the default is in the clojure-mode
14:49joshuachttps://gist.github.com/950732
14:57hippiehunterdoes anyone in here use clojure-clr?
15:01thorwilraek: i figured it out. nth-of-type failed in my defsnippet, because the script tags end up on the top level, having no parent! thanks for looking into this
15:02thorwilthough this is very inconvenient, with the way i constructed my views so far :/
15:11amalloytechnomancy: you around? trying out slamhound and it's not able to handle compojure's GET
15:24milkposttechnomancy: so you pressured some guy with a vim-themed blog to switch to emacs? HA http://writequit.org/blog/?p=431
15:26amalloytrying to debug it myself is a fun adventure, though. so far it seems that (default-disambiguator (candidates :use "GET")) is returning [compojure.core :only [GET]] when i call it manually, so i'm puzzled as to how it's throwing an exception when you call it: https://gist.github.com/950773
15:51Ramblurris there a way to set a default value for a function argument?
15:51Ramblurre.g., if i have a function that takes a number, if it is not passed a number i'd like it to be 1
15:53thorwilRamblurr: write 2 signatures, use the first with lower arity to call the function with one argument more
15:53pdk,((fn ([x 1]) x))
15:53clojurebotjava.lang.RuntimeException: java.lang.RuntimeException: java.lang.UnsupportedOperationException: nth not supported on this type: Symbol
15:53pdk,((fn [[x 1]] x))
15:53thorwilRamblurr: http://stackoverflow.com/questions/3208347/how-to-create-default-value-for-function-argument-in-clojure
15:53clojurebotjava.lang.Exception: Unsupported binding form: 1
15:53pdkderp
15:54Ramblurrlike (foo [] (foo 1) [n] stuff_with_n) ?
15:54amalloyRamblurr: almost, though the syntax isn't right
15:54fliebelRamblurr: Extra parens
15:54amalloy&((fn foo ([] (foo 1)) ([x] (inc x))))
15:54sexpbot⟹ 2
15:55amalloyaside: the compiler needs those extra parens to be able to tell "multiple function bodies" apart from "single body with multiple side-effecting forms"
15:57Ramblurramalloy: how would that look using defn?
15:58amalloyum, the same. just change fn to defn, and don't wrap it with the extra parens i used to call the function
15:58milkposthow do you call functions until one returns non-nil?
15:58amalloydefn is really implemented as a macro that expands into (def whatever (fn ...))
15:59amalloymilkpost: (first (drop-while (complement nil?) (map #(%) list-of-functions)))?
15:59milkposthrm
16:00amalloyer, except it shouldn't be complemented at all. just drop-while nil?
16:00milkpostyeah probably, shit i'm such a newb to this
16:00ihodesmilkpost: what are you trying to do?
16:01milkpostnothing, i was just curious
16:01ihodesmilkpost: ah okay; i was thinking that probably wouldn't be a great way to do most thing. probably an easier way to accomplish the same thing that's not so nondeterministic
16:01milkpostlearned how to implement fizzbuzz and the implementation i'm looking at concats calls to different functions, rather than the first one that matches
16:02milkpostbut now i'm looking at how to print odd numbers and extend that to other things.. trying to get a feel for this...
16:03raekmilkpost: I think it would simply be easier to filter the values
16:03milkposthrm.
16:03raekand do the printing later
16:04milkpostah yes
16:06ihodesmilkpost: what do you have so far?
16:06milkpostahh give me a few more secs
16:08milkposthttps://gist.github.com/950816
16:09joshuacHmm. Bit confused. I'm importing Java's "java.awt.geom.Line2D" class. Than I'm trying to access the nested class it contains, Double, with Line2D/Double. I take it that I'm not doing this right.
16:09milkposti'm actually trying to print the numbers that are at 10%, 20%, ... of the maximum value
16:09milkpostbut i'm not sure how to do partial evaluation of a function
16:09amalloyLine2D$Double
16:10ihodes(partial fn args ..)
16:10amalloyihodes: i'd be very surprised if that's what he meant by partial evaluation, in context
16:10joshuacamalloy, Thanks. Now that I've read that I'm able to see that it is in fact metnioned in the docs.
16:10milkpostihodes: is there a better way to do what I am doing?
16:11ihodesamalloy: yeah you're probably right. i saw partial, and there i went
16:12milkpostactually that is what I meant
16:12ihodesmilkpost: i'm not quite sure what you're doing yet, but you can use zero? instead of = 0
16:12milkposthttps://gist.github.com/950820
16:13amalloyor #{0}, har har
16:13milkpostso, if i have 100 i want 10, 20, 30, 40... 90.
16:14ihodes(filter #(zero? (mod % 10)) (range 100))
16:14milkpostbut i actually want to iterate through each item of the range from 0 to 100
16:14ihodesi'd use filter for that
16:15milkposti have no idea what the hell that #( thing is... will go read some more
16:15raekmilkpost: my solution: https://gist.github.com/950822
16:15ihodesah, sorry; that's syntactic sugar for (fn [x..] ...)
16:15Ramblurrcan you use the #(..) macro with multiple arguments?
16:15alandipert,(take-nth 10 (range 100))
16:15clojurebot(0 10 20 30 40 50 60 70 80 90)
16:15amalloyyes, but it's not a macro
16:15ihodesso what i just wrote == (filter (fn [n] (zero? (mod n 10))) (range 100)
16:15amalloy#(+ %1 %2)
16:15raekRamblurr: yes, just use the symbols %1, %2, %3, etc
16:16milkpostalandipert: not quite, because if i give 200, then i want 20, 40, 60... like 10% of max, 20% of max, etc.
16:16Ramblurramalloy: its not a macro?
16:16amalloyRamblurr: it's part of the compiler syntax
16:17amalloy&'#(inc %)
16:17sexpbot⟹ (fn* [p1__37356#] (inc p1__37356#))
16:17ihodesmilkpost: ah, i get ywhat you're asking now.
16:17milkpostthat works though very nicely
16:17milkpostso % defaults to %1?
16:17amalloyit's a synonym for %1
16:17ihodesmilkpost: yes
16:18milkposti figured there had to be some way to do it but for me it was easier to define a new function, and now i have learned about inline function definitions and partial functions :)
16:18technomancyamalloy: yeah, it assumes capitalized references are classes... not sure what to do about compojure.
16:18ihodesand technomancy comes from left field!
16:19amalloya macro in that position (ie, after a quote) wouldn't be expanded: ##'(dotimes [x 1] (prn x))
16:19sexpbot⟹ (dotimes [x 1] (prn x))
16:19amalloytechnomancy: can't you have it try :use, :require, and :import and return the first that succeeds, rather than deciding which to use based on the symbol?
16:19ihodesmilkpost: for your problem, i'd first identify what 10% of your value is, then i'd filter the range of that value using the #(zero? (mod % 1/10valuethinghere))
16:20ihodesmilkpost: does that make sense?
16:20milkpostihodes: yeah, that's what i was doing. is there any difference between these two functions (performance wise?) https://gist.github.com/950827
16:20technomancyamalloy: that would kill perf
16:20technomancyit's already annoyingly slow
16:21amalloytechnomancy: i doubt it. start by trying the version you currently guess to use
16:21amalloyif that works you can return it
16:21amalloyotherwise, instead of reporting failure, fall back on the other options?
16:21technomancyoh sure... there's lots of room for improvement with fallbacks.
16:21milkpostamalloy: thanks for reminding me. wrapping my denominator in (int ..) is ok? :
16:22milkpostman, i am such a goddamn newb
16:22technomancylittle trickier when they have to cross clause-type boundary, but should be doable
16:22milkposti can see why old people don't learn new things
16:22amalloymilkpost: the second one is faster, but if you care you're kinda crazy imo
16:22amalloyalso that trailing paren is bizarre
16:23technomancyamalloy: the problem is the errors compiler gives seem pretty arbitrary most of the time
16:23milkpostamalloy: hehe
16:23amalloytechnomancy: for sure, compiler errors are gross
16:25ihodesmilkpost: looks good. that's pretty idiomatic as well. 2nding what amalloy said about the rest.
16:26milkpostamalloy: i am crazy!
16:26amalloytechnomancy: i can fork slamhound and see what i can do. do i understand you correctly that you split up the missing symbols into :require, :use, :import *before* you try anytihng?
16:26milkpostthis was just a test. I am running a 2billion iteration loop in python and it sucks speed wise, so I was just curious about C speed and clojure speed comparatively and just as a learning excercise.
16:27ihodesamalloy: is the second one actually faster? clojure wouldn't create optimize that away into an equivalent fn, since n is fixed in that function? that'd be a simple enough reduction, wouldn't it?
16:28amalloyihodes: only if it knows that / has no side effects
16:28ihodesamalloy: wouldn't it know that? or is there a flag for that?
16:28amalloythere is no such flag. it might know it, i dunno
16:29ihodesamalloy: it just seems wasteful otherwise, and such a simple reduction since there's a closure created (?) once n is known.
16:29ihodesn is fixed
16:30amalloy&(let [n 100000] (time (dotimes [_ 1e7] (/ n 10))))
16:30sexpbot⟹ "Elapsed time: 1233.126597 msecs" nil
16:30raekthe anonymous function closes over a variable in both cases
16:30amalloy&(let [n 100000 quot (/ n 10)] (time (dotimes [_ 1e7] quot)))
16:30sexpbot⟹ "Elapsed time: 11.278353 msecs" nil
16:30ihodesso sad :(
16:31ihodesthat's really too bad. wasteful requirement of let-binding for something that's clearly fixed.
16:31amalloyi don't understand what you're saying about "closure created(?)"
16:33ihodesi am using the wrong terminology, but once the function (milkpost linked to) is called with an 'n' that is some integer or another, that integer won't be changing; n is no longer a free variable. so there are algorithmic lambda calc reductions you do, i *think*
16:33ihodesbut i guess there's not a great way for the compilter to know what there's no side effects
16:34ihodesthat*
16:34amalloyihodes: feel free to implement that in the clojure compiler, and tag every function and method in the jvm with :is-pure :P
16:35Deranderit would really be awesome if there was metadata to tell if a function was pure
16:36ihodesamalloy: it could be worth it ;) i was just surprised that wasn't something already there! tagging methods wouldn't be necessary, just would have to tag the clojure wrapper for the method if you needed to. it probably wouldn't be too difficult to tag. it'd be harder to figure out the optimizations the compiler could do with the knowledge
16:36alandipertthere is very recently :const in clojure for constants
16:36ihodesi guess, immediately, it could automatically put values into let-bindings like in the example we were previoulsy discussing. i wonder if that'd be difficult to do
16:36alandipertit's the most performant way to name a value you know won't change
16:37alandipert(def constants {:pi 3.14}) (def ^:const pi (:pi constants))
16:37ihodesi've got to head out for now. neat conversation :)
16:37milkpostshit, did i start a war?
16:38alandipertalso if your function is pure, you can memoize it
16:39technomancyamalloy: yeah, the failure-details function is the part that classifies the exception message
16:40amalloyalandipert: that's more work than just let'ing the result of the function in many cases
16:40technomancyI'm not too sold on that flow; it might be better if check-for-details just returned the message intact and it got analyzed in grow-step
16:40alandipertoptimization is always more work.. which is why i try to avoid it :)
16:42technomancyamalloy: would be great if you want to hack it. feel free to ask if you've got any further questions.
16:42amalloytechnomancy: what's the primary entry point function for slamhound?
16:43technomancyamalloy: slam.hound/reconstruct
16:43technomancyamalloy: did you see http://technomancy.us/148 ?
16:43amalloyyeah, read it last night
16:43technomancycool
16:44mecShoudnt (case expr ...) be equal to (condp = expr ...) when the tests are numbers? I'd think so but condp works and case gives me an exception
16:45amalloymec: case has some bugs related to macroexpansion and/or code walkers
16:45technomancyamalloy: I was thinking of allowing projects to expose disambiguator logic, but now I'm not sure it's worth the bother
16:45technomancybetter to just make the default disambiguator smarter in most cases, I think
16:45mecamalloy: ah, at first i was about to lose my mind because I couldnt figure out why it was throwing an exception, then i narrowed it down to the case :x
16:46amalloymec: https://twitter.com/#!/4clojure/status/63728776504291328
16:46mecamalloy: lol thats exactly what i was doing
16:47amalloymec: of course. i gave you the link because it shows the clojure jira issue for this if you want to look deeper
16:47alandipertamalloy: ataggart's fix went in on friday, a better case will be in the 1.3 beta
16:47amalloyoh, good news
16:48amalloythanks alandipert
16:48amalloywe may just switch 4clojure to 1.3b in that case
16:48alandipertthat would rule
16:49amalloywhen is the beta hitting?
16:49alandipertsoon :)
16:50alandiperthandful of numerics bugs and enhancements left to do, then we'll probly cut it
16:50amalloytechnomancy: excellent. i can use the cdt to step through slamhound. cool that these two hit at roughly the same time
16:50technomancyfun =)
16:51technomancyjust pushed some lingering tweaks; be sure to grab the latest. I don't have any immediate plans to work on the clj code, just the elisp.
16:51amalloykk
16:51technomancyI'm thinking improving the pretty-printing will be much much easier to do in elisp than clojure
16:51technomancysince elisp lets you treat a form as a string *and* code at the same time, whereas in clojure once you've stringified it, you can't treat it as tokens any more
16:52zrilak<noob>In order to do (binding [foo ...] ...), must I do (def foo) and _only_ that (barring any macros that effect the same thing), or are there other ways? I.e. must this foo var be defined in the root context, or can I introduce a "bindingable" thing at any point in the code?</noob>
16:53amalloy&(doc with-local-vars)
16:53sexpbot⟹ "Macro ([name-vals-vec & body]); varbinding=> symbol init-expr Executes the exprs in a context in which the symbols are bound to vars with per-thread bindings to the init-exprs. The symbols refer to the var objects themselves, and must be accessed with var-get and var-set"
16:54zrilak<smiley>Thanks!</smiley>
16:56technomancyword of caution: with-local-vars is really easy for newcomers to look at and think "that's exactly what I want" when really what you need is to learn how to rephrase your problem without mutation.
16:57technomancyI asked Rich about whether it should be deprecated at the conj, and he mentioned that there's some algorithm that's hard to implement without it, but he did imply it's for advanced usage.
16:58amalloyyeah, good point there. if i've never used it it's probably wrong to recommend to someone who doesn't know it exists
17:01zrilakinteresting, well, I was asking this precisely because I am trying to avoid mutating something at the lexical root
17:02zrilakactually I am not "mutating" the data itself, I just need to have a loop with a symbol keeping the current state, which (possibly) gets changed in every iteration.
17:03zrilakI'm perfectly happy with immutable state objects though.
17:03amalloy&(doc loop)
17:03sexpbot⟹ "Special Form: Please see http://clojure.org/special_forms#loop&quot;
17:03amalloyzrilak: loop and reduce are a million percent better than having any vars at all, for this sort of task
17:04zrilakgood, that'll teach me to jump head-first into a new language without reading the docs.
17:04zrilakI suspect recur too?
17:06technomancyyeah, often actually recur without loop
17:06technomancysince it can recur to the beginning of a function
17:07technomancythough map, filter, and reduce are often better. but it's good to start with loop.
17:07technomancyjust keep in mind it's lower-level than the functions that work in terms of sequences
17:09zrilakI'll actually start by trying to rephrase the behavior I want in terms of map, fliter and reduce -- I am not married to looping, I'd rather learn to do things the language-proper way
17:09zrilakbut yeah, I see your point, each function has its use cases
17:11amalloyzrilak: tooting my own horn a bit, but have you tried 4clojure.com? it's a good interactive introduction to the language, with problems/puzzles of varying difficulty
17:11zrilakforeclosure? that's clever :D
17:12zrilakwhy not, I'll take it for a spin right now
17:13zrilakI'm not new to LISP in general, but I can't claim to have attained some great level of understanding, so I expect I am going to gain most by tackling real code and problems
17:15amalloyzrilak: well, if you come up with a non-awful solution to http://4clojure.com/problem/53 you'll be the first. there are definitely some hard problems here
17:17zrilakawful in terms of run time or hackish code :)
17:18amalloythe latter
17:18amalloywe don't time solutions
17:21alandipertamalloy: d'oh, i was hoping nobody was looking at solutions :)
17:21amalloyalandipert: we're not, actually. but people tweet them
17:21amalloyso all i *actually* know is nobody has tweeted a good one
17:24amalloyalandipert: we don't even save solutions yet. it's an important feature on our list, but for now we're relying on the generosity of the kind strangers at gist.github.com
17:26alandipertamalloy: thanks for clarifying, i dig the use of gists in the interim
17:27amalloyalandipert: yeah, i'm still shaking my head at the remarkable coincidence that i added gisting and tweeting the evening before someone stumbled upon the website for the first time
17:30zrilakI should register to post my solution, yes?
17:30amalloyzrilak: you don't have to. you can tweet anyway
17:30amalloybut we like it if you register
17:30zrilak:)
17:59kencauseyamalloy: I was trying out 4clojure and it seems like if n appears anywhere in the solution to https://www.4clojure.com/problem/21 it triggers the alarm, like even "fn"
17:59kencauseyor "inc"
18:00amalloykencausey: that would be a pretty weird error, and it doesn't happen to me
18:01amalloydid you name your function nth?
18:01amalloycause clojail can't tell you're shadowing it rather than calling it. if that's not the problem, please paste a screenshot or gist your solution and the error message
18:03kencauseyhttp://paste.lisp.org/display/121703
18:04kencauseyerror: "You tripped the alarm! nth is bad!"
18:04amalloyaha, funny
18:04amalloyi'm not really sure how to fix that
18:05amalloy&(macroexpand '(let [[s & r] 10] s))
18:05sexpbot⟹ (let* [vec__37489 10 s (clojure.core/nth vec__37489 0 nil) r (clojure.core/nthnext vec__37489 1)] s)
18:05kencauseyhow is it testing?
18:05amalloykencausey: it macroexpands your code first to check for malice
18:05kencauseyso like my version matches nth itself?
18:05ampleyflywhy is the longest increasing subsequence of [7 6 5 4] = []?
18:06ampleyflyisn't [7] an increasing subsequence?
18:06Rayneskencausey: The macroexpansion of your code uses nth.
18:06amalloykencausey: right, because destructuring uses nth and you use destructuring
18:06kencauseyoh, ok
18:06kencauseyhmm
18:06Raynesamalloy: Not sure where to begin on this one.
18:07amalloyRaynes: not in clojail, i think. add a note in the 4clojure problem
18:07kencauseyok, yes, destructuring rather unnecessary in this case, I just kind of fell into a pattern ther
18:07kencauseythansk
18:08amalloykencausey: not your fault, of course. it "should" work
18:08Raynesamalloy: We could make it so some things can be explicitly set to be checked for in unexpanded code. A bit complicated for an edge case like this.
18:28kencauseyamalloy, Raynes: Should apply be restricted in https://www.4clojure.com/problem/24 ?
18:28amalloyno, why?
18:28kencauseyit seemed like an overly trivial solution
18:28amalloywelcome to learning a language :P
18:28kencauseyI mean, it's not restricted and I wonder if it should be
18:29kencauseyWell, OK I thought this whole section was about writing functions, all the rest have forced me to do so.
18:30amalloyyou're not in the core-functions "section" at the moment
18:30amalloywe don't really have sections, though, just tags
18:36ampleyflyamalloy: [7] is an increasing sequence
18:38zrilakis there a "forward conj" for vectors? (? 1 [2 3]) -> [1 2 3]
18:38zrilakor (? [2 3] 1), okay :)
18:39raekzrilak: no.
18:39zrilakpity.
18:39raekif you need to add to the front, use a list.
18:40raekif you need to add to one end and remove from the other, use a queue
18:40amalloyampleyfly: i suppose so. i didn't write the problem, and it's been solved a number of times as written so i don't really want to change it, aside from rewording the problem so that the text matches the desired output
18:41ampleyflythat works too =)
18:41raekzrilak: you could of course do (into [1] some-vector), but that would run in linear time
18:42zrilakactually, I *do* need conj, I just confused directions. thanks :)
18:44ampleyflyI like 4clojure
18:45amalloyampleyfly: it's only two weeks old. plenty of time to get involved early and improve things
18:46ampleyflyI'm not very skilled with clojure though =)
18:52ampleyflymaybe adding links to documentation for things that are presented would be nice, if it's intended as a learning tool, as it seems
18:52amalloyampleyfly: what do you mean "are presented"?
18:53ampleyflywell, I just saw "Clojure has many different ways to create functions." followed by code containing fn, #( %) and partial
18:54ampleyflyI know what they do, but a link to clojuredocs or something would be nice
18:56dnolenevolving tutorial on core.logic, https://github.com/swannodette/logic-tutorial. any feedback appreciated.
19:03amalloytechnomancy: excitement! slamhound is able to deduce [compojure.core :only [GET]] with no noticeable slowdown. it's choking on wrap-stateful-session though; i need to look into whether i broke that or it was always that way
19:06amalloylooks like that issue is there in your version as well. i'll put together a pull request for GET and then see what's going on with wrap-stateful-session
19:17zrilakamalloy, okay to post a pastie link here, just so you can tell me on which side of "horrible" my solution to 4clojure/53 lies?
19:17amalloyyep, that's what pastie/gist are for
19:17zrilakhttp://pastie.org/1854938
19:18zrilakI'm pretty sure it is not supposed to be THAT verbose, given that tweets are 140-char limited... :)
19:19amalloyzrilak: the tweets are all links to gists anyway
19:19zrilakah, well, okay.
19:19amalloycheck out ##(doc split-with), btw
19:19sexpbot⟹ "([pred coll]); Returns a vector of [(take-while pred coll) (drop-while pred coll)]"
19:21zrilakheh, that looks useful in this context
19:30ampleyflyhow can I check if something is a sequence (like list or vector)?
19:31amalloy&(doc sequential?)
19:31sexpbot⟹ "([coll]); Returns true if coll implements Sequential"
19:31zrilakseq?
19:31clojurebotamac: So it's a seq of connections? And what do you do with them? I understand what disjoined sets look like, but the representation and iteration is where I run into trouble.
19:31amalloyzrilak: nooooo
19:31zrilaknoo ?
19:31amalloy&(seq? [1])
19:31sexpbot⟹ false
19:32zrilakah, gotcha
19:32amalloyseq? only returns true for things that implement ISeq directly (lists and seqs), not "sequential things"
19:32zrilakISeq != Sequential...
19:32zrilakgotcha gotcha, thanks
19:39amalloytechnomancy: further update: slamhound can handle (wrap-stateful-session) because it looks up the symbol, but (session/wrap-stateful-session) it just grabs the first namespace ending in "session" and uses that
19:39pdkhow again do you import java libs from clojure
19:39pdk(require [java awt])?
19:39amalloy(import (java.awt Point Rectangle))
19:40pdkhow about for *
19:40amalloypdk: don't. it's bad form in java, and not allowed in clojure
20:02zrilakamalloy is not commenting my solution to the problem 53, must be really noobish :)
20:02amalloyhah, sorry no
20:03amalloyit's fine. mine is a huge mess. i tweeted it somewhere
20:03zrilakI guess the biggest challenge here is not to think in terms of indices
20:03zrilaka great entry problem, really
20:10amalloyi see. slamhound won't let you :require/:as with an :as name that doesn't match the last segment of the namespace; we were using (:require [sandbar.stateful-session :as session])
20:14amalloywhich, in fact, i knew was the case. but the names looked *so similar* that i thought they were the same and was trying to debug the issue
20:15zrilakthat sounds odd
20:15zrilakif the :as name is uniquely described by the library, why do we get to retype it?
20:15amalloyhuh?
20:16zrilakif I understand you correctly, one cannot do (:require [foo.bar.baz :as :blah])
20:16zrilak:as blah*
20:16amalloyzrilak: you can. you just can't use slamhound in that case
20:17zrilakall right.
20:46amalloyampleyfly: http://4clojure.com/problem/53
20:46amalloyc'est bon?
20:55ampleyflyamalloy: heh =)
21:04ampleyflyAdvanced Destructuring
21:04ampleyflyTags: easy destructuring
21:04ampleyfly=)
21:38mecwhy does setting two refs to eachother cause a stack overflow
21:40mec,(let [a (ref nil) b (ref nil)] (dosync (ref-set a b) (ref-set b a)))
21:40clojurebot#<Ref@1efb1c0: #<Ref@17ebc6c: #<Ref@1efb1c0: #<Ref@17ebc6c: #<Ref@1efb1c0: #>>>>>
21:40mecweird, why does it give me a stack overflow
21:44amalloymec: it doesn't. printing them gives you a stack overflow
21:45amalloy&(let [a (ref nil) b (ref a)] (dosync (ref-set a b) nil))
21:45sexpbot⟹ nil
21:45amalloy&(let [a (ref nil) b (ref a)] (dosync (ref-set a b) a))
21:45sexpbotjava.lang.StackOverflowError
21:46mecah
21:47mec&*print-level*
21:47sexpbot⟹ nil