Fork me on GitHub
#beginners
<
2017-11-24
>
noisesmith00:11:50

@thomas.armstrong that's a mix of syntaxes

noisesmith00:11:39

you either want (ns foo.bar (:require [clojure.math.numeric-tower :as math])) or (require '[clojure.math.numeric-tower :as math])

13tales00:11:40

@noisesmith Thanks. Yes, I’ve noticed a couple of different variations around. I think the problem might’ve been compounded by delayed feedback from emacs not recognising changes to the class path, or something? Restarting emacs seemed to help. What’s the difference between those two syntax forms?

noisesmith00:11:35

the :require form is a special syntax recognized by the ns macro

13tales00:11:53

Is it a simple matter of evaluating the require as part of the ns macro vs separately, or are there other ramifications?

noisesmith00:11:01

the ns macro implicitly quotes the arg vector

13tales00:11:13

Still finding my feet with Clojure, haven’t really covered macros yet.

noisesmith00:11:14

which is why one version needs to be quoted, and the other needs to not be quoted

noisesmith00:11:26

macros are functions that return the source code that gets compiled

noisesmith00:11:41

so they can use the whole clojure language, but they can implement new syntaxes

13tales00:11:36

Yep; that summary is about the level of my understanding. Haven’t learned them in-depth, or learned to write my own, yet 🙂

noisesmith00:11:12

s/source code/list of readable objects

13tales00:11:04

So, begging your indulgence: is there a particular reason why one would use the :require form in the ns macro, vs. the require function?

noisesmith00:11:33

ns is always at the beginning of the ns, which is almost always in the start of a file

noisesmith00:11:45

it helps us quickly find the required things when reading code

noisesmith00:11:19

ns just creates a call to require for you, the advantage is there for human readers

13tales00:11:38

Understood. Thanks.

noisesmith00:11:39

a very simple macro

+user=> (defmacro simple-macro [] (list 'println "a macro"))
#'user/simple-macro
+user=> (macroexpand '(simple-macro))
(println "a macro")
+user=> (simple-macro)
a macro
nil

noisesmith00:11:06

in practice we use syntax-quote - ` - because it makes writing correct and legible macros much easier

13tales00:11:50

Yes, still getting my head around the purpose of the ' that gets prepended to certain things.

noisesmith00:11:26

it is a shorthand for quote, and it means "consume this as input to the reader, but don't evaluate or compile any code for it"

noisesmith00:11:58

+user=> foo
CompilerException java.lang.RuntimeException: Unable to resolve symbol: foo in this context, compiling:(NO_SOURCE_PATH:0:0) 
+user=> 'foo
foo
+user=> ''foo
(quote foo)
+user=> '''foo
(quote (quote foo))

13tales00:11:59

Aha. That makes things clearer.

noisesmith00:11:28

you should be able to see why each of those returned what it did

13tales00:11:35

Yes, I think I get it. Thanks; answers much appreciated.

noisesmith00:11:51

so it should make more sense now that require (a function, can't decide whether args are evaluated) requires a quoted arg, and ns (a macro, can transform args before evaluating, or fail to evaluate them entirely if it chooses) does not need a quoted arg

13tales00:11:05

:thumbsup:

Paolo00:11:36

hello everyone, I added as a depedency on my project.clj [com.chain/chain-sdk-java "1.2.1"] a java jar library and maven got it. When I check classpath on lain repl with (println (seq (.getURLs (java.lang.ClassLoader/getSystemClassLoader)))), it is there as #object[java.net.URL 0x288ce718 file:/Users/Paolo/.m2/repository/com/chain/chain-sdk-java/1.2.1/chain-sdk-java-1.2.1.jar] but I couldn't require the file inside repl in any way. I've tried to require com.chain, com.chain.api (in java is import com.chain.api.*;) and some other combinations but nothing works. Is there any way to profile the jar and have a better understanding of importing tree? what is the usual way of finding these things?

noisesmith00:11:02

you can't require java code

noisesmith00:11:08

you can import classes

noisesmith00:11:30

clojure namespaces are not packages or class definitions - they are something else entirely that nothing made with just java will implement for you

noisesmith00:11:06

we have import,but without the * syntax, each of the classes to import must be specified explicitly

noisesmith00:11:28

interop is very easy, and less ambiguous than using the same classes / methods from java

Paolo00:11:52

uhm I was looking at this java_interop, but still, I couldn't import

Paolo00:11:03

(import '[com.chain.api :as api])
ClassNotFoundException com.chain.api.:as  java.net.URLClassLoader.findClass (URLClassLoader.java:381)

noisesmith00:11:11

that's not valid import syntax

noisesmith00:11:23

you can't import a package, only a class

noisesmith00:11:31

you can't rename packages or classes in an import

noisesmith00:11:45

(import com.chain.api.SomeClass)

noisesmith00:11:03

or (import (com.chain.api SomeClass AnotherClass YetAnotherClass))

Paolo00:11:28

uhm, thank you for poiting the way, I'll study and try a little more

noisesmith00:11:41

also you don't need to import a class to use it - classes are auto-loaded on use by the vm, import just makes it more concise to use it

noisesmith00:11:41

+user=> (import (java.util Date UUID))
java.util.UUID
+user=> (UUID/randomUUID)
#uuid "da5e57e1-3b18-443f-9b16-2dcabb4250d0"
+user=> (.getTime (Date.))
1511484154646

Paolo00:11:21

thank you very much

felipebarros00:11:33

Hi. I'm a beginner and want to develop a very simple webapp that is basically a form that on submit needs to send emails and SMS's to some people. I need to do it and I want to do it within this ecosystem for learning purposes. But I'm really lost about what is a good CLJ/CLJS stack to do this and, well, how to give the first steps. I have a hard time when it comes to choosing tools and ways and preferably would like something heavily opinionated.

noisesmith00:11:28

luminus is heavily opinionated, it has a leinigen template (also the best opinionated choice for a newcomer is to use the lein dependency manager to manage your project)

felipebarros00:11:51

@noisesmith Taking a look at it. Thanks

felipebarros00:11:52

@noisesmith as a beginner I'm a bit torn between reagent and re-frame. I really enjoyed the re-frame README so I kind of sympathized with it. But all is new and challenging, I don't need any more complexity. Do you think reagent is an easier path?

noisesmith00:11:21

re-frame is an add on to reagent

noisesmith00:11:48

you can easily start with reagent and add re-frame, or use re-frame and then write regular reagent code for it

noisesmith00:11:39

@anantpaatra but there's a good guide to the project creation options too http://www.luminusweb.net/docs/profiles.md

nakiya03:11:34

I started reading out about clojurescript, re-frame just couple of days ago. re-frame looks great! To confess, I have very little prior exposure to clojure/clojurescript though I did dabble with lisp a bit long time ago. I'm also quite new to web world too (Worked with C++/C# my whole career) I was thinking of doing a project I have in mind (in my spare time) using clojure/clojurescript. Following are the basic requirements: 1. Single page app. But multiple "areas" 2. NoSQL db at server side. Need to sync with it. - I saw luminus, is that the way to go? 3. Need to be able to use a Google Material Design library (something like http://materializecss.com/) - This, for me is important. How easy is it to integrate with clojurescript? Apologies for the broad question, I'm sure you guys get this sort of this question all the time. Just wanted to know what your suggestions are. At the moment I'm dabbling with re-frame examples. I'm testing how materializecss (http://materializecss.com/) works with it (seems to be ok for now - but I haven't checked javascript initializations on document.ready() yet). So far, I'm loving it.

noisesmith03:11:42

luminus provides a bunch of decent defaults

noisesmith03:11:59

you can use any css library you like for cljs

noisesmith03:11:07

@duminda you can scroll up to the snippet I tagged @anantpaatra with to see an example of making a luminus project using reagent, you can easily pick re-frame instead - luminus provides multiple back end db options as defaults, some are NoSql

nakiya03:11:20

@noisesmith: Yeah, I saw that, and read through the luminus doc where they enumerate the additional packages. Thanks! Additionally, do you have an idea how to do javascript initializations in cljs? For example: For this carousel, http://materializecss.com/carousel.html Need to init JQuery:

$(document).ready(function(){
      $('.carousel').carousel();
    });
Is this sort of thing easy to do? What's the support for that? Do you have any link to a page where there's a tutorial/guide for this?

noisesmith03:11:22

you can do this sort of thing via interop pretty easily, or sometimes it is just simpler to put a small js script in

noisesmith03:11:40

for that I bet it would be easiest to just put some interop in your cljs -main

noisesmith03:11:25

from a quick browse this seems OK http://www.spacjer.com/blog/2014/09/12/clojurescript-javascript-interop/ - I'll keep looking for something better

nakiya03:11:27

Great, thanks @noisesmith for your time. I will have a go at this then. Thanks again.

noisesmith03:11:29

@duminda there's also the interop section on the lower right here http://cljs.info/cheatsheet/

felipebarros04:11:10

@noisesmith I saw up there that you chose

org.noisesmith/example-project
as an example name for your project. Is this a best practice naming scheme?
organization.developer/webappname
?

noisesmith04:11:40

it's one convention people use

noisesmith04:11:16

the thing you definitely don't want is to make single element namespaces - by attaching a unique name you own as a prefix, you don't have to worry about what happens when someone else picks the same name

felipebarros04:11:50

I see. I'll try to use it from now on 🙂

noisesmith04:11:31

btw this is why leiningen creates foo.core when you run lein new foo - it doesn't want to create a foo namespace so it puts something generic there

noisesmith04:11:10

if you use lein new without luminus, lein new org.foo.bar will create src/org/foo/bar.clj and no core.clj

felipebarros04:11:33

Huh, this is really interesting!

felipebarros04:11:47

Just reproduced here. Good to know!

noisesmith04:11:13

yeah, I learned all this from technomancy (leiningen project founder) - he wishes he didn't have to create core.clj files in new projects, so if you provide some other unique name it will use that and leave out the core.clj thing

felipebarros04:11:18

There are many small nuances both in the language as in the tooling surrounding the language that escape the perception of someone with little programming background. It's nice to find out about them!

nakiya09:11:16

Hi, Just a quick question: Why does

(instance? (type 1) 1) ==> false
?

nakiya09:11:43

clojurescript

nblumoe09:11:54

Just guessing, but does type return some metadata in that case? https://clojuredocs.org/clojure.core/type

nblumoe09:11:18

Does it work with class?

Guilhem Brouat 10:11:10

Hey there ! I'm trying to create a new project using this lein template : https://github.com/Day8/re-frame-template I get the following error :

Failed to resolve version for re-frame:lein-template:jar:RELEASE: Could not find metadata re-frame:lein-template/maven-metadata.xml in local (C:\Users\gbrouat\.m2\repository)
Failed to resolve version for re-frame:lein-template:jar:RELEASE: Could not find metadata re-frame:lein-template/maven-metadata.xml in local (C:\Users\gbrouat\.m2\repository)
This could be due to a typo in :dependencies, file system permissions, or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable.
Could not find template re-frame on the classpath.
However, the HTTP_PROXY var is properly set... Do I need to install templates before using them ?

gadfly36112:11:38

Are you using +aliases?

gadfly36112:11:13

If so, try running lein deps before running anything else

Guilhem Brouat 12:11:43

Well, I'm not in a project, so deps complains about no project.clj file. I wanted to create a new project from scratch as instructed on the page of re-frame-template : > To create an application with the base template: > lein new re-frame <project-name>

gadfly36112:11:11

The way lein pdo works is it wont download deps if you dont have them, at that cryptic error message usually pops up where it makes it sound like you dont have internet

gadfly36112:11:02

Try the following: lein new re-frame myapp cd myapp lein figwheel dev ... Then navigate to localhost:3449

Guilhem Brouat 12:11:59

It is the first command (lein new) which fails actually

gadfly36112:11:10

Oh gotcha, then im not sure then

Guilhem Brouat 12:11:24

thanks anyway 🙂

dimovich14:11:36

having some issues with C-g in Emacs... it doesn't seem to quit the minibuffer

dimovich14:11:34

like, if I press C-x f and then C-g, it still stays in the minibuffer and waits for me to find a file

dimovich14:11:21

I have to press three times Esc to quit it

dimovich14:11:49

wonder if someone bumped into this before...

Ryan Radomski15:11:56

If you run describe-key and type C-g does it say it's bound to (keyboard-quit)?

Ryan Radomski15:11:19

describe-key is bound to C-h k, so C-h k C-g will tell you if it's bound corectly

dimovich10:11:53

it quits the command so no info is displayed

Ryan Radomski17:11:34

None of my Emacs installs have had that issue and I'm not sure which file is responsible for that. You'll need to ask a veteran on that one. Sorry I couldn't be more helpful. Best of luck!

Bravi19:11:44

how do I make clojure to read clj files from clj folder? this is my folder structure:

project.clj
src
 |
 application
   |
   clj
      - system.clj
I have the following in my system.clj
(ns application.system)

(defn -main []
  (println "Hello"))
and I have the following in my project.clj
:source-paths ["src/clj"]
  :min-lein-version "2.5.3"
  :main application.system

Bravi19:11:26

and this is the error

Can't find 'application.system' as .class or .clj for lein run: please check the spelling.

noisesmith19:11:39

that's the wrong folder structure for that namespace

noisesmith19:11:01

if src/clj is in your source paths, put application.system in src/clj/application/system.clj

Bravi19:11:28

I totally missed it

Bravi19:11:42

hmm still doesn’t work

Bravi19:11:39

ok I need to change the directories instead. now I get it

Bravi19:11:26

it should be src/clj/application src/cljs/application

Bravi19:11:35

makes sense

athomasoriginal22:11:04

Is there a common place to host clojure/clojurescript libraries and frameworks? For example, in JS that would be NPM? I see clojars, but I am curious if that is "blessed" so to speak.

noisesmith22:11:29

it's the most common one - it's used by default in leiningen and boot projects

noisesmith22:11:43

there's also maven and sonatype, which are more popular with java libraries