This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-03-08
Channels
- # admin-announcements (3)
- # alda (2)
- # beginners (66)
- # boot (54)
- # cider (21)
- # clara (1)
- # cljsfiddle (32)
- # cljsrn (9)
- # clojars (4)
- # clojure (164)
- # clojure-dusseldorf (4)
- # clojure-japan (2)
- # clojure-norway (1)
- # clojure-russia (76)
- # clojure-sg (8)
- # clojurescript (19)
- # core-async (1)
- # core-typed (1)
- # cursive (6)
- # datomic (1)
- # editors (48)
- # hoplon (20)
- # immutant (2)
- # jobs-discuss (6)
- # ldnclj (1)
- # om (82)
- # onyx (6)
- # parinfer (11)
- # proton (2)
- # re-frame (113)
- # reagent (17)
- # testing (11)
- # untangled (11)
- # vim (4)
- # yada (38)
@jtackett: i remember sending Keys/ENTER as per http://stackoverflow.com/questions/1629053/typing-enter-return-key-in-selenium
I have a macro that mostly just expands into a def. When I try to require the namespace and use the defined var, it works with lein run, but not when it is inside an uberjar. Can anyone explain this behavior?
if I had to guess, I would say you are aot compiling for your uberjar, and your macro is def'ing directly instead of expanding in to code that defs
The macro is here: https://github.com/cddr/samza-config/blob/master/src/samza_config/job.clj#L112
so the def happens when the macro is expanded, which happens before compilation, which, well, when running aot compiled code, compilation has already happened, so the macro is never expanded / run
The code calling this tries to resolve the symbol that would be defined by the expansion
I was thinking about making this just a function anyway so I think I should probably just go ahead and do that
Hm, maybe it's something else then. Thanks for the note about when the code gets expanded. I was a bit fuzzy on that
Ah, if I try to resolve the var as opposed to just the quoted unqualified symbol, it works as expected
So, maybe this is going to sound crazy
I’m writing a clojure.test
test to demonstrate that a function doesn’t throw a stack overflow when operating on a deeply nested tree
The function definitely works as expected by itself
But throws a stack overflow error when being evaluated in a test
The logic from the function also works fine when “inlined" into the test
Anyone know of any behaviors where clojure.test could cause an intermediate lazy-seq in a function to be realized when it otherwise wouldn’t be?
@jonahbenton: Thank you, I'll check that option
When does it make sense to use comment
rather than ;;
? I can't see the purpose. Except perhaps for making comments a part of the AST and thus more malleable. 😕
commenting out a whole form
not linewise
Good point
I'm trying to comment inside a function - is there a best practice for this?
Can you even do it?
Not as the docstring, but in the function body.
(comment ...)
evaluates and gives you nil
as I recall, whereas ;; this comment
is just a "pure comment"
And the convention in Clojure is ;;
to comment out a whole line but ;
to append a comment to the end of a line.
@seancorfield: That's what I read in the docs. I'm having trouble using either within a deftest
that I want to explain a bit
Can you http://refheap.com the code that doesn't work so we can see what's up?
just a sec
The comments are perhaps redundant and silly, but now that they don't work, I want to know why
I get a stackoverflowerror when running the tests using lein quickie
And I've run the tests, but in a different way, before
let me just try this way without the comments
Still get the error
Yeah, if you're not getting a syntax error, then the comments are fine.
I guess so
So I suspect your nth-generation
is faulty.
That is curious, because I've run the same tests using is
with no error
Inside of nth-generation, I use nth
on a lazy seq - I wonder if that gets messed up when using are
Try removing the names from those two anonymous functions at the end...
Or change them to something other than a
and b
...
Here is a paste of working is
invocations:
Let me try with different anonymous functions
Your is
version doesn't test functions, BTW.
how so?
You have the function test commented out
lines 47-48
But you don't need the a
and b
names inside the (fn ...)
forms
changing the names of the anonymous functions to something else caused an error in that exact test, but other tests to g ogreen
I see what you mean, doh
Like I say tho' I think that's the issue: the a
and b
in the are
test are being treated as the named arguments a
and b
in the are
substitution...
Sounds like you have your solution now?
Well, almost I think
I just tried is
with the functions, works well, no problem
Let me try without function names and are
(I'm out for the night so good luck!)
Hah, I'm just about to get on the train to get to work (early!)
Thank you for your help!
Hmm, having a bit of trouble following that
Ah, I think I get it. I guess each fn
invocation creates a new function instance... Maybe?
The conversion of functions to weird #<> names really confuses me.
Functions compile to Java classes. Anonymous functions get generated names. Because are
is a macro expansion, you get multiple "textual" instances of each function so your fn
will become multiple (different) classes.
But it seems like I end up with [(fn [] (+ 1 2)]
when calling nth-generation
as specified in the test.
So does that mess up equality?
Or are they still equal?
Each macro-expanded anonymous function will compile to a different class.
So your three a
functions will become three different classes.
Does that mean that calling =
on them will return false
?
They're different classes so they cannot be equal.
So functions are not really values? Or maybe my understanding of values is wrong.
How would you expect two functions to be checked for "equality"?
Something's really weird...
I dont' know ¯\(ツ)/¯
The object receive the unicode text fine, but it's saved to the database as ??? instead of ななし ...
Which is weird, because I don't get this issue testing locally, only on wildfly deployment
But textually, I can see with my eyes that 1 = 1 and (fn [] (+ 1 2) = (fn [] (+ 1 2).
What about (fn [] (+ 2 1))
?
Bottom line: each anonymous function is considered unique (not equal to any other).
I see your point.
And because are
is a macro and substitutes one of your functions three times, it will produce three unique values.
They would all evaluate to the same result but they are not equal.
Named functions defined with defn
will compile to specific named classes (not generated names) so you could compare those for equality. I am on my iPhone so I don't have a REPL to verify that.
Haha, love the cljs-lambda docs: "Afterward, the resulting ARN is written into the project file, due to accumulating doubts around your ability to perform remedial tasks."
But does that mean that anonymous functions are not values in the sense that 1
or "Hello" or [1 2 3 4]
are?
@seancorfield: I have already repl-tested nth-generation
using references to defn
'ed functions, and this seemed to have the intended result. Though I didn not compare for equality. Will have to give it a go.
Great success!
Not all values can be compared for equality. Values of different types -- different classes -- will not compare equal (caveat: certain conversions are applied).
So the tests run with are
and references to defn
'ed functions. Thank you for you help, @seancorfield!
Cool!
I guess that is where my understanding of values breaks down. (The understanding I got from "Are we there yet")
But, yes, functions are values. But that doesn't mean all operators will apply.
You can't order functions for example.
I get what you are saying
And that is why we like data first, right?
Because it's much more malleable.
Data Good 😸
So good 😄
Midnight here. Back in eight hours or so!
But not as (depending on your qualification of malleability, I guess), right, @cddr ?
9 in the morning and my Java work resumes. Thank you!
Sure. There are more ways to combine "data" values like maps, vectors etc than there are ways to combine functions
oh my god this is NOT happening
file upload breaks in wildfly because i guess it handles uploads differently from tomcat!!!
Ughhh I am an IDIOT! Why didn't I check this earlier!!
OK... WTF? I had talked to the person who has control over the fileserver to include directories I asked for... Now file upload works on Wildfly. WTF
I'm not complaining, but thank god for dodging a bullet.
Hi, I’m having some issues with clojure.tools.namespace.repl/refresh
- for some reason it’s started complaining that it can’t find my namespaces when I run (refresh)
. Initially in the repl everything works fine and I can run my code, but when I run (refresh)
I then get errors about namespaces not found. Anyone got any ideas? Many thanks!
@rauh: Thanks for your suggestions. I’m fairly new to clojure.tools.namespace.repl
so I’m not really sure what’s going on under the hood but that’s a great place to start
@tomoram: Just do a (deref #'ctnr/refresh-tracker)
and search for the offending namespace. I just pasted it into vim and did a simple search.
@rauh: removing target seems to have solved the namespace issue but now it’s getting upset with a speclj symbol…at least it’s progress 😉
ok, so, this is an interesting challenge.. i was to convert a "nice" map into a more overhead array, i think it's kind of like an unzip or something... to illustrate, i have a map like this:
{:name "Joe Awesome"
:email ""}
and want to convert it to an array that looks like this:
[{:key "name",
:value "Joe Awesome"}
{:key "email"
:value ""}]
as in, i'm aware of all the different traversal/map/etc functions... just want to know what the idiomatic approach to this would be
@tomoram: Most problems with tools.namespace like this are caused by either 1) stale AOT-compiled files on the class path; or 2) files whose ns
declaration does not match their path/name. Do lein clean
and restart the REPL will resolve (1).
Tools.namespace refresh
does not work if anything in the project is AOT-compiled.
@stuartsierra: Great, thanks for the info. It’s working again now as expected (although a bit of an issue with speclj stubs but that’s a different issue) but it great to get a better understanding of what is going on. Thanks for your replies!
You're welcome.
is there any place I can read about AOT? It always confuses me. Some tools don’t work well with AOT, but then when I build an uberjar (with lein) it fails to do so if AOT is disabled.
Ahead of time (AOT) compilation is only useful if you are delivering an application (not a library). It really only has two practical benefits: 1) a real main
method which can be invoked from the java
command line; 2) slightly faster startup time.
Yes, and you should only enable AOT compilation for production (e.g. uberjar) builds. Never for development.
You're welcome.
my preferred way to have aot is essentially
(ns my.shell (:gen-class))
(defn -main [& args]
(require 'my.real.ns)
(apply (resolve 'my.real.ns/-main) args))
this way only one harmless / mostly useless namespace is compiled, jsvc knows how to launch that ns, and it pulls in the rest without them needing compilation
A little bit, yeah
does anyone one know how to put a vector of 32 ints into an environment variable so environ can access it?
@virmundi: Well, environment variables can only hold string values. So some form of conversion is going to be necessary. You could store it in a bunch of different ways, but I might just go with EDN
Ah, right. I don’t think there’s anything built in. I remember doing something similar when I used environ
@virmundi: If you're just starting with environ, it might be worth looking at https://github.com/tolitius/cprop instead - looks like it was built for that type of use case