Fork me on GitHub
#clojure
<
2019-07-06
>
lilactown00:07:00

how much would someone be tarred a feathered if a library they authored introduced a non-namespaced reader tag?

Alex Miller (Clojure team)01:07:52

It’s been done a couple times. They were tarred because they actually collided, which is the whole reason to ns

Alex Miller (Clojure team)01:07:27

So, don’t do what you know is bad :)

lilactown01:07:39

I really want a #hiccup / #hic tag >_<

lilactown01:07:11

settling for #hiccup/element / #h/e for now but it feels harder to type & read

wilkerlucio01:07:01

hello, I have to write some java classes because of some API compatiblity, I was looking in some ways to do it, but getting stuck, my last try was just write the class in Java directly, I'm using Cursive, which says it should be fine, but it fails when I try to require my Java class, is it ok to have the java class in the same folder as the clojure sources?

wilkerlucio01:07:26

this is my class skeleton:

package com.wsscode.wise.jena;

import org.apache.jena.datatypes.BaseDatatype;
import org.apache.jena.datatypes.RDFDatatype;

public class EdnType extends BaseDatatype {
    public static final String TypeURI = "";
    public static final RDFDatatype ednLiteralType = new EdnType();

    public EdnType() {
        super(EdnType.TypeURI);
    }

    public Object parse(String lexicalForm) {
        return null;
    }

    public String unparse(Object value) {
        return "";
    }
}

wilkerlucio01:07:48

then I try to (:import (com.wsscode.wise.jena EdnType)), but get Syntax error (ClassNotFoundException) compiling at (core.clj:1:1). com.wsscode.wise.jena.EdnType

wilkerlucio01:07:50

clues on what I'm missing here?

hiredman01:07:42

Java has to be compiled to class files

wilkerlucio01:07:48

so do I have to do it manually? are you aware if cursive can help in some way with that? I never had to deal with Java before, so this is a very confusing area for me

hiredman02:07:39

I don't know what cursive has. In general it will depend on what tool you use to manage dependencies or automate builds.

seancorfield02:07:53

@wilkerlucio Are you using lein? clj?

wilkerlucio02:07:32

the java file is in the source path in the correct location I think

wilkerlucio02:07:55

Cursive can even detect and auto add the import statement, but for some reason when I try to load in the REPL it says its not there

seancorfield02:07:11

OK, with lein you can get it to compile Java code first. With clj you can use -e as a JVM option to compile the Java code but that's a bit of a hack.

seancorfield02:07:44

The bottom line is that Java is Java and should be compiled (and maybe built into artifacts) separately from Clojure.

wilkerlucio02:07:49

gotcha, what you suggest as the easiest wya to do it? I tried gen-class first, but was having a similar issue with that, proxy doesn't seem to work because I need the class to be a specific class subtype (but maybe I' m getting this wrong)

wilkerlucio02:07:25

is there some way to generate a class that will not require some external compilation process?

seancorfield02:07:39

I have one project (`deps.edn`-based) and I have a -e option in various aliases to compile the code before anything else.

wilkerlucio02:07:18

what goes after the -e?

seancorfield02:07:50

(pay no attention to the contents of that repo, other than the compile aspect 🙂 )

seancorfield02:07:09

That's for pure Clojure with gen-class stuff

wilkerlucio02:07:50

trying here, but something is going wrong

wilkerlucio02:07:54

I wrote the class gen as:

wilkerlucio02:07:56

(ns com.wsscode.wise.jena.EdnType
  (:gen-class
    :extends org.apache.jena.datatypes.BaseDatatype
    :init init
    :prefix "edn"
    :constructors {[] [String]}
    :main false))

(def uri "")

(defn edn-init []
  [[uri] (atom {})])

wilkerlucio02:07:10

but when I try to compile:

wilkerlucio02:07:11

