Fork me on GitHub
#beginners
<
2017-03-07
>
gamecubate03:03:26

@seancorfield The cljs compiler (boot_cljs) is somehow not able to locate that namespace. Is it part of some package one must require in build.boot (this is for a CLJS project)?

vinai05:03:45

@seancorfield Thanks, good to know!

mruzekw18:03:27

I’m trying to require a macro from sablano into a cljc file. It loads in CLJS but not in CLJ

mruzekw18:03:57

(ns app.ui
  (:require [rum.core :as rum]
            [sablono.core :refer-macros [html]]))

mruzekw18:03:11

It keeps saying that it can’t resolve html

sbauer18:03:47

does [sablono.core :as html :refer-macros [html]] result in anything different?

carly18:03:43

you could try

#?(:cljs
 :require-macros [sablono.core :as [html]])

vinai19:03:43

In the namespace foo-bar.core I've got (defrecord Baz [left right]). In another namespace foo-bar.core-test I want to check for membership using (instance? Baz a). I've added the import to the ns macro (ns foo-bar.core-test (:import [foo_bar.core Baz])), But the check with instance? fails because a is a foo_bar.core.Baz, not a Baz. Is there a way to import a record type so I don't have to specify the fully qualified name?

mtkp19:03:26

@vinai huh, that is suprising... Baz should map to foo_bar.core.Baz when imported as you have. how is a defined?

vinai20:03:10

@mtkp a is defined by a factory function in foo_bar.core

zlrth21:03:13

i have a list of files stored in an atom like this:

user> (take 5 @g)
(#object[java.io.File 0x593890b8 "dest/file0"] #object[java.io.File 0x33e303d8 "dest/file1"] #object[java.io.File 0x2fb5d0a2 "dest/file10"] #object[java.io.File 0x5ea35c6d "dest/file100"] #object[java.io.File 0x4303ba51 "dest/file1000”])
and i want to delete some files, but it looks like delete-file accepts a string, not a file object. I see that this works:
user> (delete-file (str (.getParent (first @g)) "/" (.getName (first @g))))
true
I can tolerate this, but i get the feeling that there’s a better way than re-deriving the file path and file name. it’d be great if there was a delete-file for file objects.

seancorfield22:03:29

Why not just call .delete on the File object?

seancorfield22:03:48

(.delete (first @g))

timgilbert22:03:19

@mruzekw: :refer-macros is a CLJS-only construct. From CLJ you'd just use :refer [html]. For CLJC, you might want a reader conditional as @carly suggested

zlrth22:03:23

oh wait, can .delete be passed in to a higher order function like map?

timgilbert22:03:05

It might be simpler to just do :require [sablono.core :as s] ... (s/html [:head ...]), with more recent versions of ClojureScript the CLJS compiler will figure out what things are macros and pull them in on :require

timgilbert22:03:36

Getting macros working in CLJS still seems like a bit of a black art though. You might find this useful if you're mixing macros and CLJC: https://github.com/cgrand/macrovich

zlrth22:03:33

i found:

(map #(.delete %) (take 5 @g))
deletes the first five files in @g. thanks @seancorfield !

payal22:03:30

I am trying to understand how class loading works.. I am using clojure.string in one of my functions and somehow the code throws runtime error 'java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils’ SO looks like ‘org/apache/commons/lang/StringUtils’ class is not found.. What is the right way to fix this?

payal22:03:07

Should I include org.apache.commons.lang.StringUtils in project.clj?

donaldball22:03:35

That’s… weird. clojure.string has no direct dependency on anything other than java and clojure itself

donaldball22:03:59

Perhaps you could paste the code in question?

payal22:03:11

I knoww…but I started coming across it only after I added this code

timgilbert23:03:07

Do you have something like (ns foo (:require [clojure.string :as string])) at the top of your file @payal? Maybe somehow your editor tried to automatically import a different string library or something?

payal23:03:34

wohoo yes I do

payal23:03:53

But why will that import different string library?

timgilbert23:03:58

Very odd, I'm not sure

timgilbert23:03:08

No, the stuff I posted above should be correct

timgilbert23:03:46

But I was thinking sometimes IDEs can auto-insert other classes for you and it's easy to get the wrong one sometimes

timgilbert23:03:52

But you'd see it in your code

timgilbert23:03:10

If you're using leiningen you could try running lein deps from your project to make sure your local repository has the correct dependencies

payal23:03:33

hmm okay let me do that .. by that you mean there should be no package other than clojure.string which lein is puling right?

timgilbert23:03:57

How are you running your code?

timgilbert23:03:40

Basically if you have a leiningen project, all the classes that are loaded when you run your code should come from the :dependencies key in your project.clj

timgilbert23:03:04

You can run lein deps :tree to view the whole tree of jar files that lein will pull in based on that list

timgilbert23:03:24

And lein deps by itself will try to download any files that you don't have locally

payal23:03:44

thanks I was looking for this command because lein deps does not shoe downloaded packages

timgilbert23:03:43

If nothing else you can start from scratch by deleting ~/.m2/repository and then lein deps again. Not sure about the exception you're getting

timgilbert23:03:01

But yeah, just with the code you posted I wouldn't expect it to require the apache string libraries

payal23:03:49

yeah i am also not convinced that it would require StringUtils, but then it is failing with that exception so not sure…thanks for the help though 🙂

adamkowalski23:03:04

is there a way to find out what protocols something implements?

adamkowalski23:03:11

like given an object get back a set of protocols