#clojure log - May 01 2011

The Joy of Clojure
Main Clojure site
Google Group
List of all logged dates

1:28 hiredman: https://github.com/hiredman/javap-mode might be of interest to some people here

1:30 http://www.thelastcitadel.com/images/javap-mode.png

1:38 technomancy: hiredman: your haskell growl is showing =P

1:39 hiredman: I know

1:39 growls by https://github.com/hiredman/Howler

1:41 I guess I should figure out parsley since that seems like it will be the "blessed" parsing library

1:41 "An experimental undocumented parser lib/DSL." the docstring for the parsley namespace

1:42 technomancy: clojurebot: dsl?

1:42 clojurebot: Huh?

1:43 technomancy: clojurebot: just wondering if you had any clever one-liners on the topic.

1:43 clojurebot: Gabh mo leithscéal?

2:44 lisperado: anyb ody here?

2:44 brehaut: probably

2:44 lisperado: oh cool.

2:45 i'm trying to get cljr installed

2:45 do you or anybody else use cljr?

2:45 brehaut: i do

2:45 on a mac

2:46 lisperado: great. i'm on mac also.

2:46 i got an error trying to install it.

2:46 i filed a bug report, but i don't think liebke maintains the program anymore

2:47 brehaut: that does appear to be the case

2:48 lisperado: i wrote about it here: https://github.com/liebke/cljr/issues/21

2:49 brehaut: no idea sorry; i just followed the instructions and it was fine

2:50 lisperado: interesting...do you use maven or maven2?

2:50 brehaut: directly?

2:50 lisperado: wellno, i mean do you have maven or maven2 installed?

2:50 i think clhr uses maven, but i have maven2 installed

2:50 brehaut: i have no idea; if they are i havent installed it myself.

2:50 cljr is built on lein which is mvn2

2:51 lisperado: that makes esnse

3:04 amalloy: cljr is old and crufty. it should work, but it really does not improve the UX compared to say, cake, in any way

3:04 sudo gem install cake && cake repl

3:04 bam, you have a repl

3:05 lisperado: interesting...thanks!

3:05 is cake a ruby tool?

3:05 amalloy: it's clojure with a thin ruby layer to get things started

3:05 (like lein is clojure with a thin bash layer)

3:06 lisperado: i was planning to use cljr to install compoure. can cake do that?

3:06 hiredman: (use lein)

3:06 lisperado: eh? how do i use lein to install compojure?

3:06 amalloy: don't. throw away everything in your head about "installing"

3:07 you 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

3:08 you don't even install clojure. clojure.jar is one of the ordinary dependencies in your project

3:08 $google Raynes getting started with clojure

3:08 sexpbot: First out of 69 results is: An indirect guide to getting started with Clojure » Bathroom ...

3:08 http://blog.raynes.me/%3Fp%3D48

3:08 amalloy: argh that link still sucks

3:09 http://blog.raynes.me/?p=48

3:09 lisperado: thanks. i'll read that page and get up to speed

10:23 * fliebel wonders if it is possible to write a lazy endless grid

12:12 datka: Does anyone know of any projects that are using Cuke4Duke with Compojure? I'm looking for good examples.

13:03 fliebel: dnolen: 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:05 dnolen: fliebel: 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:06 fliebel: dnolen: So you're not using a binary decision tree then? Because in that case 'if' would suffice I assume?

13:07 dnolen: fliebel: if is slow for multiway decisions (think types)

13:07 if checks nil

13:22 thorwil: hrmp, seems Enlive refuses to work on stuff within <script> tags

13:28 raek: thorwil: html elements inside script tags?

13:30 thorwil: raek: 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:30 (i tried tags inside <script> only as possible workaround)

13:31 raek: I assume that tagsoup (the underlying lib that does the parsing) treats everything between the script tags as text

13:33 it is built to reasonably be able to parse any html document, no matter how badly it's written

13:34 (so that's why I think < is always treated as text in a script, unless it's the stop element)

13:37 thorwil: makes perfect sense. i can use prepend to insert that one line i need. only it must be in the 3rd script tag

13:38 [[:script (en/nth-of-type 3)]] doesn't match

