Fork me on GitHub
#beginners
<
2018-09-02
>
quadron00:09:36

should I ignore http://java.io altogether in favour of nio?

quadron00:09:30

what is the wisdom regarding io vs nio simplicity-wise?

john00:09:41

IIRC nio is the better option for most things

✔️ 4
quadron00:09:45

netty it is then

bmcferren01:09:40

I have a folder (package) full of clj files with the namespace "foo.accounting.aaa" and "foo.accounting.bbb" and etc... The name of the folder (package) is "accounting" and it is inside of a parent folder (package) called "foo". At the top of these aaa.clj and bbb.clj files, I have (ns foo.accounting.aaa and (ns foo.accounting.bbb respectively. In another file, I wish to require both the aaa.clj file and bbb.clj file and alias the contents of both with (:require [foo.accounting :as act] so that I can use functions as act/funcall. Unfortunately, when I attempt this, I get a compiler error: "CompilerException java.io.FileNotFoundException: Could not locate foo/accounting__init.class or foo/accounting.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name., compiling:(foo/caller.clj:1:1). Is there a special way to possibly require the parent namespace and alias it so that I can call of the functions under that namespace with the same act/ root? Thank you greatly for help you can offer.

john01:09:48

well, jetty is nio too these days

seancorfield01:09:42

@mcferren Your require can only reference actual Clojure source namespaces. foo.accounting isn't, in your code, only foo.accounting.aaa and foo.accounting.bbb.

seancorfield01:09:52

You need to require [foo.accounting.aaa :as aaa] [foo.accounting.bbb :as bbb] and then you can call functions in aaa.clj as aaa/fun-call and functions in bbb.clj as bbb/fun-call.

seancorfield01:09:56

Does that help?

bmcferren01:09:03

yes - thanks @seancorfield wish it wasn't the case though 😞 namespaces should act like umbrella's

stardiviner06:09:42

How to check out the source code of the dot . in Java Interop like (. Math pow 2 4) ?

schmee07:09:35

if you look at the Parser inner class you see that it can compile to many different things depending on the arguments

stardiviner07:09:02

@schmee How do you find and locate this source?

schmee07:09:57

if you look at the top of Compiler.java you will see that there are a bunch of symbols defined, one of them being DOT:

static final Symbol DOT = Symbol.intern(".");
If you search for that in the file, you find on line 118:
DOT, new HostExpr.Parser(),
and then you work your way from there 🙂

stardiviner07:09:36

parse-dt always report error:

stardiviner07:09:36

Unhandled java.text.ParseException
   Unparseable date: "Tuesday, November 22, 2016 10:50:09 AM"

           DateFormat.java:  366  java.text.DateFormat/parse
c83b000ba73daad458c36e37f841882825009b3f-init.clj:   15  user/parse-dt

stardiviner07:09:43

I've tried change the data format EEEEEEEEEEEE, MMMMMMMMMMMM dd, yyyy hh:mm:ss aaa to some different styles. Maybe the problem is not on the date format. The original is (java.text.SimpleDateFormat. "EEEE, MMMM d, yyyy h:m:s a").

hiredman07:09:56

I loaded that example in a fresh repl (clojure 1.9, java 1.8) and it worked fine, you may be calling an older version of you parse-dt function for some reason, so maybe try restarting your repl

stardiviner08:09:01

@hiredman I tried my example in plain lein repl REPL, works fine, but not work in newly jacked-in cider project REPL or without-project REPL. This is weird.

stardiviner08:09:46

@hiredman Can you test the library kce-clj? `

stardiviner08:09:56

(defproject kindle-export-notes "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url ""
  :license {:name "Eclipse Public License"
            :url  ""}
  :dependencies [[org.clojure/clojure "1.9.0"]
                 [kce-clj "0.1.0"]
                 ;; [candelabrum "0.1.0"]
                 ])

stardiviner08:09:15

I got problem on this project.clj definition.

stardiviner08:09:32

The lein repl plain REPL is fine, but CIDER jacked-in REPL got error, I don't know how to debug this problem. Anybody can give me some hints on this?

dangercoder10:09:34

Hello Clojurians, I need some architectural advice. I need some tips for my "Que", people will visit my site, and they will que up and I will have to chunk each "player" into batches. Got any tips on where I can start (reading material)? I never built something like this from scratch. Was thinking about using rabbitMQ.. I will batch them in players/users of 2/10/50/100 depending on what they play.

dangercoder20:09:39

not really sure if that would be sufficient enough for 1k - 300k simultaneous players queing up hmm..

dangercoder20:09:54

Or well, it's a tool afterall that I can use, thanks

dangercoder20:09:20

Im gonna look into Langohr and RabbitMq.

sundarj20:09:13

sounds good!

Denis G12:09:40

Can I overshadow symbols in clojure using macros? E.g. (completely stupid artificial example)

(defmacro add-one [x]
  `(let [temp 1]
    (+ temp ~x))
This does not work, since temp is "not defined". I know that it should be declared with # at the end, but was wondering if it is possible with clojure to overshadow vars with macros

Alex Miller (Clojure team)13:09:57

Yes, but you ` will resolve all symbols yielding invalid code here - there are several common techniques to avoid it

Alex Miller (Clojure team)13:09:55

Instead of temp use ~’temp in both places

Alex Miller (Clojure team)13:09:08

temp# will do the same thing, but will also generate a unique name that won’t conflict with the expanded code

Alex Miller (Clojure team)13:09:35

Also google “anaphoric macros” for more

👍 8
moo14:09:07

hello, I have some basic questions…

moo14:09:24

How do I get atom + protorepl to use the namespace of my project

moo14:09:49

the way it’s working now, I see that I can “Start REPL” which just starts a generic REPL or I can “Start REPL from open project.clj/build.boot” which appears to load my project files

moo14:09:18

I’d like to be able to do something like type (-main) in my repl and have it run the program

moo14:09:53

but instead I get error messages like:

CompilerException java.lang.RuntimeException: Unable to resolve symbol: -main in this context

moo14:09:26

I tried (in-ns 'the-divine-cheese-code.core) and then (-main) but it didn’t work

henrik14:09:46

@jm.moreau Don’t type in the REPL, send code to your REPL. In the file, type (-main) and press, I think it is CMD+ALT+B on MacOS to evaluate it.

mfikes14:09:01

@jm.moreau are you using ClojureScript?

mfikes14:09:23

It sounds like you may not have required the the-divine-cheese-code.core namespace

moo14:09:10

I’m using clojure

moo14:09:14

I’ll try sending it

mfikes14:09:39

Cool, even with Clojure, in-ns doesn't load code in a namespace; you'd need to require it

moo14:09:45

but then the project doesn’t have (-main)

moo14:09:55

it has (defn -main ...)

moo14:09:18

so I would have to add a line (-main) which is not what I want to do exactly…

mfikes14:09:39

In your REPL you could

(require 'the-divine-cheese-code.core)
(in-ns 'the-divine-cheese-code.core)
(-main)

👍 4
moo14:09:55

let me try that. 🙂

moo14:09:26

(require 'the-divine-cheese-code.core)
(in-ns 'the-divine-cheese-code.core)
(-main)

;;==> CompilerException java.lang.RuntimeException: Unable to resolve symbol: require in this context, compiling:(/Users/moo/Sync/braveandtrue/the-divine-cheese-code/src/the_divine_cheese_code/core.clj:1:5) 

moo14:09:43

I should point out that lein run works

mfikes14:09:08

Ahh, you are still in the the-divine-cheese-code.core namespace

mfikes14:09:26

Require is clojure.core/require

moo14:09:48

ahh, that is making sense

moo14:09:02

because I already futzed around with in-ns

moo14:09:28

(clojure.core/require 'the-divine-cheese-code.core)

FileNotFoundException Could not locate the_divine_cheese_code/core__init.class or the_divine_cheese_code/core.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.  clojure.lang.RT.load (RT.java:456)

moo14:09:46

let me try quitting and reloading everything. When in doubt…

mfikes14:09:54

Yeah, that initial in-ns (when the namespace was not yet loaded) put things into a degenerate state

moo14:09:34

@mfikes that works, now I know how in the future. require it then switch into with in-ns

sundarj14:09:41

@jm.moreau you can also do it with a one-liner: (doto 'my.ns require in-ns)

moo14:09:55

Thanks. I’ll go look up doto 🙂

4
moo14:09:45

Thanks!

👍 4
dhruv118:09:46

What is a good conditional restart library in clojure? I am used to using hara.event but i can no longer find the source code.

thiru18:09:44

Looks like there's no way to require all vars in a namespace with clojurescript right? I.e. this works in Clojure but not ClojureScript: (require '[my.utils :refer :all])

noisesmith18:09:34

require always requires everything in the namespace, the difference is what gets mapped directly to your ns

thiru18:09:32

Yes that's what I mean.. It's not possible to auto-map all the vars into the current namespace with a :refer :all right?

noisesmith19:09:06

right, it was intentionally not implemented

noisesmith19:09:22

idiomatically we use :as with a clear shorthand instead

noisesmith19:09:36

the clojure team is very opinionated about maintaining compatibility so :refer :all and unqualified :use still work

thiru19:09:50

ok right thanks @noisesmith

thiru19:09:27

oh really? so even in Clojure :refer :all is discouraged but kept around for backwards compatibility?

noisesmith19:09:39

that's my experience, yes

noisesmith19:09:57

if you look at the code for mainstream libraries, :refer :all is very rare

noisesmith19:09:40

(and at work it's always frowned on outside a test ns where you refer the ns being tested)

Alex Miller (Clojure team)19:09:04

It’s not kept around just for backwards compatibility - there is no desire to remove it

Alex Miller (Clojure team)19:09:21

There is a preference to name the external functions you’re using

Alex Miller (Clojure team)19:09:39

Because people have found that helps in maintenance and understanding

Alex Miller (Clojure team)19:09:02

There are some cases where it’s useful when you have code broken into namespaces but still tightly coupled

thiru19:09:59

Ya I agree about the maintenance/understanding.. thanks guys

schmee19:09:49

it’s also great when you’re just writing throwaway/experimental stuff/trying out new libraries

👍 4