Fork me on GitHub
#beginners
<
2018-10-04
>
jaawerth03:10:07

@bones You might want to take a look at https://github.com/mikera/core.matrix either to use it or using its source as an example of how to define +, etc operators and protocols to make them work with your custom stuff

awb9910:10:23

I have generated a jar file for my clojure app, and now I want multiple entry points. So basically i want to run different functions with different commandlines. Is this possible?

lispyclouds11:10:40

@hoertlehner does this help? The clojure code

(ns app.core
  (:gen-class))

(defn -main
  [& args]
  (case (first args)
    "a1" (println "hello")
    "a2" (println "hi")))
then create the uberjar then try:
java -jar app.jar a1
>>> hello
java -jar app.jar a2
>>> hi

awb9911:10:54

@rahul080327 oh yes this helps! Many thanks!

😄 8
awb9912:10:53

@gon thanks! I will study that!

littleli13:10:06

Hello guys, could anyone explain me differences and implications between :keyword and ::keyword?

danielneal13:10:44

::keyword will expand to :<namespace>/keyword for the current namespace

bronsa13:10:19

to expand a bit, ::foo is just a reader macro to expand into :<current_namespace>/keyword, a keyword in the form of :foo is called a non-namespaced (or simple) keyword, a keyword in the form of :foo/bar is a namespaced keyword there's been a shift in the recent years (mostly thanks to spec) to using namespaced keywords when possible, in order to convey better semantic meaning (e.g. what does :name mean? but :person/name vs :country/name make it clear), while still using unnamespaced keywords mostly for syntax (e.g. in macros like (for [x xs :when x] ..))

littleli14:10:42

so let's say I want to code a library. current best practice guides me to use namespaces keywords, so it is clear that this thing belongs to me and has this exact meaning when used with my library? Which I can perceive as prefixed keywords, right? Is there any effect in term of memory management for example or is it just in the boundaries of semantics?

danielneal14:10:38

yep, that's exactly it - if you have a library it is usually best to namespace your keywords, to be precise in the meaning and to avoid clashing with end user keywords

danielneal14:10:41

I don't know about the implications for memory management

peter-kehl14:10:13

How do you start Clojure 1.10 (alpha) REPL, please? Do you invoke it as: java -jar ~/Downloads/clojure-1.10.0-alpha5.jar or in what way? I have Sun JDK 10.0 and OpenJDK 11 on a RPM-based Linux (SUSE). I tried both JDKs with clojure-1.10.0-alpha8.jar and two more jars from https://repo1.maven.org/maven2/org/clojure/clojure (and one from http://maven.org). All fail with: Exception in thread "main" java.lang.ExceptionInInitializerError at java.base/java.lang.Class.forName0(Native Method) .... Caused by: java.io.FileNotFoundException: Could not locate clojure/spec/alpha__init.class or clojure/spec/alpha.clj on classpath. at clojure.lang.RT.load(RT.java:463) .... I also tried to build it from source, failed again.

bronsa14:10:47

@peter.kehl no, use the clj tool

bronsa14:10:12

@ales.najmann yeah that's correct, no performance hit really

bronsa14:10:39

the namespace bit is just a string that's set instead of being nil

helen14:10:48

hey guys. i've just tried to build a new clojurescript project with reagent using lein new figwheel my-app -- --reagent. however on starting with lein figwheel i get a bunch of errors in the console complaining about being unable to find react, e.g.

Uncaught Error: goog.require could not find: create_react_class
    at Object.goog.require [as require_figwheel_backup_] (base.js:681)
    at component.cljs?rel=1538661740772:1
anyone got any ideas?

borkdude14:10:58

I vaguely remember something about create-react-class being deprecated in newer versions of React

littleli14:10:55

@bronsa @danieleneal thank you for your time explaining this to me ❤️

peter-kehl14:10:07

@bronsa Where do you get clj tool for 1.10 aplha?

bronsa14:10:54

then you can specify 1.10 in .clojure/deps.edn

alexmiller14:10:44

that is, clj is agnostic to the Clojure version you want to use, so there is no such thing as “clj tool for 1.10 alpha”, there is just “clj”, which can be used with 1.10 alphas: clj -Sdeps '{:deps {org.clojure/clojure {:mvn/version "1.10.0-alpha8"}}}'

bhauman14:10:35

@helenelizabethwilliam did you alter the generated project?

alexmiller14:10:59

(but you can specify any other version of Clojure there too)