13:39 with 2 doesn't either, with 1 it matches all 3 script elements

13:42 raek: I tested it on a page with two script elements and (select foo [:script]) returns two elements, as expected

13:44 thorwil: i 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:45 i must be misunderstanding nth-of-type?!

13:45 raek: hm, how is nth-of-type supposed to work anyway?

13:46 thorwil: "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:46 raek: I don't understand the "an+b-1" part... is "n" a variable?

13:47 thorwil: i got to that function via http://stackoverflow.com/questions/2695701/how-to-select-nth-element-of-particular-type-in-enlive

13:49 raek: in my case, (select foo [:script (nth-of-type <any number here>)]) always returns ()

13:49 maybe it only works on consecutive occurances of the elements

13:50 thorwil: i only tested with consecutive occurrences

13:53 Ramblurr: does the ->> macro have a name? I'm trying to understand it, but searching for it is.. well not working :P

13:54 mec: Ramblurr: thread-last

13:54 raek: thorwil: ah, now I tested with [[:script (nth-of-type 1)]] insted of [:script (nth-of-type 1)]... it works for me now

13:55 thorwil: raek: for nth above 1, too?

13:55 mec: Ramblurr: also i think its called something like thrush although that may be ->

13:56 thorwil: i thought -> is thread or threading?

13:56 raek: thorwil: yes, with 1 and 2 it returns the corresponding script elements

