Fork me on GitHub
#beginners
<
2019-07-20
>
its.ramzi04:07:35

how do i import a library. im trying to import hiccup to use the html function, but no matter what i do it doesnt see the function

seancorfield04:07:17

@its.ramzi You have Hiccup as a dependency in your project? You restarted the REPL after you added that dependency? How are you requiring the Hiccup namespace?

its.ramzi04:07:51

i only restarted with figwheel. i dont remember the command to recompile.

its.ramzi04:07:06

i did put it as a dependency in my project.clj

its.ramzi04:07:20

and my core.cljs looks like:

its.ramzi04:07:21

(ns betterdiscourse.core (:require [reagent.core :as reagent] [clojure.browser.dom :as dom] [hiccup.core] ))

its.ramzi04:07:39

and i put the hiccup folder in my src directory

seancorfield04:07:40

And what error exactly are you seeing?

its.ramzi04:07:56

No such namespace: hiccup.core, could not locate hiccup/core.cljs, hiccup/core.cljc, or JavaScript source providing "hiccup.core" in file <cljs repl>

seancorfield04:07:00

You don't need to put Hiccup anywhere if you put the dependency in correctly.

its.ramzi04:07:56

:dependencies [[org.clojure/clojure "1.8.0"] [org.clojure/clojurescript "1.9.946"] [reagent "0.7.0"] [jayq "2.5.5"] [hiccup "1.0.5"] ]

seancorfield04:07:22