(compile 'com.wsscode.wise.jena.EdnType)
Unexpected error (IOException) macroexpanding clojure.core/gen-class at (EdnType.clj:1:1).
No such file or directory
Unexpected error macroexpanding clojure.core/gen-class at (com/wsscode/wise/jena/EdnType.clj:1:1).
	at clojure.lang.Compiler.macroexpand1(Compiler.java:7018)
java.io.IOException: No such file or directory
	at java.io.UnixFileSystem.createFileExclusively(Native Method)
	at java.io.File.createNewFile(File.java:1012)
	at clojure.lang.Compiler.writeClassFile(Compiler.java:7671)
	at clojure.core$gen_class.invokeStatic(genclass.clj:638)
	at clojure.core$gen_class.doInvoke(genclass.clj:507)

seancorfield02:07:57

You need to create the classes folder manually.

seancorfield02:07:10

(I really wish Clojure would create the classes folder if it doesn't already exist)

wilkerlucio02:07:04

yeah... thanks, it compiled the class now, but still didn't found it, do I need to add classes to classpath too I guess? (trying now)

wilkerlucio02:07:28

got it to run and construct! thanks @seancorfield!

csd02:07:11

@seancorfield enjoyed the two most recent youtube videos you put up. keep up the good work 🙂

💯 8
csd02:07:56

I need to play around with REBL

seancorfield04:07:09

REBL rocks @csd 🙂

pinkfrog12:07:43

is there any tutorial on what mount is and how to use it?

eggsyntax21:07:03

The main page of documentation is pretty readable in my opinion: https://github.com/tolitius/mount There’s not actually that much to it; it’s pretty easy to get started with, especially because you don’t need to declare an overall system, just create pieces of state as you need them. So mostly you only need defstate and then start and stop.

dmaiocchi14:07:56

@seancorfield jdbc next nob question. Imagine I have a propertary driver, how can I interface with it? I can have the driver on my host

seancorfield16:07:47

@darioszr it's just a dependency -- and then you'll need to tell next.jdbc the :classname to use for the driver. Happy to discuss more in #sql

dmaiocchi16:07:49

Sean OK thx ❤️ moving

theeternalpulse17:07:53

Any advice on a good stratagy of seeding an in memory cache/db/map with data from a db. I've toyed with datascript but was wondering what a good interface to do a direct import of data from one or more db's to a structure that would support the relational aspect as well. I don't have a pressing need to push back to the db from the struture, I'd probably just do that separately and pull back into hte structure if needed.

theeternalpulse17:07:16

should I just go row by row manually and make a mongo like map with all the related data as an entry?

hiredman17:07:49

clojure.set/index

theeternalpulse17:07:37

that's neat. So just stuff everything in one set entry and create index as my query functions.

theeternalpulse18:07:30

I saw the example join, makes sense, it's very low level, so it would just need some abstraction to concepts I'm already familar with

Alex Miller (Clojure team)19:07:17

clojure.set has the core relational operators

theeternalpulse19:07:15

Yeah, finding some interesting tutorials on the subject

dpsutton22:07:24

is there something wrong with the following?

(defn cljs-repl
  "Starts a ClojureScript REPL over top an nREPL session.  Accepts
   all options usually accepted by e.g. cljs.repl/repl."
  [repl-env & {:as options}]
  (if cljs-present?
    (do (require 'cider.piggieback.impl)
        (cider.piggieback.impl/cljs-repl repl-env options))
    (throw (ex-info "Clojurescript not present" {}))))
Its not giving me a file not found exception but a classnotfound exception. > Syntax error (ClassNotFoundException) compiling at (cider/piggieback.clj:22:9). >cider.piggieback.impl

dpsutton22:07:58

cljs is present on the classpath so I expect i can require a namespace that requires cljs.repl and others and then invoke it

dpsutton22:07:01

i guess a bare repro is the following:

clj -Sdeps '{:deps {org.clojure/core.match {:mvn/version "0.3.0"}}}'
Clojure 1.9.0
user=> (defn foo [] (do (require '[clojure.core.match]) (clojure.core.match/match [3] [_] :womp)))
CompilerException java.lang.ClassNotFoundException: clojure.core.match, compiling:(NO_SOURCE_PATH:1:50) 
user=> (do (require '[clojure.core.match]) (clojure.core.match/match [3] [_] :womp))
:womp
user=> 
do i have a mistaken expectation that this should work?

theeternalpulse23:07:32

that statement worked for me

theeternalpulse23:07:02

actually I had to require it first

theeternalpulse23:07:07

didn't work in the do statement

theeternalpulse23:07:35

why not require it outside

theeternalpulse23:07:12

found this The require statement within the function -main is not invoked during compilation. Thus the compiler can't resolve the namespace b and complains.

dpsutton23:07:41

Ah thanks. I’ll read more into it later

theeternalpulse23:07:20

If it's already in the classpath seems like requiring on the outside wouldn't hurt

dpsutton23:07:09

The problem is that it depends on something that may not be on the class path. This is a bridge to talk to clojurescript and can’t be loaded if cljs isn’t present

noisesmith17:07:50

the canonical way to handle this is require followed by resolve, in newer clojure versions we have the handy requiring-resolve which returns a var you can invoke directly