Fork me on GitHub
#beginners
<
2017-10-19
>
byron-woodfork01:10:32

Anyone have any good libraries for improving the output presentation of stacktraces?

Lucas Barbosa01:10:04

Looking forward to see this as something native in the language itself.

eggsyntax01:10:03

You might also be interested in https://github.com/pjstadig/humane-test-output (although it's not for stacktraces).

Tadeusz08:10:59

Hello! I've just started playing with Clojure yesterday. It's a very nice language.

jlmr08:10:20

Hi! I have this code (apply partial f args), where f and args are a user supplied function and arguments. When the resulting function is called it appends any arguments to the end. How can I make it so that the resulting function uses a single supplied argument as the first argument to f?

rauh08:10:25

@jlmr Just do #(apply f % args)

jlmr08:10:15

@rauh, ok that works, awesome! Thanks!

Tadeusz08:10:41

I'm following the official guide from http://clojure.org and have unexpected result from this exercise:

Define a function triplicate which takes another function and calls it three times, without any arguments.
Here is my attempt:
(defn triplicate
  [callee]
  (
    (callee)
    (callee)
    (callee)))

(triplicate #(println "Hello"))
And the result of calling clojure functions.clj is
Hello
Hello
Hello
Exception in thread "main" java.lang.NullPointerException, compiling:(/home/tadeusz/Projects/clojure-playground/functions.clj:8:1)
        at clojure.lang.Compiler.load(Compiler.java:7391)
        at clojure.lang.Compiler.loadFile(Compiler.java:7317)
        at clojure.main$load_script.invokeStatic(main.clj:275)
        at clojure.main$script_opt.invokeStatic(main.clj:335)
        at clojure.main$script_opt.invoke(main.clj:330)
        at clojure.main$main.invokeStatic(main.clj:421)
        at clojure.main$main.doInvoke(main.clj:384)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.lang.Var.invoke(Var.java:379)
        at clojure.lang.AFn.applyToHelper(AFn.java:154)
        at clojure.lang.Var.applyTo(Var.java:700)
        at clojure.main.main(main.java:37)
Caused by: java.lang.NullPointerException
        at user$triplicate.invokeStatic(functions.clj:3)
        at user$triplicate.invoke(functions.clj:1)
        at user$eval2.invokeStatic(functions.clj:8)
        at user$eval2.invoke(functions.clj:8)
        at clojure.lang.Compiler.eval(Compiler.java:6927)
        at clojure.lang.Compiler.load(Compiler.java:7379)
        ... 11 more
So it seems like the program does what is expected (prints Hello three times, but then the exception is thrown. Why? The same happens if I paste it into REPL.

schmee09:10:33

@tadeusz since the function calls are wrapped in parens, it is also interpreted as a function call

schmee09:10:14

(println "Hello") returns nil, so

(
    (callee)
    (callee)
    (callee))
returns (nil nil nil)

schmee09:10:46

since nil is in the first position, it is interpreted as a function call, and that is why you get NullPointerException

Tadeusz09:10:56

Makes sense.

Tadeusz09:10:08

Shall I remove the outer parens then?

schmee09:10:23

to solve it, either remove the parens around it, or put a do in front:

(do
    (callee)
    (callee)
    (callee))

schmee09:10:52

and welcome to Clojure! 🙂

Tadeusz09:10:18

Thanks 😄

Tadeusz09:10:49

What is the difference between the two solutions? Booth work.

schmee09:10:24

sometimes removing the outer parens changes the meaning of the expression

schmee09:10:47

for example if you have a let block

(let [foo (callee) (callee) (callee)])
is invalid syntax

schmee09:10:02

but (let [foo (do (callee) (callee) (callee))]) works

Tadeusz09:10:21

Aha. Sure. Thanks a lot.

Tadeusz09:10:26

I can see how this wrap in parens to execute can be used to write very concise programs.

Tadeusz09:10:00

Expect more noobie questions from me soon 😉

sundarj09:10:18

@tadeusz functions basically put the do around their body for you, which is why you don't need it inside them

sundarj09:10:15

(fn [] (do 1 2)) is essentially equivalent to (fn [] (do (do 1 2)))

Tadeusz09:10:30

So you would rather opt for removing parens than adding do?

sundarj09:10:34

in the case of functions

Tadeusz09:10:25

Ok. Thanks.

agigao15:10:59

Hey guys, it seems function returns DateTime object instead of timestamp and test fails because of that… Any ideas?

agigao15:10:08

:timestamp #object[org.joda.time.DateTime 0x26dcdd5f "2017-10-19T14:52:58.882Z"]}

agigao15:10:32

:timestamp #inst "2017-10-19T15:04:02.190-00:00"}

dpsutton15:10:47

your function is returning a joda time while you are expecting the (java.util.Date.) type. Is the expectation in error or the function return type in error?

dpsutton15:10:48

this is similar to expecting a long 3 and getting a decimal 3.0. They are similar but you need to compare them with respect to their differences, if that makes sense. Although it should be noted that the timestamps in your tests aren't the same time

agigao15:10:03

@dpsutton thanks for response… here’s my test code

dpsutton15:10:31

ah, if you require clj-time it will change your timestamps to joda. not sure if that's what's going on here.

agigao15:10:22

Yup, this project uses clj-time

dpsutton15:10:58

so you'll need to unify those types to compare them. either joda -> jata util date or the reverse

agigao15:10:13

Okay, thank you!

dpsutton15:10:45

https://github.com/clj-time/clj-time check out how to use clj-time. rather than timestamp (java.util.Date.) just make a joda timestamp from the get-go

agigao15:10:28

Thank you! ^_^

agigao15:10:57

Changed java.util.Date to clj-time.core/now and the problem is solved.

dpsutton15:10:48

excellent! the printer was telling you the reason they were different :timestamp #object[org.joda.time.DateTime versus #inst. Different types have different ways of printing

agigao18:10:15

Thank you!

joelv18:10:11

Hey guys could someone help me with this? I have an jar file that i have build with lein uberjar that uses a log4j2.xml to set up the application logging. The xml file is in the resources folder but when I run java -jar -Dlog4j.configurationFile=/resources/log4j2.xml ./target/app-standalone.jar. I keep getting a ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. lein run works fine

noisesmith18:10:08

@joelv what about without the leading / ?

joelv18:10:01

@noisesmith I just tried removing the leading / and still the same error.

joelv18:10:29

java -jar -Dlog4j.configurationFile=resources/log4j2.xml target/app-standalone.jar

noisesmith19:10:00

is there an option like configurationResource - I don’t know log4j but maybe they care about “File”

noisesmith19:10:48

quick google makes me think maybe -Dlog4j.configuration=... which takes a URL but maybe without a protocol it would accept a resource path?

noisesmith19:10:07

@joelv also if you eliminate the arg altogether it will use the first log4j2.properties it finds anywhere on classpath (which would include inside your jar)

noisesmith19:10:15

(or log4j2.xml if it finds no properties or yaml first)

joelv19:10:35

yeah i'm tried eliminating that but same error

dhirensr20:10:04

any good open source projects to contribute?

dhirensr20:10:23

have you contributed to any? @donaldball like do you know which ones are good for beginners and intermediates?

donaldball20:10:53

Variously, as I’ve had itches that needed scratching, but not working from that registry. There are projects specifically tagged as beginner friendly there.

dhirensr20:10:34

Oh okay will look into it.

yogidevbear21:10:15

I just want to say a big thank you to everyone that helped me over the past couple of weeks to understand stuff around sequences and some of the core functions like map, etc. You guys rock!

Lucas Barbosa21:10:33

@yogidevbear this is by far the best community I’ve ever seen. I always get awesome advices and answers to my newbie questions.

Lucas Barbosa21:10:05

there’s always someone willing to help and share