13:57 Ramblurr: mec: I understand that (a (b (c (x) is the same as (-> x b c a), but what does ->> do?

13:57 raek: thorwil: maybe you could try (pprint (html-resource ...)) and look how/if the elements appear in the tree

13:57 mec: Ramblurr: ##(->> (range 10) (map inc ,) (reduce + ,))

13:57 sexpbot: ⟹ 55

13:58 mec: ,(macroexpand '(->> (range 10) (map inc ,) (reduce + ,)))

13:58 clojurebot: (reduce + (clojure.core/->> (range 10) (map inc)))

13:58 raek: Ramblurr: (-> 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:59 with -> each step becomes the first argument of the next, but with ->> it becomes the last argument

13:59 Ramblurr: Ah.. I see!

14:08 thorwil: raek: all 3 appear as {:tag :script ... }

14:11 (en/select (en/html-resource "templates/article-form.html") [[:script (en/nth-of-type 2)]]) works perfectly on the repl

14:14 alandipert: /j #boxgrinder

14:14 whoops

14:15 also re: ->>, it's the one known as 'thrush'

14:16 in clojure, since it's implemented syntactically (with macros) as opposed to functionally, it's not quite the 'thursh combinator', but effectively same thing

14:31 thorwil: so as soon as i want to use nth-of-type in a defsnippet, it stops working

14:31 joshuac: How do I get rid of the mapping in clojure-mode that maps return to a re-indent function?

14:32 90% of my frustration with the mode would be gone if that little function wasn't used.

14:35 thorwil: oh, with the exception to what happens with comments sometimes, i'm glad to have that indention feature

14:39 joshuac: 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:40 actually, that might not be a part of clojure mode

14:41 reindent-then-newline-and-indent could be the command

14:41 joshuac: thorwil, fixed it

14:42 (add-hook 'clojure-mode-hook

14:42 (lambda ()

14:42 (define-key clojure-mode-map (kbd "RET") nil)))

14:43 thorwil: joshuac: i would have been worried to render RET entirely effectless

14:44 joshuac: thorwil, 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:45 thorwil, 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:46 thorwil, *in my opinion

14:46 raek: joshuac: in recent versions, you can configure it to use 2-space indentation for your own macros

14:47 joshuac: raek, I like conds to have the sexps which correspond to action indented (like you would indent were it an if statement)

14:47 raek: ah, I see.

14:47 thorwil: raek: my experimentation suggests that nth-of-type works in an enlive transform, but not in transformation 0.o

14:49 joshuac: raek, example of what I mean. What I like on top what the default is in the clojure-mode

14:49 https://gist.github.com/950732

14:57 hippiehunter: does anyone in here use clojure-clr?

15:01 thorwil: raek: 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:02 though this is very inconvenient, with the way i constructed my views so far :/

15:11 amalloy: technomancy: you around? trying out slamhound and it's not able to handle compojure's GET

15:24 milkpost: technomancy: so you pressured some guy with a vim-themed blog to switch to emacs? HA http://writequit.org/blog/?p=431

15:26 amalloy: trying 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:51 Ramblurr: is there a way to set a default value for a function argument?

15:51 e.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:53 thorwil: Ramblurr: write 2 signatures, use the first with lower arity to call the function with one argument more

15:53 pdk: ,((fn ([x 1]) x))

15:53 clojurebot: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.UnsupportedOperationException: nth not supported on this type: Symbol

15:53 pdk: ,((fn [[x 1]] x))

15:53 thorwil: Ramblurr: http://stackoverflow.com/questions/3208347/how-to-create-default-value-for-function-argument-in-clojure

15:53 clojurebot: java.lang.Exception: Unsupported binding form: 1

15:53 pdk: derp

15:54 Ramblurr: like (foo [] (foo 1) [n] stuff_with_n) ?

15:54 amalloy: Ramblurr: almost, though the syntax isn't right

15:54 fliebel: Ramblurr: Extra parens

15:54 amalloy: &((fn foo ([] (foo 1)) ([x] (inc x))))

15:54 sexpbot: ⟹ 2

15:55 amalloy: aside: the compiler needs those extra parens to be able to tell "multiple function bodies" apart from "single body with multiple side-effecting forms"

15:57 Ramblurr: amalloy: how would that look using defn?

15:58 amalloy: um, the same. just change fn to defn, and don't wrap it with the extra parens i used to call the function

15:58 milkpost: how do you call functions until one returns non-nil?

15:58 amalloy: defn is really implemented as a macro that expands into (def whatever (fn ...))

15:59 milkpost: (first (drop-while (complement nil?) (map #(%) list-of-functions)))?

15:59 milkpost: hrm

16:00 amalloy: er, except it shouldn't be complemented at all. just drop-while nil?

16:00 milkpost: yeah probably, shit i'm such a newb to this

16:00 ihodes: milkpost: what are you trying to do?

16:01 milkpost: nothing, i was just curious

16:01 ihodes: milkpost: 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:01 milkpost: learned how to implement fizzbuzz and the implementation i'm looking at concats calls to different functions, rather than the first one that matches

16:02 but now i'm looking at how to print odd numbers and extend that to other things.. trying to get a feel for this...

16:03 raek: milkpost: I think it would simply be easier to filter the values

16:03 milkpost: hrm.

16:03 raek: and do the printing later

16:04 milkpost: ah yes

16:06 ihodes: milkpost: what do you have so far?

16:06 milkpost: ahh give me a few more secs

16:08 https://gist.github.com/950816

16:09 joshuac: Hmm. 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:09 milkpost: i'm actually trying to print the numbers that are at 10%, 20%, ... of the maximum value

16:09 but i'm not sure how to do partial evaluation of a function

16:09 amalloy: Line2D$Double

16:10 ihodes: (partial fn args ..)

16:10 amalloy: ihodes: i'd be very surprised if that's what he meant by partial evaluation, in context

16:10 joshuac: amalloy, Thanks. Now that I've read that I'm able to see that it is in fact metnioned in the docs.

16:10 milkpost: ihodes: is there a better way to do what I am doing?

16:11 ihodes: amalloy: yeah you're probably right. i saw partial, and there i went

16:12 milkpost: actually that is what I meant

16:12 ihodes: milkpost: i'm not quite sure what you're doing yet, but you can use zero? instead of = 0

16:12 milkpost: https://gist.github.com/950820

16:13 amalloy: or #{0}, har har

16:13 milkpost: so, if i have 100 i want 10, 20, 30, 40... 90.

16:14 ihodes: (filter #(zero? (mod % 10)) (range 100))

16:14 milkpost: but i actually want to iterate through each item of the range from 0 to 100

16:14 ihodes: i'd use filter for that

16:15 milkpost: i have no idea what the hell that #( thing is... will go read some more

16:15 raek: milkpost: my solution: https://gist.github.com/950822

16:15 ihodes: ah, sorry; that's syntactic sugar for (fn [x..] ...)

16:15 Ramblurr: can you use the #(..) macro with multiple arguments?

16:15 alandipert: ,(take-nth 10 (range 100))

16:15 clojurebot: (0 10 20 30 40 50 60 70 80 90)

16:15 amalloy: yes, but it's not a macro

16:15 ihodes: so what i just wrote == (filter (fn [n] (zero? (mod n 10))) (range 100)

16:15 amalloy: #(+ %1 %2)

16:15 raek: Ramblurr: yes, just use the symbols %1, %2, %3, etc

16:16 milkpost: alandipert: not quite, because if i give 200, then i want 20, 40, 60... like 10% of max, 20% of max, etc.

16:16 Ramblurr: amalloy: its not a macro?

16:16 amalloy: Ramblurr: it's part of the compiler syntax

16:17 &'#(inc %)

16:17 sexpbot: ⟹ (fn* [p1__37356#] (inc p1__37356#))

16:17 ihodes: milkpost: ah, i get ywhat you're asking now.

16:17 milkpost: that works though very nicely

16:17 so % defaults to %1?

16:17 amalloy: it's a synonym for %1

16:17 ihodes: milkpost: yes

16:18 milkpost: i 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:18 technomancy: amalloy: yeah, it assumes capitalized references are classes... not sure what to do about compojure.

16:18 ihodes: and technomancy comes from left field!

16:19 amalloy: a macro in that position (ie, after a quote) wouldn't be expanded: ##'(dotimes [x 1] (prn x))

16:19 sexpbot: ⟹ (dotimes [x 1] (prn x))

16:19 amalloy: technomancy: 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:19 ihodes: milkpost: 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:20 milkpost: does that make sense?

16:20 milkpost: ihodes: yeah, that's what i was doing. is there any difference between these two functions (performance wise?) https://gist.github.com/950827

16:20 * amalloy predicts it will all end in tears when milkpost tries this for some number not evenly divisible by 10

16:20 technomancy: amalloy: that would kill perf

16:20 it's already annoyingly slow

16:21 amalloy: technomancy: i doubt it. start by trying the version you currently guess to use

16:21 if that works you can return it

16:21 otherwise, instead of reporting failure, fall back on the other options?

16:21 technomancy: oh sure... there's lots of room for improvement with fallbacks.

16:21 milkpost: amalloy: thanks for reminding me. wrapping my denominator in (int ..) is ok? :

16:22 man, i am such a goddamn newb

16:22 technomancy: little trickier when they have to cross clause-type boundary, but should be doable

16:22 milkpost: i can see why old people don't learn new things

16:22 amalloy: milkpost: the second one is faster, but if you care you're kinda crazy imo

16:22 also that trailing paren is bizarre

16:23 technomancy: amalloy: the problem is the errors compiler gives seem pretty arbitrary most of the time

16:23 milkpost: amalloy: hehe

16:23 amalloy: technomancy: for sure, compiler errors are gross

16:25 ihodes: milkpost: looks good. that's pretty idiomatic as well. 2nding what amalloy said about the rest.

16:26 milkpost: amalloy: i am crazy!

16:26 amalloy: technomancy: 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:26 milkpost: this 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:27 ihodes: amalloy: 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:28 amalloy: ihodes: only if it knows that / has no side effects

16:28 ihodes: amalloy: wouldn't it know that? or is there a flag for that?

16:28 amalloy: there is no such flag. it might know it, i dunno

16:29 ihodes: amalloy: it just seems wasteful otherwise, and such a simple reduction since there's a closure created (?) once n is known.

16:29 n is fixed

16:30 amalloy: &(let [n 100000] (time (dotimes [_ 1e7] (/ n 10))))

16:30 sexpbot: ⟹ "Elapsed time: 1233.126597 msecs" nil

16:30 raek: the anonymous function closes over a variable in both cases

16:30 amalloy: &(let [n 100000 quot (/ n 10)] (time (dotimes [_ 1e7] quot)))

16:30 sexpbot: ⟹ "Elapsed time: 11.278353 msecs" nil

16:30 ihodes: so sad :(

16:31 that's really too bad. wasteful requirement of let-binding for something that's clearly fixed.

16:31 amalloy: i don't understand what you're saying about "closure created(?)"

16:33 ihodes: i 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:33 but i guess there's not a great way for the compilter to know what there's no side effects

16:34 that*

16:34 amalloy: ihodes: feel free to implement that in the clojure compiler, and tag every function and method in the jvm with :is-pure :P

16:35 Derander: it would really be awesome if there was metadata to tell if a function was pure

16:36 ihodes: amalloy: 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:36 alandipert: there is very recently :const in clojure for constants

16:36 ihodes: i 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:36 alandipert: it's the most performant way to name a value you know won't change

16:37 (def constants {:pi 3.14}) (def ^:const pi (:pi constants))

16:37 ihodes: i've got to head out for now. neat conversation :)

16:37 milkpost: shit, did i start a war?

16:38 alandipert: also if your function is pure, you can memoize it

16:39 technomancy: amalloy: yeah, the failure-details function is the part that classifies the exception message

16:40 amalloy: alandipert: that's more work than just let'ing the result of the function in many cases

16:40 technomancy: I'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:40 alandipert: optimization is always more work.. which is why i try to avoid it :)

16:42 technomancy: amalloy: would be great if you want to hack it. feel free to ask if you've got any further questions.

16:42 amalloy: technomancy: what's the primary entry point function for slamhound?

16:43 technomancy: amalloy: slam.hound/reconstruct

16:43 amalloy: did you see http://technomancy.us/148 ?

16:43 amalloy: yeah, read it last night

16:43 technomancy: cool

16:44 mec: Shoudnt (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:45 amalloy: mec: case has some bugs related to macroexpansion and/or code walkers

16:45 technomancy: amalloy: I was thinking of allowing projects to expose disambiguator logic, but now I'm not sure it's worth the bother

16:45 better to just make the default disambiguator smarter in most cases, I think

16:45 mec: amalloy: 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:46 amalloy: mec: https://twitter.com/#!/4clojure/status/63728776504291328

16:46 mec: amalloy: lol thats exactly what i was doing

16:47 amalloy: mec: of course. i gave you the link because it shows the clojure jira issue for this if you want to look deeper

16:47 alandipert: amalloy: ataggart's fix went in on friday, a better case will be in the 1.3 beta

16:47 amalloy: oh, good news

16:48 thanks alandipert

16:48 we may just switch 4clojure to 1.3b in that case

16:48 alandipert: that would rule

16:49 amalloy: when is the beta hitting?

16:49 alandipert: soon :)

16:50 handful of numerics bugs and enhancements left to do, then we'll probly cut it

16:50 amalloy: technomancy: excellent. i can use the cdt to step through slamhound. cool that these two hit at roughly the same time

16:50 technomancy: fun =)

16:51 just 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:51 amalloy: kk

16:51 technomancy: I'm thinking improving the pretty-printing will be much much easier to do in elisp than clojure

16:51 since 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:52 zrilak: <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:53 amalloy: &(doc with-local-vars)

16:53 sexpbot: ⟹ "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:54 zrilak: <smiley>Thanks!</smiley>

16:55 * amalloy wonders when irc turned into an xml-based protocol

16:56 technomancy: word 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:57 I 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:58 amalloy: yeah, good point there. if i've never used it it's probably wrong to recommend to someone who doesn't know it exists

17:01 zrilak: interesting, well, I was asking this precisely because I am trying to avoid mutating something at the lexical root

17:02 actually 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:03 I'm perfectly happy with immutable state objects though.

17:03 amalloy: &(doc loop)

17:03 sexpbot: ⟹ "Special Form: Please see http://clojure.org/special_forms#loop"

17:03 amalloy: zrilak: loop and reduce are a million percent better than having any vars at all, for this sort of task

17:04 zrilak: good, that'll teach me to jump head-first into a new language without reading the docs.

17:04 I suspect recur too?

17:06 technomancy: yeah, often actually recur without loop

17:06 since it can recur to the beginning of a function

17:07 though map, filter, and reduce are often better. but it's good to start with loop.

17:07 just keep in mind it's lower-level than the functions that work in terms of sequences

17:09 zrilak: I'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:09 but yeah, I see your point, each function has its use cases

17:11 amalloy: zrilak: 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:11 zrilak: foreclosure? that's clever :D

17:12 why not, I'll take it for a spin right now

17:13 I'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:15 amalloy: zrilak: 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:17 zrilak: awful in terms of run time or hackish code :)

17:18 amalloy: the latter

17:18 we don't time solutions

17:21 alandipert: amalloy: d'oh, i was hoping nobody was looking at solutions :)

17:21 amalloy: alandipert: we're not, actually. but people tweet them

17:21 so all i *actually* know is nobody has tweeted a good one

17:24 alandipert: 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:26 alandipert: amalloy: thanks for clarifying, i dig the use of gists in the interim

17:27 amalloy: alandipert: 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:30 zrilak: I should register to post my solution, yes?

17:30 amalloy: zrilak: you don't have to. you can tweet anyway

17:30 but we like it if you register

17:30 zrilak: :)

17:59 kencausey: amalloy: 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:59 or "inc"

18:00 amalloy: kencausey: that would be a pretty weird error, and it doesn't happen to me

18:01 did you name your function nth?

18:01 cause 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:03 kencausey: http://paste.lisp.org/display/121703

18:04 error: "You tripped the alarm! nth is bad!"

18:04 amalloy: aha, funny

18:04 i'm not really sure how to fix that

18:05 &(macroexpand '(let [[s & r] 10] s))

18:05 sexpbot: ⟹ (let* [vec__37489 10 s (clojure.core/nth vec__37489 0 nil) r (clojure.core/nthnext vec__37489 1)] s)

18:05 kencausey: how is it testing?

18:05 * Raynes lols

18:05 amalloy: kencausey: it macroexpands your code first to check for malice

18:05 kencausey: so like my version matches nth itself?

18:05 ampleyfly: why is the longest increasing subsequence of [7 6 5 4] = []?

18:06 isn't [7] an increasing subsequence?

18:06 Raynes: kencausey: The macroexpansion of your code uses nth.

18:06 amalloy: kencausey: right, because destructuring uses nth and you use destructuring

18:06 kencausey: oh, ok

18:06 hmm

18:06 Raynes: amalloy: Not sure where to begin on this one.

18:07 amalloy: Raynes: not in clojail, i think. add a note in the 4clojure problem

18:07 kencausey: ok, yes, destructuring rather unnecessary in this case, I just kind of fell into a pattern ther

18:07 thansk

18:08 amalloy: kencausey: not your fault, of course. it "should" work

18:08 Raynes: amalloy: 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:28 kencausey: amalloy, Raynes: Should apply be restricted in https://www.4clojure.com/problem/24 ?

18:28 amalloy: no, why?

18:28 kencausey: it seemed like an overly trivial solution

18:28 amalloy: welcome to learning a language :P

18:28 kencausey: I mean, it's not restricted and I wonder if it should be

18:29 Well, OK I thought this whole section was about writing functions, all the rest have forced me to do so.

18:30 amalloy: you're not in the core-functions "section" at the moment

18:30 we don't really have sections, though, just tags

18:36 ampleyfly: amalloy: [7] is an increasing sequence

18:38 zrilak: is there a "forward conj" for vectors? (? 1 [2 3]) -> [1 2 3]

18:38 or (? [2 3] 1), okay :)

18:39 raek: zrilak: no.

18:39 zrilak: pity.

18:39 raek: if you need to add to the front, use a list.

18:40 if you need to add to one end and remove from the other, use a queue

18:40 amalloy: ampleyfly: 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:41 ampleyfly: that works too =)

18:41 raek: zrilak: you could of course do (into [1] some-vector), but that would run in linear time

18:42 zrilak: actually, I *do* need conj, I just confused directions. thanks :)

18:44 ampleyfly: I like 4clojure

18:45 amalloy: ampleyfly: it's only two weeks old. plenty of time to get involved early and improve things

18:46 ampleyfly: I'm not very skilled with clojure though =)

18:52 maybe adding links to documentation for things that are presented would be nice, if it's intended as a learning tool, as it seems

18:52 amalloy: ampleyfly: what do you mean "are presented"?

18:53 ampleyfly: well, I just saw "Clojure has many different ways to create functions." followed by code containing fn, #( %) and partial

18:54 I know what they do, but a link to clojuredocs or something would be nice

18:56 dnolen: evolving tutorial on core.logic, https://github.com/swannodette/logic-tutorial. any feedback appreciated.

19:03 amalloy: technomancy: 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:06 looks 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:17 zrilak: amalloy, 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:17 amalloy: yep, that's what pastie/gist are for

19:17 zrilak: http://pastie.org/1854938

19:18 I'm pretty sure it is not supposed to be THAT verbose, given that tweets are 140-char limited... :)

19:19 amalloy: zrilak: the tweets are all links to gists anyway

19:19 zrilak: ah, well, okay.

19:19 amalloy: check out ##(doc split-with), btw

19:19 sexpbot: ⟹ "([pred coll]); Returns a vector of [(take-while pred coll) (drop-while pred coll)]"

19:21 zrilak: heh, that looks useful in this context

19:30 ampleyfly: how can I check if something is a sequence (like list or vector)?

19:31 amalloy: &(doc sequential?)

19:31 sexpbot: ⟹ "([coll]); Returns true if coll implements Sequential"

19:31 zrilak: seq?

19:31 clojurebot: amac: 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:31 amalloy: zrilak: nooooo

19:31 zrilak: noo ?

19:31 amalloy: &(seq? [1])

19:31 sexpbot: ⟹ false

19:32 zrilak: ah, gotcha

19:32 amalloy: seq? only returns true for things that implement ISeq directly (lists and seqs), not "sequential things"

19:32 zrilak: ISeq != Sequential...

19:32 gotcha gotcha, thanks

19:39 amalloy: technomancy: 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:39 pdk: how again do you import java libs from clojure

19:39 (require [java awt])?

19:39 amalloy: (import (java.awt Point Rectangle))

19:40 pdk: how about for *

19:40 amalloy: pdk: don't. it's bad form in java, and not allowed in clojure

20:02 zrilak: amalloy is not commenting my solution to the problem 53, must be really noobish :)

20:02 amalloy: hah, sorry no

20:03 it's fine. mine is a huge mess. i tweeted it somewhere

20:03 zrilak: I guess the biggest challenge here is not to think in terms of indices

20:03 a great entry problem, really

20:10 amalloy: i 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:14 which, 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:15 zrilak: that sounds odd

20:15 if the :as name is uniquely described by the library, why do we get to retype it?

20:15 amalloy: huh?

20:16 zrilak: if I understand you correctly, one cannot do (:require [foo.bar.baz :as :blah])

20:16 :as blah*

20:16 amalloy: zrilak: you can. you just can't use slamhound in that case

20:17 zrilak: all right.

20:46 amalloy: ampleyfly: http://4clojure.com/problem/53

20:46 c'est bon?

20:55 ampleyfly: amalloy: heh =)

21:04 Advanced Destructuring

21:04 Tags: easy destructuring

21:04 =)

21:38 mec: why does setting two refs to eachother cause a stack overflow

21:40 ,(let [a (ref nil) b (ref nil)] (dosync (ref-set a b) (ref-set b a)))

21:40 clojurebot: #<Ref@1efb1c0: #<Ref@17ebc6c: #<Ref@1efb1c0: #<Ref@17ebc6c: #<Ref@1efb1c0: #>>>>>

21:40 mec: weird, why does it give me a stack overflow

21:44 amalloy: mec: it doesn't. printing them gives you a stack overflow

21:45 &(let [a (ref nil) b (ref a)] (dosync (ref-set a b) nil))

21:45 sexpbot: ⟹ nil

21:45 amalloy: &(let [a (ref nil) b (ref a)] (dosync (ref-set a b) a))

21:45 sexpbot: java.lang.StackOverflowError

21:46 mec: ah

21:47 &*print-level*

21:47 sexpbot: ⟹ nil

Logging service provided by n01se.net