bhauman14:10:13

@helenelizabethwilliam I just launched it and didn’t get these errors

helen14:10:12

@bhauman haven't altered the generated project. literally just run those 2 commands

helen14:10:51

it was working about 2 hours ago and then it suddenly stopped working for me

bhauman14:10:53

so you have been working on it

bhauman14:10:03

adding code etc

helen14:10:04

this was in another clojurescript project, creating using the command i was running lein figwheel. lein figwheel stopped working so i tried creating a brand new project, which also didn't work

bhauman14:10:21

oh that explains it probably

bhauman14:10:27

sounds like caching

helen14:10:31

interesting

helen14:10:34

what gets cached?

bhauman14:10:43

Try a shift reload

bhauman14:10:48

or a hard refresh

bhauman14:10:59

well they are both at the same url

bhauman14:10:06

localhost:3449

bhauman14:10:14

so browsers can be fussy

bhauman14:10:39

when you are fetching the same artifact from the same server

helen14:10:02

:woman-facepalming: thanks - that totally worked

bhauman14:10:30

you can avoid things like this if you have a different port for each project

helen14:10:40

i'll remember that for next time

bhauman14:10:52

or just being aware that its an issue 🙂

seancorfield16:10:01

@peter.kehl How were you running REPLs for Clojure 1.9 etc? You can use the exact same tools -- just specify a different version of Clojure as a dependency. That works for lein, boot, and clj.

CyberSapiens9718:10:48

I was working on a solution for: http://www.4clojure.com/problem/19#prob-title i know people used

(first (reverse coll))
but i wonder if my solution for not using reverse is acceptable
(fn my-rest [a-seq]
  	(cond
     	(empty? (rest a-seq)) (first a-seq)
     	:else (recur (rest a-seq))))

enforser18:10:02

I think that logically it works! You could use if instead, and avoid calling rest twice with destructuring.

(fn my-rest [[fseq & rseq]]
  (if (empty? rseq)
    fseq
    (recur rseq)))

noisesmith18:10:23

and because of how destructuring handles empty rest-destructure, (if-not rseq ...) would also work

noisesmith18:10:19

(or (if rseq ...) and flip the two clauses)

enforser18:10:23

(fn [[f & r]] (if r (recur r) f))

CyberSapiens9718:10:00

oh, sweet, thanks!

noisesmith18:10:43

the nil-pun of empty collection that seq does can really make things more concise

CyberSapiens9718:10:41

destructuring seems really nice, saves me from having to use local bindings (let)

👍 4
CyberSapiens9718:10:22

i tend to solve some problems using structural recursion on sequences, because seems a lot easier for me, and then i try to simplify the code

CyberSapiens9719:10:21

I want to study spec lib, any good resources aside clojure website ?

sundarj20:10:24

@UD4SQ29M1 as well as the great spec guide on http://clojure.org, https://pragprog.com/book/shcloj3/programming-clojure-third-edition has a good chapter on it

💯 4
👍 4
Mario C.20:10:54

Any free tool like SoapUI to do some load testing on an API?

manutter5120:10:25

Are you looking for something like Insomnia? https://insomnia.rest/

Mario C.20:10:44

Thanks! Ill look into this

tdantas21:10:35

hey guys, one quick question. I’m doing my api and something bother me. My handler is calling something like a service “layer” of functions should I validate the params in the handler or into my service ? I mean, should verify the spec on the handler or inside my service layer ( my handlers are super thin , just orchestrating the flow )

noisesmith21:10:05

one approach I have seen recommended is to put the validation at the system boundary, and I'd argue that the system boundary here is where the client communicates with server, so validate the request rather than the function calls

dumrat22:10:53

Hi, I do a query in datomic with pull syntax and I get this: [#:user{:id #uuid "ef23d1a1-ac61-4a8a-9448-61d14c1ec13d", :first-name "Sozuke", :last-name "aizen", :email "", :password-hash "xxx"}] A simple question: What does #:user signify here?

noisesmith22:10:16

it's a namespaced map syntax

noisesmith22:10:49

user=> {:user/foo 1 :user/bar 2}
#:user{:foo 1, :bar 2}

dumrat22:10:49

oh, so actual keys are :user/id, :user/first-name, etc?

noisesmith22:10:22

you can also make map literals that way

noisesmith22:10:11

user=> (= {::foo 1 ::bar 2} #:user{:foo 1 :bar 2} {:user/foo 1 :user/bar 2})
true

👍 8