Referencing macros in ClojureScript namespace - clojure

I was trying to reference macros in my ClojureScript namespace:
(ns swagger-service.core
(:require [reagent.core :as reagent :refer [atom]]
[ajax.core :refer [GET]])
(:require-macros [secretary.core :refer [defroute]]))
But I got the following error:
java.lang.RuntimeException
No such var: clojure.core/require-macros

You can find a working example here to clone: https://github.com/cloojure/cljs-template. You probably want a syntax something more like this:
(ns tst.flintstones.pebbles
(:require
[clojure.string :as str]
[flintstones.test-cljs :refer [dotest is isnt is= isnt= testing use-fixtures]] ))
As akond pointed out, it appears you are invoking the Clojure compiler, not the ClojureScript compiler.
Be sure to read and follow the README for the above repo as it is easy to make a mistake setting up the config for a CLJS project.

Related

:require data.json in Clojure doesn't seem to be working

I am new to Clojure and have been stuck for a while on the :require. I am using lein and included in my project.clj
:dependencies [[org.clojure/clojure "1.6.0"]
[http-kit "2.1.18"]
[org.clojure/data.json "0.2.6"]])
I checked the class path and tried to :require the data.json as it said on the data.json Github page but it says cannot find on classpath. I tried
:require [org.httpkit.client :as http]
[clojure.string :as str]
[clojure.data.json :as json]))
along with org.clojure.data.json and a whole bunch of other things. In my classpath it says
.m2/repository/org/clojure/data.json/0.2.6/data.json-0.2.6.jar
So I know it is in my classpath.
Thanks
Edit
My full ns script in my core.clj is
(ns myproject.core
(import [java.net URLEncoder])
(:require [org.httpkit.client :as http]
[clojure.string :as str]
[clojure.data.json :as json]))
Just for clarification I am importing one project into another using the /checkouts/. When I delete the data.json line it works but doesn't work with it.
if you're using lein try running lein install - this should make the jars available to you.
I'm using the same library in a current project and my project.clj and ns :require are both identical to yours.

How do I fix this dependency issue in Clojure?

I'm having a lot of trouble fixing an issue where the dependencies for two different packages are colliding. My project.clj's dependencies look like this:
:dependencies [[org.clojure/clojure "1.6.0"]
[itsy "0.1.1"]
[amazonica "0.3.22" :exclusions [commons-logging org.apache.httpcomponents/httpclient com.fasterxml.jackson.core/jackson-core]]])
My namespace looks like this:
(ns crawler.core
(:require [itsy.core :refer :all])
(:require [itsy.extract :refer :all])
(:use [amazonica.core]
[amazonica.aws.s3]))
When I try to load the namespace into lein's repl with (load crawler/core), I get this error:
CompilerException java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z, compiling:(amazonica/core.clj:1:1)
Online sources suggest that this is a dependency mismatch. How do I fix it?
I put the exclusion on itsy rather than amazonica and it worked. Also fixed the NS form in core.clj.
project.clj:
(defproject blabla "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[itsy "0.1.1" :exclusions [com.fasterxml.jackson.core/jackson-core]]
[amazonica "0.3.22" :exclusions [commons-logging org.apache.httpcomponents/httpclient]]])
core.clj:
(ns blabla.core
(:require [itsy.core :refer :all]
[itsy.extract :refer :all]
[amazonica.core :refer :all]
[amazonica.aws.s3 :refer :all]))
(defn foo
"I don't do a whole lot."
[x]
(println x "Hello, World!"))
to deal with these situatuions in general run
lein deps :tree
and add exclusions until only the newest versions remain.

How to make functions from all namespaces available in the .core namespace in Clojure?

