This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-11-04
Channels
- # admin-announcements (36)
- # beginners (54)
- # boot (74)
- # cider (14)
- # cljs-dev (91)
- # clojure (197)
- # clojure-austin (1)
- # clojure-conj (3)
- # clojure-india (5)
- # clojure-japan (3)
- # clojurescript (111)
- # core-logic (12)
- # cursive (6)
- # datascript (3)
- # datomic (16)
- # devcards (26)
- # events (1)
- # funcool (11)
- # hoplon (63)
- # jobs (2)
- # ldnclj (10)
- # lein-figwheel (6)
- # luminus (5)
- # nginx (7)
- # nyc (3)
- # off-topic (1)
- # om (148)
- # onyx (122)
- # portland-or (5)
- # re-frame (3)
- # reagent (25)
- # yada (15)
Probably in here: https://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core.clj
(defmacro let
"binding => binding-form init-expr
Evaluates the exprs in a lexical context in which the symbols in
the binding-forms are bound to their respective init-exprs or parts
therein."
{:added "1.0", :special-form true, :forms '[(let [bindings*] exprs*)]}
[bindings & body]
(assert-args
(vector? bindings) "a vector for its binding"
(even? (count bindings)) "an even number of forms in binding vector")
`(let* ~(destructure bindings) ~@body))
They initially define let, and let* here: https://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core.clj#L32-L35 -- I think there's a lot of bootstrapping of code between that definition and the next. It seems to build a list with let*, though I'm not sure where let* is interpreted.
Looks like it gets defined here: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L44
Then you're basically in java code though
question: This may have already been answered, but is this the preferred comms over freenode/IRC?
anyone know why I would be getting a null pointer exception here?
(defmacro my-let [a b & body]
(list 'let ['res b]
(list 'println "just checking" 'res)
body))
(my-let [foo 2] 'bribe (println "in second body"))
This is what it's expanding to: (let [res (quote bribe)] (println "just checking" res) ((println "After")))
@taylor.sando: look at your macro-expansion
Well the & body gets packaged as a list of arguments, so the println gets packaged inside that list. You would have to eval it. Usually you'd use syntax quote for defining macros. You could do this:
Actually my thing would ignore the println
(defmacro my-let [a b & body] #_=> (apply list 'let ['res b] #_=> (list 'println "just checking" 'res) #_=> body))
you'll have other problems (with the macro in general), but it will get rid of the null pointer
the NPE comes from trying to evaluate the result of (println "after"), which will be nil, since println always returns nil
Sure, (println "whatever") returns nil, and (nil) is a null pointer exception
As a learning exercise, I took a homework project I had to do in Java and re-did it in Clojure. The clojure version ended up running over 50x slower than the Java one, and I'm having trouble figuring out what I've done wrong. I'd appreciate it if anyone was willing to take a look at the code to help me understand what I need to do differently: https://gist.github.com/anonymous/703ffb1fe824bed2cb2e#file-star-distance-clj
I'm sure there's all kinds of sloppy code in there as I'm still really new, but mostly I'm curious what I need to be focusing on to improve the performance.
There's kind of a lot of extraneous lines, but basically all of the work is being done in the (compute-distance) function, which is called over 10 million times (this is an n^2 algorithm). I'm not sure if the issue is how I'm doing the computations there, or if it's more about the scaffolding around that.
I'm not very experienced at profiling
One of the things I would try is to memoize is to memoize these https://gist.github.com/anonymous/703ffb1fe824bed2cb2e#file-star-distance-clj-L48
http://i.imgur.com/17xQoa9.png here's what I got out when I tried to profile the program
ooh memoizing is an interesting idea I hadn't thought of
I'll give it a shot and see how it goes, thanks!
(let [ax->bx (- (:x a) (:x b))
ay->by (- (:y a) (:y b))
az->bz (- (:z a) (:z b))]
(math/sqrt (+ (memoize math/expt ax->bz 2) (memoize math/expt ay->by 2) (memoize math/expt az->bz 2)))
and to squeeze out some more speed you could probably also try memoizing the sqrt function.
Also, you can improve the algo. You are calculating the distance between star a and star b 2x.
But you can still save extra computation by only calculating distances b/w same stars only once
Yeah you're right
also wow, the Math/sqrt is way faster
yeah I just switched it to Math/pow
@roberto fyi memoization seems to actually slow things down, I don't think there's enough overlap in the problems
on the other hand using the java Math functions speeds things up quite a bit, that made a large difference
so apparently I shouldn't be averse to using Java functions...for some reason I had a desire to stay within Clojure
so I changed to using the Math/ functions, and I switched all the maps to records, and the total running time is half as long now
that's much more in line with what I was expecting, thanks for the help guys
@nimblerabit might be worth trying core.matrix with vectorz-clj. There are some highly optimised vector maths operations there
do you know if there’s a way to change the routes for compojure api based on the APP_CONTEXT env variable? seems like they compile in, but i have to deploy into a context other than root for prod and it’s just the swagger-ui pieces that are busted i can hit the api via curl at the app_context just fine but swagger-ui is so handy
@audaxion: Compojure-api automatically supports setting swagger-ui base-path from servlet context, if that is not enough you sould be able to set it manually: (swagger-docs "/api-docs" {:basePath "..."})
@juhoteperi: got it working, thanks!
you can build a handler without defroute (apply compojure/routes [list-of-routes])
ok guys... what's the simplest way of getting all files with a particular extension from a folder?
@triss: I had to do this in a project and ended up taking over the file-seq code but adding a FilenameFilter to it
itrillian: ah thanks man. might come in handy next time I have a lot of files to sort through
@triss: There is also this is you're doing a lot of things with filesystems. I like it a lot: https://github.com/Raynes/fs
I'm working with multimethods, and I'm a little concerned about how I should order something in this system.
I'm using honeysql, and I'm adding a postgres function to it (`ilike`) But I'm not sure how to organize my code for including this extension of the multimethod. Anybody got any advice?
Or even documentation which describes what I'm speaking of? I'm hoping there may be a few pointers there.
https://groups.google.com/d/msg/clojure/TeUuwgTnD1I/0iUd0hZCcg4J This may be more somewhat similar.
@dominicm: short answer would be that each namespace that expects a given multimethod to be there should require it
@thheller: Yeah. It's just.. weird to me, because you're requiring something from the bedroom, so you can go in the bathroom. If you get my point?
well .. if you have a "system" namespace that loads everything you can do it there too
so if you want it clean and simple require it in the namespace that actually uses it
Yeah, that's what arises 😛. Glad to know there's not something obvious I'm missing to resolve it. Thanks @thheller
It's safe, but somewhat complicating, as you said. As there's a silent dependency. Which hopefully will never change, but it's code, and it will. It's inevitable.
hi, is there any short way to convert nested map like {:a {:b "1"}}
to xml in form <a><b>1</b></a>
? I have only elements, no attributes, cdata, etc.
should I walk the whole structure to convert it it data.xml/element
?
@pjagielski: Does this help? https://gist.github.com/semperos/807755
should help, thanks!
I’m struggling to google an answer for this but, using leiningen, how can i control which source folders are included? I may be going about this the wrong way but my tests are getting run when I am running my app in development and, hence, polluting the database.
i’m wondering if maybe i have something else wrong … i don’t have a lot of time for dev at the moment so keep having to relearn what’s going on
@sandbags: :source-paths
@sandbags: also, leiningen has a "sample project.clj" here https://github.com/technomancy/leiningen/blob/master/sample.project.clj
it has all of the options for a project.clj file
In my systems where I participate in honeysql’s multimethods, I have a project.honeysql ns that I require in my project.system ns, which is in turn required by anything that does anything with the db
@yogthos: We’re using Selmer really heavily at work and one of the things we find we need fairly often is a way to look up filter arguments in the context-map, so foo|my-filter:kw
means something like this (my-filter (:foo context-map) (kw context-map))
rather than (my-filter (:foo context-map) kw)
@seancorfield: do you have a change in mind, it sounds like something that could be added fairly easily
It would be great if there was some syntax for "special" arguments that indicated "look this up in the context-map" instead of just being a literal value. Not sure what that syntax should be tho’?
Can’t use :
since that’s the separator. Not sure what would be safe to use that wouldn’t break existing Selmer code…
foo|my-filter:@kw
perhaps? (still risks breaking existing code I guess)
right now the separator parsing is pretty straight forward, I think it’s just a regex
so it shouldn’t break anything off top of my head, @ seems like a reasonable character to use there
Is it possible using get, always looking it up and if it's not found returning the literal as default?
@meikemertsch: I suspect that would break a lot of existing code?
yeah I think changing the existing semantics would affect the current users, and it would be a subtle change so tricky to test
sounds like this would be the place to add this https://github.com/yogthos/Selmer/blob/8e9f1d199df534667fc4cef7077b9810b70f496e/src/selmer/filter_parser.clj#L123
probably the easiest would be to take the parsed out filters and check for any that start with @ for example
Yeah, it would need to pass context-map
into a some of the called functions so filter args could be looked up — since @foo.bar
would need to be supported so they’d have to be split-filter-val
d too
I’m happy to have a go at it (since I have a use case for it right now) although part of me wants full recursive evaluation since my main use case right now is actually @(locale|language)
, i.e., the ability to filters to the argument values as well
I’m open to whatever makes the use case work best barring regressions in current behavior
using the parens would make sense to group them, just have to get more clever with the parsing that way
I’m looking at the parsing now…
Our business team love that they can write HTML email templates as i18n content stored in the DB and don’t have to ask DEV to write code
Hmm, making the parser fully recursive would touch a lot of parts :( read-tag-info
would need to become fully recursive and a lot of code would get touched supporting that. I guess I’ll be a bit less ambitious
if you did go with that approach it would probably make sense to have a separate namespace that handles these types of filters
as long as they can be encapsulated in a way that’s easy to parse out on the initial parse it wouldn’t be too bad
I’m missing something. my reading of the docs suggest that {:profiles {:dev {:test-paths ^:replace []}}}
should override the default value (as shown using lein pprint
) but doesn’t seem to. Anyone see where I have come unglued?
assuming the default profile if nothing else is specified is dev, i’m pretty sure it is but maybe i goofed there
@sandbags: lein test
uses the test
profile
https://github.com/technomancy/leiningen/blob/stable/doc/PROFILES.md#task-specific-profiles
@bostonaholic: my problem is the code on the test-paths being evaluated in the dev profile
I don't know why, but I recall (maybe) needing to use it as {:profiles {:dev {:test-paths ^:replace [""]}}}
`
maybe not
are your sources and tests in a "non-standard" path structure?
xeqi: the test source folder isn’t in the :source-paths
variable so I don’t think so...
@sandbags: adding :profiles {:dev {:test-paths ^:replace []}
causes lein pprint
to show me an empty :test-paths
on lein 2.5.3
When trying to use the jsr166y jar with Clojure to support JDK6, I’m getting an "Unsupported major.minor version 51.0"
hey @all, I'm having a weird bug using prismatic/schema 0.4.0, and clojure 1.8.0 if I re-eval the file that has all of my schemas, functions that use those schemas don't see to update to the new value. If I re-eval the functions that use those schemas, then it works
thanks for your help @bostonaholic and @xeqi
good luck
I’m also having a problem where I can’t compile my Clojure code under JDK6, I get the “Can’t connect to window server” error.
@cfleming: http://g.oswego.edu/dl/concurrency-interest/ under "Package jsr166y" ?
@stopachka: are you using protocols as part of your schema?
java.lang.UnsupportedClassVersionError: jsr166y/ForkJoinPool : Unsupported major.minor version 51.0, compiling:(clojure/core/reducers.clj:56:21)
why does Clojure forbid you from creating an unbuffered channel with a transducer?
@cfleming: http://repo1.maven.org/maven2/org/codehaus/jsr166-mirror/jsr166y/1.7.0/ has a 1.6 ForkJoinPool.class if you want to trust random jars from the internet
(and by forbid I mean "silently ignore your transducer leaving you with a subtle bug")
@xeqi: I trust a random internet jar more than one I’ve built myself with this ant file.
for example: https://www.refheap.com/111383
I notice this was raised in Jira but I disagree with the resolution - am interested in hearing others' thoughts. http://dev.clojure.org/jira/browse/ASYNC-140
@yogthos: PR submitted to support @foo.bar
in filter arguments.
LMK if anything needs changing. I’d like to be able to start relying on this new functionality at work
@seancorfield: it looks good to me, the only question is if the syntax would need to be changed if you decide to add the recursive case