#clojure logs

2013-04-08

00:10murtaza52I have a sorted map that I am sending to the client. The client is in cljs, the hash-map that appears on the client is not sorted, any ideas?
00:11nightflyI don't think javascript has a native notion of a sorted map
00:14murtaza52so the sort order wont me maintained, I mean I am not manipulating the collection on the client
00:14murtaza52I am displaying it as is
00:14pbostrommurtaza52: you are sending as edn?
00:14murtaza52nope
00:14murtaza52I am using shoreleave which uses fetch
00:15pbostromin any case, you'll probably have to explicitly call sorted-map
00:16murtaza52call sorted-map on the client ?
00:17pbostromyeah
00:17murtaza52the problem is that sorting is being done based on the date, which is using clj-time, which uses java's joda time. So I wont have this dependency avalaible in cljs
00:19pbostromhmm, maybe convert the map to a vector of map entries instead
00:19murtaza52any way around it?
00:19pbostrombefore sending to the client
00:19pbostromthat will stay in order at least
00:21murtaza52thanks pbostrom, let me try that. The reason it will maintain the order, is because arrays are ordered by index ?
00:26pbostromyes, your sorted map is probably getting converted to a normal map for serializing over the wire via fetch, it seems like there would be a way to maintain the sorted map using the edn reader, but I don't know enough about it
00:27andyfingerhutI'm pretty sure edn has no notion of order for sets or maps.
00:27andyfingerhutvectors or lists would be the way to go if you want to preserve order.
00:29andyfingerhutHere's an excerpt from the edn spec regarding sets: "No semantics should be associated with the order in which the elements appear." It says the same for maps.
00:30andyfingerhutHmmm. I think I'll suggest to Bronsa that he mention this somewhere in the tools.reader docs for that edn reader.
00:30pbostromthere you go
01:44ebaxtAre there any good reasons for not having a regex? predicate in Clojure?
01:51andyfingerhutOne could potentially argue that there are plenty of similar things that could be added. Where would you draw the line?
01:51andyfingerhute.g. array? uuid? file?
01:51andyfingerhut(instance java.util.regex.Pattern x) should do what you need, yes?
01:52andyfingerhuter, that should have been instance? with a ?
01:53ebaxtandyfingerhut: fair point
05:10NobitaZhii
17:35zaphyroh. i see. so i have to :require-macros or such in every cljs ns i want to use them in, there's no way to make them export?
17:36gfredericksthat's how clojure generally works; explicitely requiring things
17:37zaphyryes, but in clojure I can import macros along with other definitions in the same :require, whereas in clojurescript macros are imported with a different :require-form, you can't just (:require foo :as bar), but you also have to (:require-macros foo :as bar)
17:38gfredericksyep
17:38zaphyrouch
17:38gfredericksthe compiler has to know whether something is a macro or not
17:38gfredericksit's definitely not ideal
17:38zaphyrsure, but clojurescript is entirely AOT isn't it? so in *theory* you could do that
17:38zaphyrokay it would break brepl
17:39dnolenzaphyr: macros are written in Clojure, require is for runtime dependencies. I don't see how it could be made to work.
17:39dnolenor I could imagine it, and it sounds yucky.
17:40zaphyrhey, it's not r6rs staged macro horror :)
17:41zaphyrbut- can't you track imports, at least via ns, at compile time, then fully macro-expand the source then? (in theory)
17:41OkasuGuys, what do you usually use when it comes to realtional db and clojure? Clojure jdbc lack of abstraction disturbing(yeah, i can abstract things away by myself but is there something already done in this field?).
17:42dnolenzaphyr: CLJS compilation unit is a function, just like Clojure.
17:43zaphyrdnolen: ah.
17:44dnolenzaphyr: I take it you do a bit of Scheme? :)
17:45zaphyra bit of all sorts of lisps. but implementing scheme macros is... oh.. dear lord.
07:48ggbothsoHi all, is there a way to automatically run the tests every time a filesystem change is detected?
07:49ggbothsoin scala, using sbt, I can do it with: "~ test"
07:50babilenggbothso: midje supports that (autotest), no idea if there is anything like that for clojure.test
07:51babilenggbothso: there was lein-autotest, but that hasn't been maintained (along with lazytest) in quite a while
07:54babilenggbothso: midje /can/ run clojure.test tests as well (cf. https://github.com/marick/Midje/wiki/A-tutorial-introduction-for-Clojure.test-users) but you might want to take a look at the Testing section on https://github.com/technomancy/leiningen/wiki/Plugins
11:39mpenetunless you are thinking about something I am missing
11:44mpenetthe problem with clojure.core promise is that they are way too simple, it's sometimes good, but often it's not enough. The callback issue is one but exception handling is another important issue (deref can't throw), well the fact that there is only 1 type of result really.
11:47CookedGryphonhugod: I've tried disabling eldoc and autocomplete-mode in my nrepl buffer, but I'm still having issues with the repl hanging after I clear an exception window. Any ideas?
11:48CookedGryphonI am at least past the point where emacs would just completely freeze
11:49CookedGryphonalso, all the locals in one of the exceptions I caught appear to be nil, is that something other people have come across?
11:54alexnixonCoo--- File clojure/2013-04-10.log
17:08tbaldrid_these are reader issues, legal symbols can be anything.
20:10neilmarcushello?
20:10clojurebotBUENOS DING DONG DIDDLY DIOS, fRaUline neilmarcus
20:25ravsterwhats the max that java.lang.Integer can go to? I'm trying to use the java.awt.Polygon class to find if a given latitude and longitude is part of a polygon, and I'm not sure by how many decimal places I can move a value (Egs: latitude 44.35745968346 -> 4435745968346 )
20:26hiredman,Interger/MAX_VALUE
20:26clojurebot#<CompilerException java.lang.RuntimeException: No such namespace: Interger, compiling:(NO_SOURCE_PATH:0:0)>
20:26hiredman,Integer/MAX_VALUE
20:26clojurebot2147483647
20:26hiredman,Integer/MIN_VALUE
20:26clojurebot-2147483648
20:26hiredman,Long/MAX_VALUE
20:26clojurebot9223372036854775807
20:26hiredman,Long/MIN_VALUE
20:26clojurebot-9223372036854775808
20:27ravsterhiredman: oh, I wish I could use longs. But the Polygon class doesn't seem able to consume them.
20:27ravsterhiredman: and thanks for the answer. :)
20:38nopromptwhen using require is it possible to both refer and rename?
20:40noprompt or is it ok to use use in that case?
20:42nopromptoh, there it is.
20:46bttfbrand new to clj ... just wrote some code in my core.clj, trying to run it in my 'lein repl' ... i do (in-ns 'testing-clj.core) to get into the namespace but it seems not able to see my symbols
20:49bttfhttps://gist.github.com/bttf/776f7389cd96b4743dd7
20:51bttfit seems that i'm entering that namespace but completely separate from what i have defined in src/testing_clj/core.clj
20:53ivandoes it work without (:gen-class)? are you sure you're doing (in-ns 'testing-clj.core) and not (in-ns 'testing_clj.core)?
20:54ivan`hello` shouldn't even compile because `hi` is defined after it, though I don't know how AOT works with that
20:54bttfivan: thanks for replying, i have since removed (:gen-class) since i am not using it ... when I do lein compile i get no output whatsoever .. i don't even know if lein see's the file
20:55bttfi mean, i just generated a new project ,wrote the code and did a 'lein compile'
20:55ivanyou don't need to lein compile before lein repl
20:56bttfok
20:57bttfand yes i'm sure i am doing (in-ns 'testing-clj.core)
20:58bttfi've rearranged the functions, same issue
21:00ivanbttf: I'm probably missing something obvious, it's not working here either
21:01bttfok ... does somehing need to be specified in the project.clj ? id assume that it should be set to go
21:03ivanbttf: maybe it's because your directory starts with "test"
21:04ivanlein might be ignoring those by default
21:04bttfweird, let me try
21:04ivanmake sure you change the (ns too
21:06ivanbttf: heh, actually you need to (require 'testing-clj.core) first
21:06ivan(in-ns) does not seem to load things
21:06dakroneamalloy_: cool, will look when I can
21:07bttfivan: ahh that works, thank you
21:09mdeboardbrehaut: re: named groups https://gist.github.com/mattdeboard/5359853
21:10mdeboardI find it hard to believe this doesn't exist already
21:11ivanbttf: you can put :main testing-clj.core in project.clj to load and enter that namespace
21:13bttfah cool thanks
21:14jhawk28can anyone give be some suggestions on creating a DSL?
21:14jhawk28I want to create a subset of the language that is mainly arithmetic/boolean with some specific functions
21:15jhawk28but I need to to be limited since the code is "dynamic" and can potentially be unsafe
21:16jhawk28is there a way to remove all functions from the dsl's namespace and only add in the specific ones I want?
21:16jhawk28or do I need to just read in the data as ebn and then execute it myself
21:17ivanI think I would use edn and a whitelist
21:17mthvedtjhawk28: you want to read in untrusted data that's a subset of clojure?
21:17nightflyclojail might be useful
21:17jhawk28yes, a subset
21:18bttfivan: what about reloading a file in the repl? i'm trying (load-file) but its not cooperatng
21:19mthvedtyou could walk the tree and throw out anything not on the whitelist
21:19ivanbttf: probably (require 'testing-clj.core :reload)
21:19mthvedtafter reading it in as edn
21:19ivanthere's also a :reload-all
21:20ivanalso nrepl.el has many conveniences for sending new forms to the repl
21:20bttfnice, it works
21:21bttfill check out nrepl.el
21:22bttfthere isn't a vim equivalent is there? ;)
21:22brehautmdeboard: cool; pity you have to double handle the group names :/
21:22mdeboardYeah. Either that or uh
21:22mdeboardparse the patterns :P
21:22mdeboardnothx
21:22jhawk28thanks, I think the edn or the clojail may work
21:22brehaut(╯°□°)╯︵ ┻━┻
21:22mdeboardbrehaut: I'm sure there's a much better way of handling that
21:22mdeboard┬──┬◡ノ(° -°ノ) chill out bro
21:22mdeboarddat emacs macro
21:23ivanbttf: I hear people use https://github.com/tpope/vim-fireplace
21:23mdeboardnever got to use it in the wild before
21:23brehautha
21:23bttfbrehaut: are you flipping tables
21:23brehautyes
21:23bttfawesome
21:23brehautregexps bring out the worst in me
21:29brehaut,(re-pattern (str #"\w" #"\d")) ; mdeboard
21:29clojurebot#"\w\d"
21:29brehautmdeboard: that'll save you having to escape all your slashes in your regexps
21:36mdeboardbrehaut: Oh, didn't think that works, using the regex reader
21:37mdeboardas args to str
21:37brehautmdeboard: str takes anything that has a toString method (ie, everything)
21:38brehautregex patterns happen to have a very useful toString
21:38brehautits perhaps not immediately obvious though; i learnt the trick from weavejester
21:42mdeboardbrehaut: Cool, thanks for the pointer
21:56mikepencereading the joy of closure
21:56mikepence<3 new stuff
22:05bttfanyone good with vim-fireplace in here ?
22:07TimMcAlmost certainly. If you have a question, ask and find out!
22:10joegallothat was the question, he was just checkin' ;)
22:11bttfwell, i'm moving my cursor to a namespace and trying 'gf' .. it's complaining about several things, the first one is that its unable to resolve a symbol that i've not implemented yet (this is the test)
22:11bttfand when i try :Eval ( ... ), whatever i try it gives me the same complaint of unable to resolve symbol
22:12tpopeis your file requirable?
22:15bttftpope: my apologies, the hopping stops here
22:16bttfin the repl i can require the file no problem
22:16bttfis there a fireplace command for require
22:17tpopethere is, :Require
22:17tpopeit also implicitly requires the current namespace if it's your first time evaluating code in it
22:18tpopewhich I assumed was what was failing, albeit with a pecular sounding error
22:18tpopecan you refheap the error?
22:18tpopeuse :messages to see it again
22:19bttfi don't see the 'unable to resolve symbol' errors in messages
22:19bttfbut i do see the others, dealing with 'Error detected while processing function <SNR>36_GF..fireplace#findfile..<SNR>36_eval'
22:20tpopewhat are you pressing gf on?
22:20bttfhttps://gist.github.com/bttf/808d402bea36784c1eb4
22:21bttfhttps://gist.github.com/bttf/4db2ea0d2bf7d3a31dbc line 3 is what i'm gf-ing
22:23tpopehttps://github.com/tpope/vim-fireplace/issues/44#issuecomment-16054922
22:23tpopeis that your alterego? same error right down to the example
22:24tpopeoh, because it's from the tutorial, herp derp
22:24bttfnope and yes, the tut
22:25tpopebttf: to be clear, you can require the *test* file, correct?
22:26bttf(clojure.core/require 'command-line-args.core-test :reload)
22:26bttfCompilerException java.lang.RuntimeException: Unable to resolve symbol: parse-args in this context, compiling:(command_line_args/c
22:26bttfnope
22:26tpopewell, that's the root of the problem
22:26tpopethe error is messier than it should be
22:27bttfmessier or misleading?
22:27tpopeit says couldn't require command-line-args.core-test plain is day
22:28tpopeit's just surrounded by 5 lines of vim garbage
22:28bttfoh i see
22:29bttfbut when I require the test, i only get the error i pasted just above
22:29bttfunless the other erros are hidden away somewhere
22:29tpopewell it's one level of abstraction up. requiring the file tells you what went wrong. doing something that implicitly requires the file tells you the file couldn't be required
22:30tpopeI just reproduced it. there's another error that happens at the top that tells you exactly what you're looking for
22:30mthvedtis there a macro that's like memoize, but for an inline chunk of code
22:31mthvedtto execute it exactly once
22:34amalloymthvedt: delay
22:35tpopebttf: I just cleaned up the error on gf and ]d. let me know if you find others
22:35bttfalright, ill give it a try
22:36mthvedtamalloy: delay returns an object that can be derefed, i want to skip that intermediate step
22:36amalloymthvedt: in that case, all code always, is executed exactly once :P
22:37mthvedtit would have made this one thing i'm writing more readable… but never mind
22:41bttftpope: looks good so far
22:42bttfbut cpR isn't doing anything for me.
22:42bttfand i've deleted my function definition from the code and the test isn't giving me the unresolved symbol error that it should, i believe
22:43tpopewell it only requires once
22:43tpopeafter that it's up to you to reload
22:44bttfand cpr reloads, no ?
22:46bttfcpR should reload-all, but i don't see it happening. if i do cpr on each file, i dont see any errors
22:46tpopecemerick made me take away cpR :(
22:47bttfooh
22:47tpopeyou can :Require! to reload-all
22:47bttfok
22:47bttfstill no dice
22:49tpopewell try :Eval (require ... :reload-all)
22:49tpopethat's all :Require! is doing
22:50bttfi did :Eval (require 'command-line-args.core) :reload-all
22:50bttfthen I did, :Eval (clojure.test/run-tests)
22:51bttfand im seeing errors from when my function existed
22:51tpopere-requiring a file doesn't delete the old namespace first
22:52tpopeyou can ns-unmap, or just restart your repl
22:52bttfinteresting
22:52bttfbut if i make changes to my source, shouldnt it automatically update namespace?
22:53bttfmaybe im missing something here
22:53tpopeignoring your use of "automatically", it doesn't remove anything
22:54tpopeif you defined a function, it's not automagically undefined just because you deleted it from the file
22:56bttfheh
22:56bttfi guess if the behavior of the function is changed that will be reflected when reloaded
22:57bttfbut if its flat-out deleted? shouldn't that somehow be reflected the same way?
22:57bttfi guess the repl isn't made to work like that
23:08bttfthx for the help tpope
23:09tpopeta
23:44dr_chocAnyone here mess around with clojurescript? Specifically the browser repl?
23:46brehaut~anyone
23:46clojurebotJust a heads up, you're more likely to get some help if you ask the question you really want the answer to, instead of "does anyone ..."
23:46brehaut(inc amalloy)
23:46lazybot⇒ 49
23:52dr_chocHas anyone found the cljs browser repl to be finicky? I'm using the lein-cljsbuild plugin and running lein trampoline cljsbuild repl-listen to get a repl, but sometimes it works and sometimes it just hangs as if the browser never connected, but I can see in the network tab (chrome) that it does connect. Any ideas?