I have a library that has multiple namespaces. I would like if I could make functions in all namespaces available in the core namespace. This way I could just require example.core instead of requiring example.ns1, example.ns2, etc.
Here is what I have in my core namespace
(ns example.core
(:require [example.options :refer :all]
[example.playback :refer :all]
[example.controlls :refer :all]
[example.stored :refer :all]
[example.db :refer :all]))
here is how i'm trying to require it
(ns test-app.core
(:require [example.core :as e])
(e/foo) ; where foo is defined in one of the namespaces required by example.core
When I try to execute that I get CompilerException java.lang.RuntimeException: No such var: e/foo
Is what I'm after possible? or will I have to import the multiple namespaces individually?
Thanks for your time
You can do this using import-vars from the library Potemkin.

Incanter dependency

I am trying to implement the following link http://data-sorcery.org/category/pca/ and found myself stuck trying to load the necessary Incanter libraries, i.e.
(use '(incanter core stats charts datasets))
The only dependency that I have for Incanter is [incanter "1.5.4"]. Is this enough to load the libraries, am I just missing something?
I am not really sure how to load the 4 highlighted libraries in the link. To note I have been able to use Incanter previously in the REPL.
Edit: My text editor has the following
(ns my-namespace.filename
(:use [incanter.core]
[incanter.stats]
[incanter.charts]
[incanter.datasets]))
(def iris (to-matrix (get-dataset :iris)))
(view iris)
which returns the error CompilerException javax.net.ssl.SSLProtocolException: handshake alert: unrecognized_name, compiling:(pca.clj:11:22)
The error seems to stem from the inner part, namely the get-dataset... which I am unsure how to fix.
Since you say you've been able to load dependencies from the REPL I assume you are now trying to load it from lein.
You need to include the dependency in your project.clj:
(defproject my-project "0.1.0-SNAPSHOT"
:dependencies [[incanter "1.5.4"]])
At the top of the file where you want to use incanter functions have one of the following with the proper namespace and file name.
(ns my-namespace.filename
(:require (incanter [core :refer :all]
[stats :refer :all]
[charts :refer :all]
[datasets :refer :all]))
This is the same as:
(ns my-namespace.filename
(:require [incanter.core :refer :all]
[incanter.stats :refer :all]
[incanter.charts :refer :all]
[incanter.datasets :refer :all]))
Same as:
(ns my-namespace.filename
(:use [incanter.core]
[incanter.stats]
[incanter.charts]
[incanter.datasets]))
I use the first variation for consistency since I usually don't want to :refer :all with all dependencies.
Sometimes there is a confusion between the Incanter's libraries (that are included as dependencies) & Incanter's namespaces. One library can contain many namespaces, for example, incanter-core includes incanter.core, incanter.stats, etc., while the incanter.datasets is in the incanter-io library (together with incanter.io), and incanter.charts is in the incanter-charts library.
If you include the incanter as dependency in your project.clj, then it will include all libraries & namespaces provided by Incanter.
The Incanter was split into many libraries to decrease the number of dependencies for cases, when people want to use only small part of its functionality, for example, only incanter.stats + incanter.datasets.
Some information about Incanter's libraries you can find in the following presentation
Edited: The problem with SSL arises from the old bug when dataset always was downloaded from Internet. See this issue for details...
I've committed the fix 2 days ago, but it still only in the master, not released. To fix it in the release version, add following to your project.clj:
:jvm-opts ["-Djsse.enableSNIExtension=false"]
This will prevent the error. If you don't want to download the datasets from Internet, you can explicitly pass the path to them via get-dataset's options:
(get-dataset :iris :from-repo false
:incanter-home "/Users/ott/projects/incanter")
The :incanter-home path should point to the directory under which the Incanter's data folder is stored.

What is the correct terminology to describe what goes on in project.clj and core.clj?

When explaining Clojure builds, I would like to use the correct terminology. Therefore my overarching question is, am I using the correct terminology in the following examples?
Given one of my project.clj files:
(defproject bene-csv "1.0.4-SNAPSHOT"
:description "A csv parsing library"
:dependencies [[org.clojure/clojure "1.3.0"]
[clojure-csv/clojure-csv "1.3.2"]
[util "1.0.2-SNAPSHOT"]]
:aot [bene-csv.core]
:omit-source true)
I believe the correct terminology is I am creating dependencies to Clojure 1.3.0, clojure-csv, and one my my modules, which is named util.
Is that correct?
Given the header of my core.clj
(ns bene-csv.core
^{:author "Charles M. Norton",
:doc "bene-csv is a small library to parse a .csv file.
Created on March 8, 2012"}
(:require [clojure.string :as cstr])
(:require [util.core :as utl])
(:use clojure-csv.core))
am I including or referencing these modules, or should I be using different terminology?
Thank you.
In the project.clj you are defining the dependencies for specific packages (or projects) that will be required in classpath for you project to work.
In the core.clj you are referencing to the namespaces or importing the namespace vars depending on what you use (:use or :require)