[email protected]:~/clojure$ clj -Sdeps '{:deps {hiccup {:mvn/version "RELEASE"}}}'
Downloading: hiccup/hiccup/maven-metadata.xml from 
Downloading: hiccup/hiccup/2.0.0-alpha2/hiccup-2.0.0-alpha2.pom from 
Downloading: hiccup/hiccup/2.0.0-alpha2/hiccup-2.0.0-alpha2.jar from 
Clojure 1.10.0
user=> (require '[hiccup.core :as h])
nil
user=>        

its.ramzi04:07:54

No such namespace: hiccup.core, could not locate hiccup/core.cljs, hiccup/core.cljc, or JavaScript source providing "hiccup.core" at line 1 <cljs repl> 1 (require '[hiccup.core :as h]) ^---

seancorfield04:07:05

I know nothing about Figwheel. If you're using lein, you need to start a new lein repl after you added the dependency.

its.ramzi04:07:17

let me run clj -Sdeps '{:deps {hiccup {:mvn/version "RELEASE"}}}'

its.ramzi04:07:19

my command prompt doesnt see clj

seancorfield04:07:09

[email protected]:~/clojure$ lein update-in :dependencies conj '[hiccup "RELEASE"]' -- repl
nREPL server started on port 61574 on host 127.0.0.1 - 
WARNING: cat already refers to: #'clojure.core/cat in namespace: net.cgrand.regex, being replaced by: #'net.cgrand.regex/cat
REPL-y 0.3.7, nREPL
Clojure 1.8.0
OpenJDK 64-Bit Server VM 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

user=> (require '[hiccup.core :as h])
nil
user=>

seancorfield04:07:47

If that works and your project doesn't, then either you didn't specify the dependency correctly or you didn't restart your repl.

its.ramzi04:07:50

C:\Users\Ramzi\Desktop\betterdiscourse>lein update-in :dependencies conj '[hiccup "RELEASE"]' -- repl java.lang.RuntimeException: EOF while reading at clojure.lang.Util.runtimeException (Util.java:221) clojure.lang.LispReader.readDelimitedList (LispReader.java:1204) clojure.lang.LispReader$VectorReader.invoke (LispReader.java:1150) clojure.lang.LispReader.read (LispReader.java:263) clojure.lang.LispReader.read (LispReader.java:200)

seancorfield04:07:56

Windows... OK, so you're running into cmd's weird quoting behavior...

seancorfield04:07:55

Regardless, you have something wrong in your project.clj and/or you're not restarting your REPL properly.

its.ramzi04:07:04

how do u restart the repl

noisesmith04:07:25

also - hiccup is a clj only dep afaik, it won't work in a figwheel cljs repl

seancorfield04:07:38

I don't have lein installed on this Windows machine to do the equivalent to the above -- but it would have the same result I showed.

noisesmith04:07:29

there's no cljs code here, if you are using things via figwheel hiccup won't be available https://github.com/weavejester/hiccup/tree/master/src/hiccup - it's not a frontend dep

dpsutton04:07:32

what are you trying to do? @noisesmith identified why hiccup won't be an available tool for you in cljs but there are plenty of options there for you

its.ramzi04:07:22

i want to, then, from a clean reagent template, get the hiccup library imported into my project, such that it is in the "java" layer of my reagent program, and that i can make an ajax call to it, to get values from the hiccup library residing in the "java" layer

its.ramzi04:07:34

I would also like to import jquery, because I had trouble with that too

noisesmith04:07:42

regent does its own rendering, it doesn't use hiccup

noisesmith04:07:44

but I'd start with making the thing work on the clj / jvm side, before trying to access it from the cljs / browser side

its.ramzi04:07:05

whats the diff between an atom and a variable

noisesmith04:07:29

a variable is an abstract concept in cs, an atom is a mutable container

noisesmith04:07:45

when you use def that creates a var (which might be want you mean by variable)

noisesmith04:07:07

an atom has extra rules for how it can be changed, that make it safer to use from multiple threads

noisesmith04:07:25

vars are for mutating as you write new code, atoms are for mutating in your app via code

seancorfield04:07:38

If you need Hiccup-like functionality in cljs, there's at least one lib: https://github.com/teropa/hiccups

its.ramzi04:07:35

man nothing ever works for me

its.ramzi04:07:04

ompiling build :dev to "resources/public/js/app.js" from ["src/cljs"]... Failed to compile build :dev from ["src/cljs"] in 0.566 seconds. ---- Could not Analyze src/cljs/betterdiscourse/core.cljs line:1 column:1 ---- Only :refer-clojure, :require, :require-macros, :use, :use-macros, and :import libspecs supported. Got [clojure.browser.dom :as dom] instead. at line 1 src\cljs\betterdiscourse\core.cljs 1 (ns betterdiscourse.core ^--- Only :refer-clojure, :require, :require-macros, :use, :use-macros, and :import libspecs supported. Got [clojure.browser.dom :as dom] instead. at line 1 src\cljs\betterdiscourse\core.cljs 2 (:require 3 [reagent.core :as reagent]) 4 [clojure.browser.dom :as dom] ---- Analysis Error : Please see src/cljs/betterdiscourse/core.cljs ----

its.ramzi04:07:17

(ns betterdiscourse.core (:require [reagent.core :as reagent]) [clojure.browser.dom :as dom] (:require-macros [hiccups.core :as hiccups :refer [html]]) (:require [hiccups.runtime :as hiccupsrt])) (hiccups/defhtml my-template [] [:div [:a {:href "https://github.com/weavejester/hiccup"} "Hiccup"]])

noisesmith04:07:47

@its.ramzi line 3, the ) is too soon

its.ramzi04:07:18

so move it to after 6?

its.ramzi04:07:21

that didnt work either?

dpsutton04:07:29

and normally you only use one (:require form with multiple libraries in that list

noisesmith04:07:35

after your last require, I don't know what's on line 6

noisesmith04:07:46

oh yeah, multiple :require is bad

seancorfield04:07:14

This is why it's important to use an editor setup that manages your parens for you...

noisesmith04:07:31

the paren is balanced, it's just in the wrong position

dpsutton04:07:42

(ns betterdiscourse.core
 (:require [reagent.core :as reagent]
           [clojure.browser.dom :as dom]
           [hiccups.runtime :as hiccupsrt])
 (:require-macros [hiccups.core :as hiccups :refer [html]]))

seancorfield04:07:07

@noisesmith Right, but parinfer would fix the parens to match the indentation πŸ™‚

noisesmith04:07:41

oh man, I wasn't thinking of parinfer - I kind of block it out due to past trauma

its.ramzi04:07:09

yay that worked

noisesmith04:07:11

one coworker who never indented things properly, and another that blindly checked in the way parinfer moved the parens

seancorfield04:07:11

Parinfer is far and away the best choice for beginners in a lot of people's opinion πŸ™‚ Because of exactly this.

seancorfield04:07:29

Orly? OMG! Sorry 😞

noisesmith04:07:57

hah - if everyone had used it, or no-one, it would have worked out

noisesmith04:07:09

or if we had proper code review even...

its.ramzi04:07:51

dpsutton's solution looks a lot more complicated to me than just paren balance

its.ramzi04:07:12

there's .runtime and :refer, two things i dont know about

seancorfield04:07:49

@its.ramzi You had .runtime and :refer in your code.

dpsutton04:07:51

i just reformatted your own code snippet. i don't know what you're talking about

its.ramzi04:07:14

oh, thanks, i copied and pasted that without reading it apparently

its.ramzi06:07:46

I can get resizing working on one node, but not on multiple nodes. Can someone help me?

its.ramzi06:07:03

it's hard to explain without pasting all the code

johnjelinek13:07:02

why clojurian instead of clojurist?

kurva13:07:41

Clojurastians or Clojurasts

ymussi14:07:32

hi ppl, i need help with this: { β€œerrors”: β€œ(not (map? a-clojure.lang.PersistentVector))” }

noisesmith15:07:55

usually with ring, the return value from a handler has to be a String (which becomes the body of the response), or a stream (which becomes the streaming body) or a hash-map (which should have a valid :status field, and probably a :body which can be string, stream etc.)

noisesmith15:07:10

there's no ring conversion of a vector as far as I know

noisesmith15:07:48

to return the string representation of clojure data you can use pr-str, clojure.data.json, or transit, for a few possibilities

noisesmith15:07:57

but the stream itself is just going to end up being bytes

ymussi14:07:55

I created a simple api rest, where I only pass a value and this api should return it, however this does not happen.

reecemcmillin15:07:47

This isn't directly a Clojure question, but I'm taking a series of online classes (How to Code - Simple & Complex Data) and they use Racket. Is this going to be a solid enough prerequisite to start diving into Clojure without being too lost?

motoom15:07:56

I found this playlist about learning Clojure on YouTube: https://www.youtube.com/watch?v=9A9qsaZZefw&amp;list=PLAC43CFB134E85266

reecemcmillin15:07:08

I'm alright on finding learning materials, I'm just not sure if what I'm already taking is enough of a prerequisite or if it'd be better to go farther into functional programming before actually starting to learn Clojure.

nate_clojurians16:07:10

if you grok racket you'll be fine in clojure

darioszr16:07:04

@reecemcmillin https://www.youtube.com/watch?v=0if71HOyVjY this is a good video for Functional languages in general

ashley20:07:20

Hey, I joined because the boot website brought me here. I wanted to talk about boot a little bit from a beginners perspective, it sounds very interesting but most people seem to be using leiningen as it's more tried and tested? For instance I was able to to type something like lein new figwheel <name-of-project> -- --reagent and it was perfect. Does boot have something like this? Or is it a lot more manual and built for more experienced devs?

seancorfield21:07:58

@ashley Hi and welcome! Leiningen has been around the longest and so it is much more popular than Boot -- it's lein that you'll typically find in books and tutorials. Boot is certainly well-established and very powerful but it's just not as widely used.

seancorfield21:07:55

Most of the templates out there for new projects are designed for Leiningen, but boot does have a new option and can generate new projects using Leiningen templates.

ashley21:07:53

Thank you for welcoming me! I can see that. I've got the jist of using leiningen and was simply wondering if, lets say someone like you was to start a new project, would you use boot or lein? Is one more 'modern' than the other?

seancorfield21:07:54

But if the template produces a Leiningen-based project (which I bet the figwheel one does), then even if you generate it via boot/new, it'll still be a Leiningen project.

ashley21:07:50

well with me being a beginner and enjoying the look of figwheel and such, without a boot template for figwheel it'd be an inconvenience to my studies at this point I think!

ashley21:07:23

I guess you could say I'm a sucker for boot's website, it looked nice and modern and something I should be excited about πŸ™‚

seancorfield21:07:29

To complicate matters, Cognitect have produced a new set of tooling for running Clojure programs https://clojure.org/guides/getting_started and a lot of people are starting to use that now -- and there's a new task for that CLI tooling that also generates new projects from Leiningen (and Boot) templates.

seancorfield21:07:26

If you use lein new app myapp, you'll get a lein project. If you use boot -d boot/new new -t app -n myapp, you'll get a boot project. If you do the equivalent with clj-new, you'll get a CLI/`deps.edn` project. The built-in templates generate projects based on the tool itself. But there are a lot more Leiningen templates out there than Boot templates (and I don't know if there are any CLI templates yet).

ashley21:07:16

this space seems pretty clouded then ><

seancorfield21:07:16

At work, we started with Leiningen back in 2011 -- it was the only option -- but switched to Boot in 2015 and we were very happy with that (at first). Last year we switched everything over to the newer CLI/`deps.edn` tool chain.

seancorfield21:07:58

I tend to steer new Clojure developers to Cognitect's CLI/`deps.edn` because that's the most "modern" approach and it's "simple" -- there's a lot less magic -- whereas Leiningen is very widely used and it is "easy". Boot is somewhere in the middle -- very powerful, still some magic, not as popular.

ashley21:07:16

Im struggling to find much information about CLI/deps.edn from your link - is CLI/deps.edn like an official clojure method of starting new projects?

ashley21:07:51

the bottom of that page recommends lein or boot so?

seancorfield21:07:52

It's "official" in the sense that it is produced and supported by the Clojure/core team (essentially, Cognitect).

nate_clojurians21:07:12

the gist I get is that most people use lein

seancorfield21:07:06

lein is going to be the easiest option when you are learning since it's the oldest and most widely used in tutorials/books. I think also learning the clj / deps.edn tooling from Cognitect is important since more and more projects are going in that direction these days.

ashley21:07:57

I can understand why purely because its the first one they encounter. To give some context, I come from C++ and Haskell backgrounds and I'm coming up to my 5th year of uni and getting my masters. I wanted to do my final year project in clojure as I feel like I could get more done in clojure than Haskell, and I just don't feel like C++

ashley21:07:20

my uni doesn't teach functional programming (or git.. or linux..) so I wanted to give them a screw you and write a program they can't read haha

justin90908:07:47

I did exactly this for my final!! hahah

seancorfield21:07:38

The official docs for clj / deps.edn sort of assume you're going to make a new project manually -- but there is https://github.com/seancorfield/clj-new (created from boot-new, which in turn I created from lein-new, so there's a lot of common code and concepts).

ashley21:07:47

also I've been seeing more and more businesses interested in clojure, and as someone who enjoys Haskell and functional programming I wanted to learn clojure to. From what I've done I love it

seancorfield21:07:39

Given your exposure to Haskell, you'll find the functional approach of Clojure easy to pick up. But the workflow will be very different -- no type system, no compile step. Clojure focuses on the REPL, not just as a command-line tool to try out code -- like most languages -- but as the core way to build your applications, interactively, with your editor connected, evaluating code as you go.

ashley21:07:25

I've done some work already on Hackerrank, unfortunately that means that I haven't had the experience of setting up my own project though!

ashley21:07:29

I love the language

nate_clojurians21:07:31

93% used leiningen in 2018's survey, 90% this year Β―\(ツ)/Β―

seancorfield21:07:08

@nate_clojurians Nice comparison -- the new CLI / deps.edn is growing really fast!

ashley21:07:08

I just want to do something with it. I actually tried to contribute to braid.chat, but I could only do a little bit ebcause of my limited knowledge of reagent and server-client apps

nate_clojurians21:07:19

yeah, it definitely is coming up

seancorfield21:07:32

The cljs stuff is a whole 'nother ball of stuff to learn...

ashley21:07:33

It looks exciting, I'm wondering why I haven't even heard of it yet though haha

nate_clojurians21:07:59

9% used clj in 2018, 33% this year

seancorfield21:07:42

My background was in C++ BTW πŸ™‚

seancorfield21:07:06

I didn't realize it was taught at uni much these days?

seancorfield21:07:30

If you do decide to take CLI / deps.edn for a spin, a lot of people are using a variant of https://github.com/seancorfield/dot-clojure/ for their ~/.clojure/deps.edn file to get up and running quickly with a lot of tooling.

ashley21:07:42

Well, I wouldn't count my uni as educational to be honest. I haven't done anything to do with networks over 5 years nor have we covered working with any gui libraries

ashley21:07:57

im very disappointed with it

seancorfield21:07:01

When I went through uni, we used Pascal to solve a lot of math problems, and we did a lot of comp sci theory. We didn't touch networks at all, nor GUI stuff. But that was a long time ago 😐

ashley21:07:10

@seancorfield so if I put that in .clojure/deps.edn that acts as a default file I can use when I start a new projecto r something?

seancorfield21:07:01

Yup, once you have clj installed per the http://clojure.org instructions (assuming you're on macOS or Linux?), replacing the default installed ~/.clojure/deps.edn with the one from my repo gives you a nice jump start.

ashley21:07:20

The only reason I feel annoyed as.. to be honest.. I don't know anything? I'm not lying when I say this, we didn't see a single lecturer type a line of code in our 4th year. They could have not been programmers and we wouldn't know as they just showed powerpoints

ashley21:07:31

yeah I'm on arch πŸ™‚

seancorfield21:07:53

Ouch! At least most of our lecturers did programming stuff too.

ashley21:07:02

I had an amazing lecturer in my first year! He kind of set me off on functional programming as I wanted something harder. But he stopped teaching so yeah 😞 I have him on whatsapp though haha! Anyway back to the topic at hand. I admit you're winning me over with clj, its so hard making a decision though! I know in the end I probably want to learn them all but I'm trying to decide which to learn first. Like I know lein is widely used, but I feel like if I work somewhere, the project will already be set up and I can handle that. I just want to learn one of the more modern ones like boot or clj for personal projects you know? Something that'll make life easier while also helping me bond with my tooling better. Build tools have always been a little difficult for me, I struggled with CMake a lot at first 😞

seancorfield21:07:31

For me, the nice thing about clj / deps.edn is that it's very simple and close to the metal. It fetches dependencies, it builds a classpath, it runs Clojure code. That's it. You can understand each part of what it is doing. Each tool for the CLI (https://github.com/clojure/tools.deps.alpha/wiki/Tools) tends to do just one job and also focuses on simplicity.

ashley21:07:03

okay, and what about boot then? You said it's powerful, but does that also mean its difficult?

seancorfield21:07:12

By contrast, lein is easy because it hides a lot of complexity/machinery and it bundles a lot of tooling "out of the box".

nate_clojurians21:07:29

I think that's actually a downside to clj when you're starting out. knowing all the metal right away distracts from learning the other stuff

seancorfield21:07:03

Yeah, Boot is somewhere in the middle. I still really like it's approach -- tasks as functions -- and it has a very neat feature in "pods" so you can run multiple processes with their own dependencies in the same JVM.

nate_clojurians21:07:22

if I'm fighting with tooling all the time because I don't fully understand the bare metal then I'm just going to get frustrated and maybe quit using it

nate_clojurians21:07:36

like I don't know what a classpath is

nate_clojurians21:07:08

simple vs easy is all well and good but you need easy while first learning so you can ramp up

ashley21:07:53

I honestly am thinking of boot for now because it looks very well documented from what I've seen of it

seancorfield21:07:57

I come from an era where learning the basics was considered critical before you learned much of the rest of it. There are arguments in favor of both approaches.

nate_clojurians21:07:45

ehhh where to draw the line is a matter of preference. I think of it like training wheels

nate_clojurians21:07:54

and we see this in basically every language that's blown up. people made it easy to get started, a steady ramp up to learning it thoroughly, and it took off. it would be a mistake to dismiss that

nate_clojurians21:07:08

I mean I don't know how a CPU works but I use them all the time

nate_clojurians21:07:39

I don't mean to pick a fight or anything, just something I feel pretty strongly about

seancorfield21:07:08

My only concern with starting off with Boot would be that it's rather niche compared to both lein and clj / deps.edn so it might be harder to get answers online if you run into problems (there's a #boot channel here tho' that's going to be a good place to ask questions).

ashley21:07:47

I don't actually see the boot channel here though weirdly enough

ashley21:07:59

Ah I had to click your link

seancorfield21:07:58

It can be a bit hard to navigate around all the channels -- we have hundreds now -- and folks are only added to about half a dozen when they join.

seancorfield21:07:03

There's a #leiningen channel (and #lein-figwheel too if you continue with figwheel). Then there's #tools-deps for the CLI / deps.edn stuff (since it's most based on the clojure.tools.deps Contrib library).

ashley21:07:29

I feel like for everything I want to learn right now I should try it with figwheel. When I worked on braid.chat figwheel was so nice

seancorfield21:07:02

You can ask in #slack-help if you need assistance finding your way around the Clojurians space.

seancorfield21:07:48

There are also #figwheel and #figwheel-main channels (sorry, I don't know which is appropriate for what sort of questions).

ashley21:07:11

don't worry about it! Thank you for everything. I'll do some more research and have a look at some examples. Like I said though figwheel and reagent are what I'm aiming to work with right now so my first task will be looking into setting those up

seancorfield21:07:40

It's nearly 11pm where you are? Europe?

ashley21:07:04

the UK πŸ™‚

seancorfield21:07:31

Oh, I'm an ex-pat. Born and raised in Northern Ireland, moved to California 20 years ago.

seancorfield21:07:48

I went to Surrey university.

seancorfield21:07:51

So you may well want to join #clojure-uk -- they're a great bunch of folks who will be on your timezone!

ashley21:07:38

would love to move to cali haha