This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-24
Channels
- # aws (14)
- # beginners (111)
- # boot (12)
- # cider (1)
- # cljsrn (7)
- # clojure (65)
- # clojure-dusseldorf (1)
- # clojure-germany (7)
- # clojure-greece (10)
- # clojure-italy (13)
- # clojure-poland (7)
- # clojure-russia (7)
- # clojure-spec (53)
- # clojure-uk (29)
- # clojurescript (27)
- # community-development (9)
- # cursive (2)
- # data-science (1)
- # datomic (17)
- # emacs (16)
- # events (6)
- # fulcro (155)
- # graphql (8)
- # instaparse (1)
- # leiningen (30)
- # lumo (29)
- # om-next (3)
- # other-languages (46)
- # pedestal (11)
- # portkey (7)
- # re-frame (13)
- # reagent (6)
- # ring (8)
- # rum (1)
- # shadow-cljs (75)
- # sql (1)
- # timbre (3)
- # unrepl (128)
@thomas.armstrong that's a mix of syntaxes
you either want (ns foo.bar (:require [clojure.math.numeric-tower :as math]))
or (require '[clojure.math.numeric-tower :as math])
@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?
the :require
form is a special syntax recognized by the ns
macro
Is it a simple matter of evaluating the require
as part of the ns
macro vs separately, or are there other ramifications?
the ns macro implicitly quotes the arg vector
which is why one version needs to be quoted, and the other needs to not be quoted
macros are functions that return the source code that gets compiled
so they can use the whole clojure language, but they can implement new syntaxes
Yep; that summary is about the level of my understanding. Haven’t learned them in-depth, or learned to write my own, yet 🙂
s/source code/list of readable objects
So, begging your indulgence: is there a particular reason why one would use the :require
form in the ns
macro, vs. the require
function?
ns is always at the beginning of the ns, which is almost always in the start of a file
it helps us quickly find the required things when reading code
ns just creates a call to require for you, the advantage is there for human readers
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
in practice we use syntax-quote - ` - because it makes writing correct and legible macros much easier
Yes, still getting my head around the purpose of the '
that gets prepended to certain things.
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"
+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))
you should be able to see why each of those returned what it did
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
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?
you can't require java code
you can import classes
clojure namespaces are not packages or class definitions - they are something else entirely that nothing made with just java will implement for you
we have import,but without the * syntax, each of the classes to import must be specified explicitly
interop is very easy, and less ambiguous than using the same classes / methods from java
(import '[com.chain.api :as api])
ClassNotFoundException com.chain.api.:as java.net.URLClassLoader.findClass (URLClassLoader.java:381)
that's not valid import syntax
you can't import a package, only a class
you can't rename packages or classes in an import
(import com.chain.api.SomeClass)
or (import (com.chain.api SomeClass AnotherClass YetAnotherClass))
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
+user=> (import (java.util Date UUID))
java.util.UUID
+user=> (UUID/randomUUID)
#uuid "da5e57e1-3b18-443f-9b16-2dcabb4250d0"
+user=> (.getTime (Date.))
1511484154646
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.
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)
@noisesmith Taking a look at it. Thanks
@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?
re-frame is an add on to reagent
Oh, alright.
you can easily start with reagent and add re-frame, or use re-frame and then write regular reagent code for it
@anantpaatra but there's a good guide to the project creation options too http://www.luminusweb.net/docs/profiles.md
Thanks!
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.
luminus provides a bunch of decent defaults
you can use any css library you like for cljs
@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
@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?you can do this sort of thing via interop pretty easily, or sometimes it is just simpler to put a small js script in
for that I bet it would be easiest to just put some interop in your cljs -main
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
Great, thanks @noisesmith for your time. I will have a go at this then. Thanks again.
@duminda there's also the interop section on the lower right here http://cljs.info/cheatsheet/
@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
?it's one convention people use
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
I see. I'll try to use it from now on 🙂
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
if you use lein new without luminus, lein new org.foo.bar
will create src/org/foo/bar.clj
and no core.clj
Huh, this is really interesting!
Just reproduced here. Good to know!
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
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!
Just guessing, but does type
return some metadata in that case? https://clojuredocs.org/clojure.core/type
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 ?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>
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
Try the following: lein new re-frame myapp cd myapp lein figwheel dev ... Then navigate to localhost:3449
It is the first command (lein new) which fails actually
thanks anyway 🙂
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
If you run describe-key
and type C-g
does it say it's bound to (keyboard-quit)
?
describe-key
is bound to C-h k
, so C-h k C-g
will tell you if it's bound corectly
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!
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
and this is the error
Can't find 'application.system' as .class or .clj for lein run: please check the spelling.
that's the wrong folder structure for that namespace
if src/clj is in your source paths, put application.system in src/clj/application/system.clj
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.
it's the most common one - it's used by default in leiningen and boot projects
there's also maven and sonatype, which are more popular with java libraries